Skip to content

Commit 8757281

Browse files
authored
Made the verilog module consistent with the Circuit simulation logic (#619)
* made the verilog module consistent with the simulation logic * fixed logic
1 parent c2c685c commit 8757281

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/simulator/src/sequential/DflipFlop.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,18 @@ export default class DflipFlop extends CircuitElement {
135135
module DflipFlop(q, q_inv, clk, d, a_rst, pre, en);
136136
parameter WIDTH = 1;
137137
output reg [WIDTH-1:0] q, q_inv;
138-
input clk, a_rst, pre, en;
139-
input [WIDTH-1:0] d;
138+
input clk, a_rst, en;
139+
input [WIDTH-1:0] d, pre;
140140
141-
always @ (posedge clk or posedge a_rst)
142-
if (a_rst) begin
143-
q <= 'b0;
144-
q_inv <= 'b1;
145-
end else if (en == 0) ;
146-
else begin
147-
q <= d;
148-
q_inv <= ~d;
141+
always @ (posedge clk or posedge a_rst) begin
142+
if (a_rst) begin
143+
q <= pre;
144+
q_inv <= ~pre;
145+
end else if (en) begin
146+
q <= d;
147+
q_inv <= ~d;
148+
end
149+
// When en == 0, hold current state
149150
end
150151
endmodule
151152
`

0 commit comments

Comments
 (0)