feat:接入iverilog工具
- 将iverilog可以随着插件的下载而下载 - 用户输入自然语言就可以控制生成对应的VCD文件
This commit is contained in:
134
tools/iverilog/examples/README.md
Normal file
134
tools/iverilog/examples/README.md
Normal file
@ -0,0 +1,134 @@
|
||||
# Iverilog 测试示例
|
||||
|
||||
这个目录包含一个简单的 Verilog 项目示例,用于测试 IC Coder 插件的 VCD 生成功能。
|
||||
|
||||
## 文件说明
|
||||
|
||||
- **counter.v** - 一个简单的 4 位计数器模块
|
||||
- **counter_tb.v** - 计数器的测试平台(testbench)
|
||||
|
||||
## 功能说明
|
||||
|
||||
### counter.v(顶层模块)
|
||||
|
||||
这是一个同步复位的 4 位计数器:
|
||||
- **输入**:
|
||||
- `clk` - 时钟信号
|
||||
- `rst_n` - 低电平有效的复位信号
|
||||
- **输出**:
|
||||
- `count[3:0]` - 4 位计数值(0-15)
|
||||
|
||||
### counter_tb.v(测试平台)
|
||||
|
||||
测试平台包含:
|
||||
- 时钟生成器(100MHz,周期 10ns)
|
||||
- 复位序列(初始复位 20ns)
|
||||
- VCD 波形文件生成
|
||||
- 信号监控和显示
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 方法 1:使用 IC Coder 插件(推荐)
|
||||
|
||||
1. 在 VS Code 中打开这个 `examples` 目录作为工作区
|
||||
2. 打开 IC Coder 插件面板
|
||||
3. 在聊天框中输入以下任一命令:
|
||||
- `生成 VCD`
|
||||
- `运行仿真`
|
||||
- `生成波形`
|
||||
4. 插件会自动编译并运行仿真,生成 `output.vcd` 文件
|
||||
|
||||
### 方法 2:手动运行(用于测试)
|
||||
|
||||
在命令行中执行:
|
||||
|
||||
```bash
|
||||
# 进入示例目录
|
||||
cd "D:\IC Coder Plugin\ic-coder\tools\iverilog\examples"
|
||||
|
||||
# 编译 Verilog 文件
|
||||
"D:\IC Coder Plugin\ic-coder\tools\iverilog\bin\iverilog.exe" -o simulation.vvp counter.v counter_tb.v
|
||||
|
||||
# 运行仿真
|
||||
"D:\IC Coder Plugin\ic-coder\tools\iverilog\bin\vvp.exe" simulation.vvp
|
||||
|
||||
# 查看生成的 VCD 文件
|
||||
ls -lh output.vcd
|
||||
```
|
||||
|
||||
## 预期输出
|
||||
|
||||
### 控制台输出
|
||||
|
||||
```
|
||||
Time=0 ns, rst_n=0, count=0 (0x0)
|
||||
Time=20 ns, rst_n=1, count=0 (0x0)
|
||||
Time=25 ns, rst_n=1, count=1 (0x1)
|
||||
Time=35 ns, rst_n=1, count=2 (0x2)
|
||||
Time=45 ns, rst_n=1, count=3 (0x3)
|
||||
...
|
||||
Time=215 ns, rst_n=1, count=15 (0xf)
|
||||
Final count value: 15
|
||||
```
|
||||
|
||||
### 生成的文件
|
||||
|
||||
- **simulation.vvp** - 编译后的中间文件(可以删除)
|
||||
- **output.vcd** - VCD 波形文件(约 2-5 KB)
|
||||
|
||||
## 查看波形
|
||||
|
||||
使用 GTKWave 查看生成的 VCD 文件:
|
||||
|
||||
```bash
|
||||
gtkwave output.vcd
|
||||
```
|
||||
|
||||
在 GTKWave 中:
|
||||
1. 在左侧 SST 窗口选择 `counter_tb`
|
||||
2. 将信号 `clk`、`rst_n`、`count[3:0]` 拖到波形窗口
|
||||
3. 点击 "Zoom Fit" 查看完整波形
|
||||
|
||||
## 波形说明
|
||||
|
||||
你应该能看到:
|
||||
- **clk** - 规则的时钟信号(10ns 周期)
|
||||
- **rst_n** - 初始 20ns 为低电平,然后保持高电平
|
||||
- **count** - 从 0 开始递增到 15 的计数值
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 问题:编译失败
|
||||
|
||||
**检查**:
|
||||
- 确认 iverilog.exe 在 `tools/iverilog/bin/` 目录中
|
||||
- 确认所有 DLL 文件都已复制
|
||||
|
||||
### 问题:VCD 文件未生成
|
||||
|
||||
**检查**:
|
||||
- testbench 中是否包含 `$dumpfile("output.vcd");`
|
||||
- testbench 中是否包含 `$dumpvars(0, counter_tb);`
|
||||
- 仿真是否正常结束(有 `$finish;`)
|
||||
|
||||
### 问题:路径错误
|
||||
|
||||
**解决**:
|
||||
- 确保在正确的工作区目录中运行
|
||||
- 检查路径中是否有特殊字符
|
||||
|
||||
## 扩展练习
|
||||
|
||||
你可以修改这个示例来学习:
|
||||
|
||||
1. **修改计数器位宽**:将 4 位改为 8 位
|
||||
2. **添加使能信号**:只在使能时计数
|
||||
3. **添加加载功能**:可以加载初始值
|
||||
4. **创建递减计数器**:向下计数
|
||||
5. **添加溢出标志**:计数到最大值时输出标志
|
||||
|
||||
## 参考资料
|
||||
|
||||
- Verilog 语法:https://www.asic-world.com/verilog/
|
||||
- Icarus Verilog 文档:http://iverilog.icarus.com/
|
||||
- GTKWave 使用:http://gtkwave.sourceforge.net/
|
||||
17
tools/iverilog/examples/counter.v
Normal file
17
tools/iverilog/examples/counter.v
Normal file
@ -0,0 +1,17 @@
|
||||
// counter.v - 简单的 4 位计数器模块
|
||||
|
||||
module counter (
|
||||
input wire clk,
|
||||
input wire rst_n,
|
||||
output reg [3:0] count
|
||||
);
|
||||
|
||||
always @(posedge clk or negedge rst_n) begin
|
||||
if (!rst_n) begin
|
||||
count <= 4'b0000;
|
||||
end else begin
|
||||
count <= count + 1;
|
||||
end
|
||||
end
|
||||
|
||||
endmodule
|
||||
54
tools/iverilog/examples/counter_tb.v
Normal file
54
tools/iverilog/examples/counter_tb.v
Normal file
@ -0,0 +1,54 @@
|
||||
// counter_tb.v - 计数器测试平台
|
||||
|
||||
`timescale 1ns/1ps
|
||||
|
||||
module counter_tb;
|
||||
|
||||
// 信号声明
|
||||
reg clk;
|
||||
reg rst_n;
|
||||
wire [3:0] count;
|
||||
|
||||
// 实例化被测模块
|
||||
counter uut (
|
||||
.clk(clk),
|
||||
.rst_n(rst_n),
|
||||
.count(count)
|
||||
);
|
||||
|
||||
// 生成时钟信号 (10ns 周期 = 100MHz)
|
||||
initial begin
|
||||
clk = 0;
|
||||
forever #5 clk = ~clk;
|
||||
end
|
||||
|
||||
// 测试序列
|
||||
initial begin
|
||||
// 生成 VCD 波形文件
|
||||
$dumpfile("output.vcd");
|
||||
$dumpvars(0, counter_tb);
|
||||
|
||||
// 初始化信号
|
||||
rst_n = 0;
|
||||
|
||||
// 等待 20ns 后释放复位
|
||||
#20;
|
||||
rst_n = 1;
|
||||
|
||||
// 运行 200ns 让计数器计数
|
||||
#200;
|
||||
|
||||
// 显示最终计数值
|
||||
$display("Final count value: %d", count);
|
||||
|
||||
// 结束仿真
|
||||
$finish;
|
||||
end
|
||||
|
||||
// 监控输出变化
|
||||
initial begin
|
||||
$monitor("Time=%0t ns, rst_n=%b, count=%d (0x%h)",
|
||||
$time, rst_n, count, count);
|
||||
end
|
||||
|
||||
endmodule
|
||||
Reference in New Issue
Block a user