IMO, most of the time infinite loops happen is with clock generation. Especially if you've them set up to generate variable frequencies. For example, if you've a clock set up like this:
`timescale 1ns / 1ns
real period;
reg clk;
initial begin
period = 5.0;
clk = 1'b0;
forever begin
#(period/2) clk = !clk;
end
end
If you change period
then infinite loops can happen if you change period
to 0.0 accidentally.
Even trickier, sometimes period / 2
can fall outside of your timescale precision. For example, if you set period = 1.0
, then period / 2
is 0.5, and since your time precision is 1ns, this will snap to 0, causing infinite loops. If I suspect this, I usually put a guard on the time just before I go into the delay (again, careful with precision...) .
...
half_period_ns = period_ns / 2.0;
if( half_period_ns == 0 )
half_period_ns = 1;
#(half_period_ns) clk = !clk;
...
Another thing to do is to run the simulation in interactive mode and randomly Ctrl-C, type in the command to ask the simulator where it's at (simulator specific, sadly, but in Incisive it's where
I think), and resume the sim. Do this a few times and you'll be able to get an idea of code is taking up all the simulator's time.