logo

Verilog винаги блокира

Във Verilog винаги блокът е един от процедурните блокове. Изявленията вътре в винаги блок се изпълняват последователно.

Един винаги блок се изпълнява винаги, за разлика от началните блокове, които се изпълняват само веднъж в началото на симулацията. Винаги блокът трябва да има чувствителен списък или забавяне, свързано с него

Чувствителният списък е този, който казва на винаги блока кога да изпълни блока от код.

Синтаксис

java replaceall

The Verilog винаги блокирайте следния синтаксис

 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 

В горния пример ние описваме 2:1 мултиплексор с вход x и y. The това е избраният вход и м е изходът на mux.

Във всяка комбинирана логика изходът се променя всеки път, когато входът се променя. Когато тази теория се приложи към винаги блокове, тогава кодът вътре във винаги блоковете трябва да се изпълнява всеки път, когато входните или изходните променливи се променят.

ЗАБЕЛЕЖКА: Може да управлява reg и integer типове данни, но не може да управлява типове данни за кабели.

Има два типа чувствителен списък във Verilog, като например:

  1. Чувствителен към ниво (за комбинирани вериги).
  2. Чувствителен на ръбове (за джапанки).

Кодът по-долу е същият 2:1 mux, но изходът м вече е тригерен изход.

 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></=>

Необходимост от списък на чувствителността

Винаги блокът се повтаря непрекъснато по време на симулация. Списъкът с чувствителност носи определено усещане за синхронизиране, т.е. всеки път, когато някой сигнал в списъка с чувствителност се промени, винаги се задейства блокиране.

Ако няма оператори за управление на времето в винаги блок, симулацията ще виси поради безкраен цикъл с нулево забавяне.

Например, винаги блокирайте опитите за инвертиране на стойността на сигнала 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 се изпълняват при всеки положителен фронт на сигнала clk

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

Дизайн на последователни елементи

Кодът по-долу дефинира модул, наречен tff който приема въвеждане на данни, часовник и активно ниско нулиране. Тук блокът винаги се задейства или при положителния ръб на clk или отрицателния край на rstn .

1. Положителният край на часовника

Следните събития се случват на положителния ръб на часовника и се повтарят за всички положителни ръбове на часовника.

Етап 1: Първо, инструкцията if проверява стойността на активно-ниско нулиране rstn .

  • Ако rstn е нула, тогава изходът q трябва да бъде нулиран до стойността по подразбиране от 0.
  • Ако rstn е едно, тогава това означава, че нулирането не е приложено и трябва да следва поведението по подразбиране.

Стъпка 2: Ако предишната стъпка е невярна, тогава

  • Проверете стойността на d и ако се установи, че е единица, тогава обърнете стойността на 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></=>