Easy Tutorial
❮ Verilog Sync Intellij Idea Usage ❯

2.3 Verilog Sequential Logic UDP

Category Advanced Verilog Tutorial

Sequential Logic UDPs differ from combinational logic UDPs in both definition form and behavioral functionality, with the main differences as follows:

The representation of sequential logic UDPs is mainly divided into two types: level-triggered UDPs and edge-triggered UDPs.

Level-Triggered UDP

The output of a level-triggered UDP changes based on the change in the input level state.

The functional description of a D latch with a reset end is as follows:

Its truth table is (q represents the current state, q+ represents the next state):

In fact, the process of writing a UDP can be understood as a process of writing a truth table in a different format.

The UDP of a D latch with a reset end can be described as follows:

primitive d_latch(q, clear, en, d);
    output q;
    reg q;
    input d, en, clear;

    initial
        q = 0;

    table
    //clear      en      d      :q      :q+;
    1           ?        ?       :?      :0;   //clear
    0           0        ?       :?      :-;    //"-" means stable

    0           1        0       :?      :0;   //q = d
    0           1        1       :?      :1;
    endtable
endprimitive

Of course, you can also declare the type and assign initial values when listing port signals.

primitive d_latch2(
    output reg q = 0,
    input clear, en, d);
    ...
endprimitive

Edge-Triggered UDP

The output of an edge-triggered UDP changes based on the input edge transitions and/or changes in the input level state.

Directly provide the "truth table" of a D flip-flop with an asynchronous reset end (RST) and captures the signal on the falling edge of the clock:

It can be seen that this "truth table" also adds the concept of rising and falling edges, which is convenient for writing UDP code.

The sequential logic UDP description of this D flip-flop is as follows:

primitive D_TRI(
    output reg Q = 0,
    input RST, CP, D);
table
//RST      CP      D      :Q      :Q+;
//(1) Reset
1           ?        ?       :?      :0;  //RST=1 resets to zero
(??)        ?        ?       :?      :-;  //Ignore RST edge changes
//(2) Capture on falling clock edge
0           (10)     0       :?      :0;  //Capture signal on falling clock edge
0           (10)     1       :?      :1;
//possible negedge
0           (1x)     ?       :?      :-;  //May hold on falling clock edge
0           (x0)     ?       :?      :-;
//(3) Hold on rising clock edge
0           (0?)     ?       :?      :-;  //Hold on rising clock edge
//possible posedge
0           (x1)     ?       :?      :-;  //May hold on rising clock edge
//(4) Even if there is a data transition when not on a clock edge, the output still holds
0           ?        (??)    :?      :-;
endtable
endprimitive // D_TRI

Perform a simple simulation on this

WeChat Follow

❮ Verilog Sync Intellij Idea Usage ❯