我已经为SR闩锁,SR触发器(通过实例化SR闩锁模块)和JK触发器(通过实例化SR闩锁模块)编写了verilog模块。我正在使用Xilinx Vivado 2019版本进行仿真和查看输出波形。 SR锁存器和SR触发器模块工作正常,我也获得了正确的输出波形。我尝试通过实例化SR锁存模块来创建JK触发器模块。但是我只是没有得到输出波形。我不知道怎么了。我也检查了布尔表达式。一切似乎都很好。有人可以指出错误吗?
这里是密码。
SR锁存模块
module sr_latch(s, r, q, qbar);
input s, r;
output q, qbar;
nand(q, s, qbar);
nand(qbar, r, q);
endmodule
使用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
使用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触发器测试台
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
答案 0 :(得分:0)
您的输出未知(X
,因为您的jk_ff
模型不允许正确初始化SR锁存器。
基于此简单原理图,您只需在SR锁存器的输入上实现2个NAND门:
这是使用连续分配的一种方法:
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
这将使输出变得已知。
另一种方法是添加2个nand
基元。
请注意,JK触发器可以由SR 锁存器而不是SR 触发器构成。