如何解决运行仿真时更改内部信号的值
我想知道如何更改内部信号的值并传播此修改。 我有一个计数器,在模拟的第三个周期中,其中 cnt(内部信号)取 3 我已将其强制为 0 两个周期。我发现的问题是在这两个循环之后,cnt 需要 5 而不是 1
add_force cnt_o 0 -after 400us [two cycles] .
你有什么解决方案可以解决这个问题吗? 注:用于故障攻击模拟
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
cnt_q <= 0;
end else begin
cnt_q = cnt_q + 1;
end
end
assign cnt_o = cnt_q
测试台:
logic [32 : 0] cnt;
logic clk;
logic rst_n;
counter test (.clk,.rst_n,.cnt_o(cnt) )
initial begin
clk = 0;
rst_n = 1;
end
always begin
clk = ~clk ;
end
解决方法
您应该强制使用 cnt_q
信号而不是 cnt_o
,因为 cnt_q
保留它以前的值。
不要使用 Vivado 特定的命令,而是在测试平台中使用 force/release
。这是一个完整的工作示例:
module counter (input clk,rst_n,output [32 : 0] cnt_o);
logic [32 : 0] cnt_q;
always_ff @(posedge clk or negedge rst_n) begin
if (!rst_n) begin
cnt_q <= 0;
end else begin
cnt_q <= cnt_q + 1;
end
end
assign cnt_o = cnt_q ;
endmodule
module tb;
logic [32 : 0] cnt;
logic clk;
logic rst_n;
counter test (.clk,.rst_n,.cnt_o(cnt));
initial begin
clk = 0;
rst_n = 0;
#22 rst_n = 1;
wait (test.cnt_q == 3);
force test.cnt_q = 0;
repeat (2) @(posedge clk);
release test.cnt_q;
end
always begin
#5 clk = ~clk;
end
endmodule
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。