Hot take: The proper Verilog template for synchronously reset flip-flops looks like this. always @(posedge clk) begin [non-reset code here] if (reset) begin [reset code here] end end
-
-
Replying to @oe1cxw
Yes, and alternately: always @(posedge clock) begin [non-reset code] foo <= (reset == 1'b1) ? [reset value] : foo; bar <= (reset == 1'b1) ? [reset value] : bar; end Why? Compact, and simulates correctly if reset is X or Z. Else reset code fails to apply with an if.
1 reply 0 retweets 4 likes -
Replying to @elaforest
Your foo and bar are stuck at the reset value because non-blocking assignment. (All non-blocking assignment to foo/bar in [non-reset code] will be ignored and blocking assignments are not allowed because you must not mix blocking and non-blocking assignments for the same reg.)
2 replies 0 retweets 2 likes -
Replying to @oe1cxw
If reset is not asserted, won't those lines devolve to "foo <= foo", which has no effect (except adding a delta cycle to the simulation)? I don't know what the LRM says, but wouldn't a subsequent n-b assignment override a blocking one?
1 reply 0 retweets 0 likes -
Replying to @elaforest
If you have for example `foo <= 42; foo <= foo;` then the RHS of the second assignment refers to the value of `foo` before the first assignment. So the 2nd assignment reverts the effect of `foo <= 42;`. `x <= cond ? y : x;` is *not* identical to `if (cond) x <= y;`
1 reply 0 retweets 1 like -
Replying to @oe1cxw
Oh dear, I think you're right, but not "foo <= 42" I think: "reg foo = 0; always @(...) begin foo <= 42; foo <= foo; end" So the 2nd assignment gets 0, not 42?
1 reply 0 retweets 0 likes
Yes. That's putting `foo <= 42;` followed by `foo <= 0;` on the queue. They are then executed in that order, effectively assigning 0 to foo.
-
-
Replying to @oe1cxw
It all makes sense now, thank you. My example would work under reset, but fail outside of reset. Hah! :P And since I avoid blocking statements in @(posedge clk) (due to synthesis warnings about unused regs), then your first idiom seems to be the only way.
0 replies 0 retweets 1 likeThanks. Twitter will use this to make your timeline better. UndoUndo
-
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.