【问题标题】:Verilog: T flip flop using dataflow modelVerilog:使用数据流模型的 T 触发器
【发布时间】:2018-04-04 12:22:06
【问题描述】:

我正在尝试模拟 t-flipflop 的工作。

`timescale 1ns / 1ps
module t_flipflop(
input t,
input clk,
input clear,
output q,
output qbar
);

 wire sbar, rbar;


 assign sbar= ~(t & clk & qbar & clear);
 assign rbar= ~(t & clk & q);

 assign q= ~(sbar & qbar);
 assign  qbar= ~(rbar & q & clear);
endmodule

现在在输出中 q 的值在 t=1 时切换,但 qbar 的值始终为 1

同样当 t=1 时,q 始终为 0,qbar 为 1。

我做错了什么?

测试夹具 -

`timescale 1ns / 1ps
module test_t_flipflop;

// Inputs
reg t;
reg clk;
reg clear;

// Outputs
wire q;
wire qbar;

// Instantiate the Unit Under Test (UUT)
t_flipflop uut (
    .t(t), 
    .clk(clk), 
    .clear(clear), 
    .q(q), 
    .qbar(qbar)
);



initial begin


    clear=1'b0;
    #34 clear=1'b1;


end

initial begin

    t=1'b0;
    clk=1'b0;
    forever #15 clk=~clk;
end



initial begin

    #10 t=1;
    #95 t=0;
    #40 t=1;
end 

编辑:添加了完整的测试夹具代码。

我想用数据流模型来实现这个,理解清楚

【问题讨论】:

    标签: verilog flip-flop


    【解决方案1】:

    您正在尝试使用连续分配对顺序逻辑进行建模。这可能导致不可预测的模拟结果。例如,当我使用 Incisive 运行您的代码时,它会导致无限循环,这通常表示竞争条件。我认为竞争是由于反馈路径:q 依赖于 qbar,而后者又依赖于 q

    对时序逻辑建模的正确方法是使用这种寄存器传输逻辑 (RTL) 编码风格:

    module t_flipflop (
        input t,
        input clk,
        input clear,
        output reg q,
        output qbar
    );
    
    assign qbar = ~q;
    
    always @(posedge clk or negedge clear) begin
        if (!clear) begin
            q <= 0;
        end else if (t) begin
            q <= ~q;
        end
    end
    endmodule
    

    这消除了反馈路径并通过消除内部接线简化了您的代码。也可用于合成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多