【问题标题】:Change value of internal signals while running simulation运行仿真时更改内部信号的值
【发布时间】:2021-06-26 22:05:15
【问题描述】:

我想知道如何更改内部信号的值并传播此修改。 我有一个计数器,在模拟的第三个周期中,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

【问题讨论】:

    标签: tcl verilog simulation vivado


    【解决方案1】:

    您应该强制使用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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多