📄 ch09.7.htm
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML EXPERIMENTAL 970324//EN"><HTML><HEAD><META NAME="GENERATOR" CONTENT="Adobe FrameMaker 5.5/HTML Export Filter"><LINK REL="STYLESHEET" HREF="ch09.css"><TITLE> 9.7 Procedural timing controls </TITLE></HEAD><BODY BGCOLOR="#ffffff"><DIV><HR><P><A HREF="ch09.htm">Chapter start</A> <A HREF="ch09.6.htm">Previous page</A> <A HREF="ch09.8.htm">Next page</A></P></DIV><H1 CLASS="Section"><A NAME="pgfId=685"> </A>9.7 <A NAME="39185"> </A><A NAME="marker=180"> </A>Procedural timing controls </H1><P CLASS="Body"><A NAME="pgfId=686"> </A>The Verilog HDL has two types of explicit timing control over when procedural statements can occur. The first type is a <I CLASS="Emphasis">delay control</I><A NAME="marker=181"> </A> in which an expression specifies the time duration between initially encountering the statement and when the statement actually executes. The delay expression can be a dynamic function of the state of the circuit, but can be a simple number that separates statement executions in time. The delay control is an important feature when specifying stimulus waveform descriptions. It is described in sections <A HREF="ch09.7.htm#41281" CLASS="XRef">See Delay control</A>, and <A HREF="ch09.7.htm#26871" CLASS="XRef">See Intra-assignment timing controls</A>.</P><P CLASS="Body"><A NAME="pgfId=687"> </A>The second type of <A NAME="marker=188"> </A>timing control is the <I CLASS="Emphasis">event expression</I><A NAME="marker=189"> </A>, which allows statement execution to be delayed until the occurrence of some simulation event occurring in a procedure executing concurrently with this procedure. A simulation event can be a change of value on a net or register (an <A NAME="marker=190"> </A>implicit <A NAME="marker=191"> </A>event), or the occurrence of an explicitly named event that is triggered from other procedures (an <A NAME="marker=192"> </A>explicit <A NAME="marker=193"> </A>event). Most often, an <A NAME="marker=194"> </A>event control is a positive or negative edge on a clock signal. Sections <A HREF="ch09.7.htm#92814" CLASS="XRef">See Event control</A> through <A HREF="ch09.7.htm#26871" CLASS="XRef">See Intra-assignment timing controls</A> discuss event control.</P><P CLASS="Body"><A NAME="pgfId=688"> </A>The procedural statements encountered so far all execute without advancing simulation time. Simulation time can advance by one of the following three methods:</P><UL><LI CLASS="DashedList"><A NAME="pgfId=689"> </A>a<CODE CLASS="code"> </CODE><B CLASS="codebold">delay</B> control, which is introduced by the symbol #</LI><LI CLASS="DashedList"><A NAME="pgfId=690"> </A>an <B CLASS="codebold">event</B> control, which is introduced by the symbol @</LI><LI CLASS="DashedList"><A NAME="pgfId=418"> </A>the<CODE CLASS="code"> </CODE><B CLASS="codebold">wait</B><A NAME="marker=115"> </A> statement, which operates like a combination of the event control and the while loop</LI></UL><P CLASS="Body"><A NAME="pgfId=419"> </A>The following syntax describes timing control in procedural statements:</P><P CLASS="Body"><A NAME="pgfId=564"> </A></P><DIV><IMG SRC="ch09-31.gif"></DIV><P CLASS="BNFCapBody"><A NAME="pgfId=566"> </A>Syntax 9-8: Syntax for procedural timing control</P><P CLASS="Body"><A NAME="pgfId=464"> </A>The gate and net delays also advance simulation time as discussed in <A HREF="/Humuhumu/Files/Prof_Smith/Academic/ASICs/Web/ASICs/HTML/Verilog/LRM/HTML/09/ch06.htm#26312" CLASS="XRef"></A>. The next subsections discuss the three procedural timing control methods.</P><P CLASS="SubSection"><A NAME="pgfId=420"> </A><A NAME="41281"> </A><A NAME="marker=117"> </A>Delay control</P><P CLASS="Body"><A NAME="pgfId=691"> </A>A procedur<A NAME="marker=122"> </A>al statement following the delay control shall be delayed in its execution with respect to the procedural statement preceding the delay control by the specified delay. If the delay expression evaluates to an unknown or high impedance value, it shall be interpreted as zero delay. If the delay expression evaluates to a negative value, it shall be interpreted as a two's complement unsigned integer of the same size as a time variable.</P><DIV><H2 CLASS="Example"><A NAME="pgfId=397"> </A></H2><P CLASS="Body"><A NAME="pgfId=414"> </A>1. The following example delays the execution of the assignment by 10 time units:</P><PRE CLASS="CodeIndent"><A NAME="pgfId=692"> </A>#10 rega = regb;</PRE><P CLASS="Body"><A NAME="pgfId=526"> </A>2. The next three examples provide an expression following the number sign (#). Execution of the assignment is delayed by the amount of simulation time specified by the value of the expression.</P><PRE CLASS="CodeIndent"><A NAME="pgfId=553"> </A>#d rega = regb; // d is defined as a parameter#((d+e)/2) rega = regb;// delay is average of d and e#regr regr = regr + 1; // delay is the value in regr</PRE><P CLASS="SubSection"><A NAME="pgfId=694"> </A><A NAME="92814"> </A><A NAME="78422"> </A><A NAME="marker=203"> </A>Event control </P><P CLASS="Body"><A NAME="pgfId=696"> </A>The execution of a procedural statement can be synchronized with a value change on a net or register, or the occurrence of a declared event. The value changes on nets and registers can be used as events to trigger the execution of a statement. This is known as detecting<I CLASS="Emphasis"> an implicit event</I>. The event can also be based on the direction of the change--that is, toward the value 1 (<B CLASS="Keyword">posedge</B>) or toward the value 0 (<B CLASS="Keyword">negedge</B>). The behavior of posedge and negedge event is shown in <A HREF="ch09.7.htm#95856" CLASS="XRef">See : Detecting posedge and negedge</A> and can be described as follows: </P><UL><LI CLASS="DashedList"><A NAME="pgfId=697"> </A>a <I CLASS="Emphasis">negedge</I> shall be detected on the transition from <CODE CLASS="code">1</CODE> to <CODE CLASS="code">x</CODE>, <CODE CLASS="code">z</CODE>, or <CODE CLASS="code">0</CODE>, and from <CODE CLASS="code">x</CODE> or <CODE CLASS="code">z</CODE> to <CODE CLASS="code">0</CODE></LI><LI CLASS="DashedList"><A NAME="pgfId=698"> </A>a <I CLASS="Emphasis">posedge</I> shall be detected on the transition from <CODE CLASS="code">0</CODE> to <CODE CLASS="code">x</CODE>, <CODE CLASS="code">z</CODE>, or <CODE CLASS="code">1</CODE>, and from <CODE CLASS="code">x</CODE> or <CODE CLASS="code">z</CODE> to <CODE CLASS="code">1</CODE></LI><TABLE BORDER="1"><CAPTION><P CLASS="TableTitle"><A NAME="pgfId=398"> </A>Table 9-1<A NAME="95856"> </A>: Detecting posedge and negedge</P></CAPTION><TR><TH ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=860"> </A></P></TH><TH ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=872"> </A>To</P></TH><TH ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=861"> </A>0</P></TH><TH ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=862"> </A>1</P></TH><TH ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=868"> </A>x</P></TH><TH ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=871"> </A>z</P></TH></TR><TR><TH ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=819"> </A>From</P></TH><TH ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=855"> </A></P></TH><TH ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=820"> </A></P></TH><TH ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=821"> </A></P></TH><TH ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=822"> </A></P></TH><TH ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=823"> </A></P></TH></TR><TR><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=824"> </A>0</P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=856"> </A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=825"> </A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=826"> </A>posedge</P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=827"> </A>posedge</P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=828"> </A>posedge</P></TD></TR><TR><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=829"> </A>1</P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=857"> </A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=830"> </A>negedge</P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=831"> </A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=832"> </A>negedge</P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=833"> </A>negedge</P></TD></TR><TR><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=834"> </A>x</P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=858"> </A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=836"> </A>negedge</P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=846"> </A>posedge</P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=847"> </A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=848"> </A></P></TD></TR><TR><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=849"> </A>z</P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellHeading"><A NAME="pgfId=859"> </A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=850"> </A>negedge</P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=851"> </A>posedge</P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=852"> </A></P></TD><TD ROWSPAN="1" COLSPAN="1"><P CLASS="CellBody"><A NAME="pgfId=853"> </A></P></TD></TR></TABLE></UL><P CLASS="Body"><A NAME="pgfId=699"> </A>If the expression evaluates to more than one bit result, the edge transition shall be detected on the least significant bit of the result. The change of value in any of the operands without a change in the value of the least significant bit of the expression result shall not be detected as an edge.</P></DIV><DIV><H2 CLASS="Example"><A NAME="pgfId=490"> </A></H2><P CLASS="Body"><A NAME="pgfId=450"> </A>The example below shows illustrations of edge controlled statements.</P><P CLASS="Body"><A NAME="pgfId=700"> </A></P><DIV><IMG SRC="ch09-32.gif"></DIV><P CLASS="SubSection"><A NAME="pgfId=702"> </A><A NAME="40970"> </A><A NAME="marker=205"> </A><A NAME="marker=206"> </A>Named events </P><P CLASS="Body"><A NAME="pgfId=703"> </A>A new data type, in addition to net and register, called event can be declared. An identifier declared as an event data type is called a n<A NAME="marker=123"> </A>amed event. A named event can be triggered explicitly, and can be used in an event expression to control the execution of procedural statements in the same manner as event control described in the previous section. Named events can be made to occur from a procedure. This allows control over the enabling of multiple actions in other procedures. </P><P CLASS="Body"><A NAME="pgfId=704"> </A>An event name shall be declared explicitly before it is used. The following is the <A NAME="marker=207"> </A><A NAME="marker=208"> </A>syntax for <A NAME="marker=209"> </A>declaring events.</P><P CLASS="Body"><A NAME="pgfId=705"> </A></P><DIV><IMG SRC="ch09-33.gif"></DIV><P CLASS="BNFCapBody"><A NAME="pgfId=706"> </A>Syntax 9-9: Syntax for event declaration</P><P CLASS="Body"><A NAME="pgfId=707"> </A>An event shall not hold any data. The following are the characteristics of a named event:</P><UL><LI CLASS="DashedList">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -