亿迅智能制造网
工业4.0先进制造技术信息网站!
首页 | 制造技术 | 制造设备 | 工业物联网 | 工业材料 | 设备保养维修 | 工业编程 |
home  MfgRobots >> 亿迅智能制造网 >  >> Industrial programming >> VHDL

ModelSim 仿真入门:FPGA 与 ASIC 设计验证的实战指南

教程:ModelSim 仿真入门

ModelSim 是 Mentor Graphics(现属 Siemens EDA)推出的 VHDL/Verilog 仿真工具,是商业与教育领域最广泛使用的仿真软件。本教程先解释仿真的重要性,再演示如何免费获取 ModelSim 学生版。

为什么仿真至关重要

仿真是 FPGA/ASIC 设计流程的关键环节。它允许设计者施加激励信号,观察代码对各种输入场景的响应。完善的仿真能遍历设计的所有可能状态,确保每种输入组合都被正确处理。漏写 if 语句、case 语句未全覆盖等错误,不仿真极易遗漏。

获取与安装 ModelSim 学生版

  1. 访问官网下载安装包,按默认参数安装。
  2. 必须向 Mentor Graphics 申请许可证。安装结束勾选 Finish 时会弹出浏览器打开许可证申请表,直接点击书签或网页链接无效,需通过安装向导跳转。

仿真示例:与门及其测试平台

仿真代码包含两个文件:and_gate.vhd(设计)与 and_gate_tb.vhd(测试平台)。无需精通 VHDL 即可跟随操作。

and_gate.vhd(设计文件)

library ieee; use ieee.std_logic_1164.all; 
entity and_gate is 
  port ( 
    input_1    : in  std_logic; 
    input_2    : in  std_logic; 
    and_result : out std_logic 
  ); 
end and_gate; 

architecture rtl of and_gate is 
  signal and_gate : std_logic; 
begin 
  and_gate    <= input_1 and input_2; 
  and_result  <= and_gate; 
end rtl;

and_gate_tb.vhd(测试平台)

library ieee; use ieee.std_logic_1164.all; 
entity and_gate_tb is end and_gate_tb; 

architecture behave of and_gate_tb is 
  signal r_SIG1   : std_logic := '0'; 
  signal r_SIG2   : std_logic := '0'; 
  signal w_RESULT : std_logic; 
  
  component and_gate is 
    port ( 
      input_1    : in  std_logic; 
      input_2    : in  std_logic; 
      and_result : out std_logic
    ); 
  end component; 
begin 
  and_gate_INST : and_gate port map ( 
    input_1    => r_SIG1, 
    input_2    => r_SIG2, 
    and_result => w_RESULT 
  ); 
  
  process is 
  begin 
    r_SIG1 <= '0'; r_SIG2 <= '0'; wait for 10 ns; 
    r_SIG1 <= '0'; r_SIG2 <= '1'; wait for 10 ns; 
    r_SIG1 <= '1'; r_SIG2 <= '0'; wait for 10 ns; 
    r_SIG1 <= '1'; r_SIG2 <= '1'; wait for 10 ns; 
  end process; 
end behave;

ModelSim 仿真全流程操作

1. 创建工程

打开 ModelSim,选择 File → New → Project。设置工程路径与名称(如 and_gate),扩展名 .prj,库映射保持默认 work。

2. 添加源文件

点击 Add Existing File,选中上述两个 .vhd 文件加入工程,其余设置默认,点击 OK。

3. 编译源文件

工程窗口中文件旁显示蓝色问号,表示未编译。右键 and_gate.vhd → Compile → Compile All。Console 窗口显示绿色编译成功信息。

4. 启动仿真

菜单栏 Simulate → Start Simulation。展开 work → and_gate_tb,选中 and_gate_tb(而非 and_gate),点击 OK。仿真就绪窗口出现。

5. 添加波形信号

右键仿真窗口中的 and_gate_tb → Add Wave,或从其他窗口拖拽信号至波形窗口。本例监控测试平台所有信号。

6. 运行仿真与观察波形

点击工具栏 Run 100 ns 图标(带下箭头的文档图标),仿真运行 100 纳秒。观察信号随激励变化的时序波形。恭喜,您已完成首次 ModelSim 仿真!

掌握了建工程、加文件、编译、启动仿真、看波形的完整流程,即可自行探索更多仿真案例。页面顶部侧边栏提供导航。

VHDL

  1. 在块RAM中设计健壮的VHDL环形缓冲区FIFO
  2. 你的第一个 VHDL 程序:分步 Hello World 教程
  3. 在Linux VPS上用Jenkins、Vivado、GitHub自动化FPGA开发
  4. 精通VHDL与Verilog:编写整洁组合与时序逻辑
  5. 用 OSVVM 掌握约束随机验证
  6. 利用进程内过程简化VHDL状态机设计
  7. 构建VHDL时钟触发进程实战指南
  8. 掌握VHDL Case-When语句:高效多路选择器设计
  9. FPGA入门实战:LED闪烁教程(VHDL与Verilog)
  10. 基于Tcl的交互式测试平台增强硬件验证
  11. VHDL进阶测验第2部分:测试你的HDL专业知识
  12. 善用VHDL记录类型构建整洁可复用FIFO接口