logo

Verilog は常にブロックします

Verilog では、always ブロックは手続き型ブロックの 1 つです。 always ブロック内のステートメントは順番に実行されます。

シミュレーションの開始時に 1 回だけ実行される初期ブロックとは異なり、always ブロックは常に実行されます。 Always ブロックには機密リストまたはそれに関連付けられた遅延が必要です

機密リストは、always ブロックにコードのブロックをいつ実行するかを指示するものです。

構文

ベリログ 次の構文を常にブロックします

 always @ (event) [statement] always @ (event) begin [multiple statements] end 

予約語の後の記号 @ いつも 、ブロックがトリガーされることを示します @ 記号の後の括弧内の条件。

 always @ (x or y or sel) begin m = 0; if (sel == 0) begin m = x; end else begin m = y; end end 

上の例では、入力 x と y を使用した 2:1 マルチプレクサについて説明します。の これ は選択入力であり、 メートル はマルチプレクサ出力です。

どのような組み合わせロジックでも、入力が変化するたびに出力も変化します。この理論を always ブロックに適用すると、入力変数または出力変数が変更されるたびに、always ブロック内のコードを実行する必要があります。

注: reg および integer データ型は駆動できますが、wire データ型は駆動できません。

Verilog には、次の 2 種類の機密リストがあります。

  1. レベルに敏感です(組み合わせ回路の場合)。
  2. エッジセンシティブ (フリップフロップの場合)。

以下のコードは同じ 2:1 マルチプレクサですが、出力は メートル はフリップフロップ出力になりました。

 always @ (posedge clk ) if (reset == 0) begin m <= 0; end else if (sel="=" 0) begin m <="x;" pre> <h4>NOTE: The always block is executed at some particular event. A sensitivity list defines the event.</h4> <h3>Sensitivity List</h3> <p>A sensitivity list is an expression that defines when the always block executed, and it is specified after the @ operator within the parentheses ( ). This list may contain either one or a group of signals whose value change will execute the always block.</p> <p>In the code shown below, all statements inside the always block executed whenever the value of signals x or y change.</p> <pre> // execute always block whenever value of &apos;x&apos; or &apos;y&apos; change always @ (x or y) begin [statements] end </pre> <p> <strong>Need of Sensitivity List</strong> </p> <p>The always block repeats continuously throughout a simulation. The sensitivity list brings a certain sense of timing, i.e., whenever any signal in the sensitivity list changes, the always block is triggered.</p> <p>If there are no timing control statements within an always block, the simulation will hang because of a zero-delay infinite loop.</p> <p>For example, always block attempts to invert the value of the signal clk. The statement is executed after every 0-time units. Hence, it executes forever because of the absence of a delay in the statement.</p> <pre> // always block started at time 0 units // But when is it supposed to be repeated // There is no time control, and hence it will stay and // be repeated at 0-time units only and it continues // in a loop and simulation will hang always clk = ~clk; </pre> <p>If the sensitivity list is empty, there should be some other form of time delay. Simulation time is advanced by a delay statement within the always construct.</p> <pre> always #10 clk = ~clk; </pre> <p>Now, the clock inversion is done after every 10-time units. That&apos;s why the real Verilog design code always requires a sensitivity list.</p> <h4>NOTE: Explicit delays are not synthesizable into logic gates.</h4> <h3>Uses of always block</h3> <p>An always block can be used to realize combinational or sequential elements. A sequential element like flip flop becomes active when it is provided with a clock and reset.</p> <p>Similarly, a combinational block becomes active when one of its input values change. These hardware blocks are all working concurrently independently of each other. The connection between each is what determines the flow of data.</p> <p>An always block is made as a continuous process that gets triggered and performs some action when a signal within the sensitivity list becomes active.</p> <p>In the following example, all statements within the always block executed at every positive edge of the signal clk</p> <pre> // execute always block at the positive edge of signal &apos;clk&apos; always @ (posedge clk) begin [statements] end </pre> <h3>Sequential Element Design</h3> <p>The below code defines a module called <strong> <em>tff</em> </strong> that accepts a data input, clock, and active-low reset. Here, the always block is triggered either at the positive edge of the <strong> <em>clk</em> </strong> or the negative edge of <strong> <em>rstn</em> </strong> .</p> <p> <strong>1. The positive edge of the clock</strong> </p> <p>The following events happen at the positive edge of the clock and are repeated for all positive edge of the clock.</p> <p> <strong>Step 1:</strong> First, if statement checks the value of active-low reset <strong> <em>rstn</em> </strong> .</p> <ul> <li>If <strong> <em>rstn</em> </strong> is zero, then output q should be reset to the default value of 0.</li> <li>If <strong> <em>rstn</em> </strong> is one, then it means reset is not applied and should follow default behavior.</li> </ul> <p> <strong>Step 2:</strong> If the previous step is false, then</p> <ul> <li>Check the value of d, and if it is found to be one, then invert the value of q.</li> <li>If d is 0, then maintain value of q.</li> </ul> <pre> module tff (input d, clk, rstn, output reg q); always @ (posedge clk or negedge rstn) begin if (!rstn) q <= 0; else if (d) q <="~q;" end endmodule pre> <p> <strong>2. Negative edge of reset</strong> </p> <p>The following events happen at the negative edge of <strong> <em>rstn</em> </strong> .</p> <p> <strong>Step 1:</strong> First, if statement checks the value of active-low reset <strong> <em>rstn</em> </strong> . At the negative edge of the signal, its value is 0.</p> <ul> <li>If the value of <strong> <em>rstn</em> </strong> is 0, then it means reset is applied, and output should be reset to the default value of 0.</li> <li>And if the value of <strong> <em>rstn</em> </strong> is 1, then it is not considered because the current event is a negative edge of the <strong> <em>rstn</em> </strong> .</li> </ul> <h3>Combinational Element Design</h3> <p>An always block can also be used in the design of combinational blocks.</p> <p>For example, the digital circuit below represents three different logic gates that provide a specific output at signal o.</p> <img src="//techcodeview.com/img/verilog-tutorial/39/verilog-always-block.webp" alt="Verilog Always Block"> <p>The code shown below is a module with four input ports and a single output port called o. The always block is triggered whenever any of the signals in the sensitivity list changes in value.</p> <p>The output signal is declared as type <strong> <em>reg</em> </strong> in the module port list because it is used in a procedural block. All signals used in a procedural block should be declared as type <strong> <em>reg</em> </strong> .</p> <pre> module combo (input a, input b, input c, input d, output reg o); always @ (a or b or c or d) begin o <= ~((a & b) | (c^d)); end endmodule < pre> <p>The signal o becomes 1 whenever the combinational expression on the RHS becomes true. Similarly, o becomes 0 when RHS is false.</p> <hr></=></pre></=></pre></=>

機密性リストの必要性

Always ブロックは、シミュレーション全体を通じて継続的に繰り返します。感度リストは、特定のタイミングの感覚をもたらします。つまり、感度リスト内の信号が変化するたびに、always ブロックがトリガーされます。

Always ブロック内にタイミング制御ステートメントがない場合、遅延ゼロの無限ループが原因でシミュレーションがハングします。

たとえば、always ブロックは信号 clk の値を反転しようとします。このステートメントは、0 時間単位ごとに実行されます。したがって、ステートメントに遅延がないため、永久に実行されます。

 // always block started at time 0 units // But when is it supposed to be repeated // There is no time control, and hence it will stay and // be repeated at 0-time units only and it continues // in a loop and simulation will hang always clk = ~clk; 

感度リストが空の場合は、何らかの他の形式の時間遅延が存在するはずです。シミュレーション時間は、always 構造内の遅延ステートメントによって進められます。

 always #10 clk = ~clk; 

現在、クロック反転は 10 時間単位ごとに行われます。このため、実際の Verilog 設計コードには常に感度リストが必要です。

注: 明示的な遅延は論理ゲートに合成できません。

Always ブロックの使用法

always ブロックを使用すると、組み合わせ要素または順次要素を実現できます。フリップフロップのようなシーケンシャル素子は、クロックとリセットが与えられるとアクティブになります。

同様に、組み合わせブロックは、その入力値の 1 つが変化するとアクティブになります。これらのハードウェア ブロックはすべて、互いに独立して同時に動作します。それぞれの間の接続がデータの流れを決定します。

Always ブロックは、感度リスト内の信号がアクティブになったときにトリガーされて何らかのアクションを実行する連続プロセスとして作成されます。

次の例では、always ブロック内のすべてのステートメントが信号 clk の正のエッジごとに実行されます。

 // execute always block at the positive edge of signal &apos;clk&apos; always @ (posedge clk) begin [statements] end 

シーケンシャル要素設計

以下のコードは、というモジュールを定義します。 ふふ データ入力、クロック、アクティブ LOW リセットを受け入れます。ここで、always ブロックは、 カチカチ または負のエッジ 最初の

1. クロックのポジティブエッジ

次のイベントはクロックの立ち上がりエッジで発生し、クロックのすべての立ち上がりエッジで繰り返されます。

ステップ1: まず、if ステートメントでアクティブロー リセットの値を確認します。 最初の

Javaの揮発性キーワード
  • もし 最初の がゼロの場合、出力 q はデフォルト値の 0 にリセットされる必要があります。
  • もし 最初の が 1 の場合、リセットは適用されず、デフォルトの動作に従う必要があることを意味します。

ステップ2: 前のステップが false の場合、

  • d の値を確認し、1 であることが判明した場合は、q の値を反転します。
  • d が 0 の場合、q の値を維持します。
 module tff (input d, clk, rstn, output reg q); always @ (posedge clk or negedge rstn) begin if (!rstn) q <= 0; else if (d) q <="~q;" end endmodule pre> <p> <strong>2. Negative edge of reset</strong> </p> <p>The following events happen at the negative edge of <strong> <em>rstn</em> </strong> .</p> <p> <strong>Step 1:</strong> First, if statement checks the value of active-low reset <strong> <em>rstn</em> </strong> . At the negative edge of the signal, its value is 0.</p> <ul> <li>If the value of <strong> <em>rstn</em> </strong> is 0, then it means reset is applied, and output should be reset to the default value of 0.</li> <li>And if the value of <strong> <em>rstn</em> </strong> is 1, then it is not considered because the current event is a negative edge of the <strong> <em>rstn</em> </strong> .</li> </ul> <h3>Combinational Element Design</h3> <p>An always block can also be used in the design of combinational blocks.</p> <p>For example, the digital circuit below represents three different logic gates that provide a specific output at signal o.</p> <img src="//techcodeview.com/img/verilog-tutorial/39/verilog-always-block.webp" alt="Verilog Always Block"> <p>The code shown below is a module with four input ports and a single output port called o. The always block is triggered whenever any of the signals in the sensitivity list changes in value.</p> <p>The output signal is declared as type <strong> <em>reg</em> </strong> in the module port list because it is used in a procedural block. All signals used in a procedural block should be declared as type <strong> <em>reg</em> </strong> .</p> <pre> module combo (input a, input b, input c, input d, output reg o); always @ (a or b or c or d) begin o <= ~((a & b) | (c^d)); end endmodule < pre> <p>The signal o becomes 1 whenever the combinational expression on the RHS becomes true. Similarly, o becomes 0 when RHS is false.</p> <hr></=></pre></=>