简体   繁体   English

T触发器使用数据流model

[英]T flip-flop using dataflow model

I'm trying to simulate the working of t-flipflop.我正在尝试模拟 t-触发器的工作。

`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

Now in output the value of q toggles when t=1, but the value of qbar is always 1.现在在 output 中,q 的值在 t=1 时切换,但 qbar 的值始终为 1。

Also when t=1, q is always 0 and qbar is 1.同样,当 t=1 时,q 始终为 0,qbar 为 1。

What am I doing wrong?我究竟做错了什么?

Test fixture:测试夹具:

`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 

输出信号

I want to implement this with the data flow model to understand it clearly.我想用数据流model来实现这个,理解清楚。

You are attempting to model sequential logic with continuous assignments.您正在尝试使用连续分配的 model 顺序逻辑。 This can result in unpredictable simulation results.这可能会导致不可预测的模拟结果。 For example, when I run your code using Incisive, it results in an infinite loop, which usually indicates a race condition.例如,当我使用 Incisive 运行您的代码时,它会导致无限循环,这通常表示竞争条件。 I assume the race is due to the feedback path: q depends on qbar which in turn depends on q .我假设比赛是由于反馈路径: q取决于qbar ,而 qbar 又取决于q

The proper way to model sequential logic is to use this register-transfer logic (RTL) coding style: model 时序逻辑的正确方法是使用这种寄存器传输逻辑 (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

This eliminates the feedback path and simplifies your code by eliminating the internal wires.这消除了反馈路径,并通过消除内部连线简化了您的代码。 It can also be used for synthesis.也可用于合成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM