Closed abdulhameed-akram closed 4 months ago
NOTE: I am not an iverilog contributor.
It's been a spell since I've written synchronous logic, so forgive me if I'm mistaken:
You are assigning data_out <= data_out_reg
on posedge clk
, and you are also updating data_out_reg
on the same posedge. Since there are no delays in the modules, I think that this probably is the expected behavior.
Can you assign data_out <= data_out_reg
on negedge clk
instead?
It is in fact non-deterministic. Either result is possible, depending on the order in which the simulator processes events. Always use non-blocking assignments when modelling flip-flops to avoid this.
Closing as this is not an Icarus Verilog issue.
The rtl design is as follows:
When simulated with following testbench :
Result in following waveform:
Here we see data_out and data_out_reg are on same cycle, even though data_out should be on next cycle.
if we only instantiate large mux, then we get correct result i.e data_out on next cycle after data_out_reg.