简体   繁体   English

在 Verilog 中使用 SR 触发器模块创建 JK 触发器模块

[英]Creating a JK Flip Flop module using an SR Flip Flop Module in Verilog

I have written verilog modules for SR Latch, SR Flip Flop (by instantiating the SR Latch module), and JK Flip Flop (by instantiating the SR Latch module).我已经为 SR Latch、SR Flip Flop(通过实例化 SR Latch 模块)和 JK Flip Flop(通过实例化 SR Latch 模块)编写了 verilog 模块。 I'm using Xilinx Vivado 2019 version for simulation and viewing output waveforms.我正在使用 Xilinx Vivado 2019 版本进行仿真和查看 output 波形。 The SR Latch and SR Flip flop modules work just fine and I'm getting the proper output waveforms also. SR 锁存器和 SR 触发器模块工作得很好,我也得到了正确的 output 波形。 I tried creating a JK Flip Flop Module by instantiating the SR Latch Module.我尝试通过实例化 SR 锁存器模块来创建 JK 触发器模块。 But I just don't get the output waveforms.但我就是没有得到 output 波形。 I don't know what is going wrong.我不知道出了什么问题。 I checked the Boolean expressions as well.我还检查了 Boolean 表达式。 Everything seems to be fine.一切似乎都很好。 Can someone please point out the error?有人可以指出错误吗?

Here are the codes.这是代码。

SR Latch Module SR 锁存模块

module sr_latch(s, r, q, qbar);
    input s, r;
    output q, qbar;
    nand(q, s, qbar);
    nand(qbar, r, q);
endmodule

SR Flip Flop Module using the SR Latch使用 SR 锁存器的 SR 触发器模块

module sr_ff(s, r, clk, q, qbar);
    input s, r, clk;
    output q, qbar;
    reg t1, t2;
    always @(posedge clk)
        begin
            t1 <= !(clk & s);
            t2 <= !(clk & r);
        end
    sr_latch SRL(t1, t2, q, qbar);
endmodule

JK Flip Flop using SR Latch使用 SR 锁存器的 JK 触发器

module jk_ff(j, k, clk, q, qbar);
    input j, k, clk;
    output q, qbar;
    reg t1, t2;
    always @(posedge clk)
        begin
            t1 <= !(clk & qbar & j);
            t2 <= !(clk & q & k);
        end
    sr_latch SRL(t2, t1, q, qbar);
endmodule

JK Flip Flop Testbench JK 触发器测试台

module jk_ff_tb();
    wire q, qbar;
    reg j, k, clk=1;
    integer i;
    jk_ff JKFF(j, k, clk, q, qbar);
    always #25 clk = !clk;

    initial
        begin
            for(i=0; i<4; i=i+1)
                begin
                    {j, k} <= i; #50;
                end
        $stop;
        end
endmodule

Your output is unknown ( X ) because your jk_ff model does not allow for proper initialization of the SR Latch.您的 output 未知 ( X ),因为您的jk_ff model 不允许正确初始化 SR Latch。

Based on this simple schematic, you need to just implement the 2 NAND gates on the inputs to the SR latch:根据这个简单的原理图,您只需在 SR 锁存器的输入上实现 2 个 NAND 门:

jkff 示意图

This is one way, using continuous assignments:这是一种方法,使用连续分配:

module jk_ff (j, k, clk, q, qbar);
    input j, k, clk;
    output q, qbar;
    wire sn = clk & qbar & j;
    wire rn = clk & q    & k;
    sr_latch SRL (sn, rn, q, qbar);
endmodule

This allows the output to become known.这使得 output 成为已知的。

Another way is to add 2 nand primitives.另一种方法是添加 2 个nand基元。

Note that the JK Flip-flop can be constructed from an SR Latch , not an SR Flip-flop .请注意,JK 触发器可以由 SR Latch构造,而不是 SR触发器

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

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