D
Daku
Guest
Could some Verilog guru please help ? I
have a circuit consisting of two D flip-flops
with reset. Each of these are driven by a separate clock. The 'D'
inputs of both are
held at logic '1'.
The tricky part is the resets. The 'Q' outputs of the two D flip-flops
are fed into a NAND gate, and the output of this NAND gate acts
as the common reset signal for both the two flip-flops. My question
(with reference to the source code files attached below) is:
1. Is the way I am handling this reset signal
the correct one - I am holding the reset value
in a 'wire', and then this is being fed into each
of the 'reset' ports of the two flip-flops. If I try
hold the reset value in a 'reg' I get compilation errors about
continuous assignment.
module dfftb;
reg clock1;
reg clock2;
reg d;
wire resetwire;
wire q1, q1_bar;
wire q2, q2_bar;
initial
begin
$dumpfile ("/root/verilog/dfftb.vcd");
$dumpvars (1, dfftb);
clock1 = 0;
clock2 = 0;
d = 1;
#250 $finish;
end
always
begin
#5 clock1 = !clock1;
end
always
begin
#10 clock2 = !clock2;
end
nand(resetwire, q1, q2);
dff d0(
.d (d),
.clk (clock1),
.reset (resetwire),
.q (q1),
.q_bar (q1_bar)
);
dff d1(
.d (d),
.clk (clock2),
.reset (resetwire),
.q (q2),
.q_bar (q2_bar)
);
endmodule
module dff( d, clk, reset, q, q_bar);
input d;
input clk;
input reset;
output q;
output q_bar;
reg q;
reg q_bar;
always @ (posedge clk or negedge reset)
if(~reset)
begin
q <= 1'b0;
end
else
begin
q <= d;
q_bar <= !d;
end
endmodule
The code compiles and runs fine under Icarus Verilog 0.9.1.
have a circuit consisting of two D flip-flops
with reset. Each of these are driven by a separate clock. The 'D'
inputs of both are
held at logic '1'.
The tricky part is the resets. The 'Q' outputs of the two D flip-flops
are fed into a NAND gate, and the output of this NAND gate acts
as the common reset signal for both the two flip-flops. My question
(with reference to the source code files attached below) is:
1. Is the way I am handling this reset signal
the correct one - I am holding the reset value
in a 'wire', and then this is being fed into each
of the 'reset' ports of the two flip-flops. If I try
hold the reset value in a 'reg' I get compilation errors about
continuous assignment.
module dfftb;
reg clock1;
reg clock2;
reg d;
wire resetwire;
wire q1, q1_bar;
wire q2, q2_bar;
initial
begin
$dumpfile ("/root/verilog/dfftb.vcd");
$dumpvars (1, dfftb);
clock1 = 0;
clock2 = 0;
d = 1;
#250 $finish;
end
always
begin
#5 clock1 = !clock1;
end
always
begin
#10 clock2 = !clock2;
end
nand(resetwire, q1, q2);
dff d0(
.d (d),
.clk (clock1),
.reset (resetwire),
.q (q1),
.q_bar (q1_bar)
);
dff d1(
.d (d),
.clk (clock2),
.reset (resetwire),
.q (q2),
.q_bar (q2_bar)
);
endmodule
module dff( d, clk, reset, q, q_bar);
input d;
input clk;
input reset;
output q;
output q_bar;
reg q;
reg q_bar;
always @ (posedge clk or negedge reset)
if(~reset)
begin
q <= 1'b0;
end
else
begin
q <= d;
q_bar <= !d;
end
endmodule
The code compiles and runs fine under Icarus Verilog 0.9.1.