简体   繁体   English

我的触发器JK总是返回X

[英]my Flip Flop JK always return X

I want to write flip flop JK. 我想写触发器JK。 I wrote it, but when I run it, it always returns x. 我写了它,但是当我运行它时,它总是返回x。 It's supposed to look like this: pic and test module just for testing 它应该看起来像这样: pic和test模块仅用于测试

`timescale 1ns / 100ps
module flipflopJK(input j , k , r , s , clk , output q , nq);//nq = not q -- r=rest -- s=set 
    wire w1,w2,w3,w4;//explaine wires in pic in file
    assign w3=q;
    assign w4=nq;
    nand n1(w1,j,clk,nq);
    nand n1(w2,k,clk,w3);
    nand n3(q,r,w1,w4);
    nand n4(nq,s,w2,w3);
endmodule 
module test;
    reg clk,rst,st,a,b;
    wire ck;
    flipflopJK f(.j(a),.k(b),.r(rst),.s(st),.clk(clk),.q(ck),.nq( ));
    initial
    begin
    $monitor("j:%b  k:%b    ck:%b",a,b,ck);
    end
    initial
    begin
        clk = 1'b0;
        rst = 1'b1;
        st=1'b1;
        a=1'b0;b=1'b0;
        #5 a=1'b0;b=1'b1;
        #10 a=1'b1;b=1'b0;
        #15 a=1'b1;b=1'b1;
    end
    always
        #5 clk = ~clk;

endmodule

result after compile it 编译后的结果

soroush@soroush:~/Desktop/MadarManteghi/P2$ vvp P2
j:0 k:0 ck:x
j:0 k:1 ck:x
j:1 k:0 ck:x
j:1 k:1 ck:x

I get compile errors. 我收到编译错误。 I changed the 2nd n1 instance to n2 . 我将第二个n1实例更改为n2

You need to pulse either st or rst low in your testbench. 您需要在测试台中将strst脉冲为低电平。

initial
begin
    clk = 1'b0;
    rst = 1'b1;
    st=1'b1;
    repeat (5) @(negedge clk);
    st=0;
    repeat (5) @(negedge clk);
    a=1'b0;b=1'b0;
    repeat (5) @(negedge clk);
    a=1'b0;b=1'b1;
    repeat (5) @(negedge clk);
    a=1'b1;b=1'b0;
    repeat (5) @(negedge clk);
    a=1'b1;b=1'b1;
end

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

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