24.03.2013 Views

ModelSim SE User's Manual - Electrical and Computer Engineering

ModelSim SE User's Manual - Electrical and Computer Engineering

ModelSim SE User's Manual - Electrical and Computer Engineering

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

UM-132 5 - Verilog simulation<br />

Event ordering in Verilog designs<br />

<strong>ModelSim</strong> <strong>SE</strong> User’s <strong>Manual</strong><br />

Event-based simulators such as <strong>ModelSim</strong> may process multiple events at a given<br />

simulation time. The Verilog language is defined such that you cannot explicitly control the<br />

order in which simultaneous events are processed. Unfortunately, some designs rely on a<br />

particular event order, <strong>and</strong> these designs may behave differently than you expect.<br />

Event queues<br />

Section 5 of the IEEE Std 1364-1995 LRM defines several event queues that determine the<br />

order in which events are evaluated. At the current simulation time, the simulator has the<br />

following pending events:<br />

active events<br />

inactive events<br />

non-blocking assignment update events<br />

monitor events<br />

future events<br />

- inactive events<br />

- non-blocking assignment update events<br />

The LRM dictates that events are processed as follows – 1) all active events are processed;<br />

2) the inactive events are moved to the active event queue <strong>and</strong> then processed; 3) the<br />

non-blocking events are moved to the active event queue <strong>and</strong> then processed; 4) the monitor<br />

events are moved to the active queue <strong>and</strong> then processed; 5) simulation advances to the next<br />

time where there is an inactive event or a non-blocking assignment update event.<br />

Within the active event queue, the events can be processed in any order, <strong>and</strong> new active<br />

events can be added to the queue in any order. In other words, you cannot control event<br />

order within the active queue. The example below illustrates potential ramifications of this<br />

situation.<br />

Say you have these four statements:<br />

1 always@(q) p = q;<br />

2 always @(q) p2 = not q;<br />

3 always @(p or p2) clk = p <strong>and</strong> p2;<br />

4 always @(posedge clk)<br />

<strong>and</strong> current values as follows: q = 0, p = 0, p2=1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!