Torrid Fish

Back

Analyze and Design Sequential circuit#

Sensitivity List#

  1. Once using sensitivity list (posedge, negedge), then all signal must use sensitivity list.
  2. assign use <=. (In sequential circuit always @(posedge clk), rather than use =. (in combinational circuit always @*)
<==
Using timingSequential circuitCombinational circuit
MeaningUse old valueUse new value
Example
  1. Results of operators (at the left side of assignment) inside always block must be declared as register, for example:
// Code A
reg z;
wire c;
always @* begin
    z = x || y
    c = x || y // wrong code
end
        
// Code B
wire z;
assign z = x && y // z is not a reg here
verilog
  1. There are two types of coding:

Finite-State Machine (FSM)#

  • Sychronous sequential circuit (a.k.a. clocked sequential circuit) is a kind of Finite-State Machine.
  • Current state at time tt is stored in a set of flip-flops.
  • (input, current state) => (output, next state) next state at time t+1t+1 is a boolean function of the present state and input.

Different types of output function decides different types of circuit.

Mealy machine (circuit)#

Info:

The output is a function of both present state and input.

And here is an example state diagram:

digraph mealy{
    layout = circo
    node [shape = circle];
    s1 -> s1 [label = "1/1"];
    s1 -> s2 [label = "0/1"];
    s0 -> s1 [label = "1/0"];
    s0 -> s2 [label = "0/0"];
}
plaintext

Moore machine (circuit)#

Info:

The output is a function of present state only.

And here is an example state diagram:

digraph moore{
    layout = circo
    node [shape = circle];
    k [shape = point];
    s0 [label = "s0\n 00"];
    s1 [label = "s1\n 01"];
    s2 [label = "s2\n 11"];
    k -> s0 ;
    s1 -> s1 [label = "1"];
    s1 -> s2 [label = "0"];
    s0 -> s1 [label = "1"];
    s0 -> s2 [label = "0"];
}
plaintext

Analysis#

Illustration#

Ok, lets start analyzing. First, take a look at this example: First, look at the combinational part, we can obtain:

DA=AX+BXDB=AXY=(A+B)X\begin{align} D_A &= AX+BX \\ D_B &= A'X \\ Y &= (A+B)X' \end{align}

process:

Also, we have known that in a D flip-flop, Q(t+1)=DQ(t+1) = D. So we will get:

A(t+1)=DA=A(t)X(t)+B(t)X(t)B(t+1)=DB=A(t)X(t)\begin{align} A(t+1) &= D_A = A(t)X(t)+B(t)X(t) \\ B(t+1) &= D_B = A'(t)X(t) \end{align}

Hence, we can get:

{A(t+1)=DA=A(t)X(t)+B(t)X(t)B(t+1)=DB=A(t)X(t)Y=(A+B)X\begin{cases} A(t+1) &= D_A = A(t)X(t)+B(t)X(t) \\ B(t+1) &= D_B = A'(t)X(t) \\ Y &= (A+B)X' \end{cases}

After this process, we want to record the status as truth table,so we define a status table. There are two ways to represent: After this, we can use a state diagram to represent the transition. Info:

State diagram#

  • circle : a state
  • directed line : transition between the states
  • On the edge, it is either output (Moore) or input/output(Mealy).
digraph state_diagram{
    node [shape = circle];
    layout = circo;
    00 -> 00 [label = "0/0"];
    10 -> 10 [label = "1/0"];
    00 -> 01 [label = "1/0"];
    01 -> 00 [label = "0/1"];
    01 -> 11 [label = "1/0"];
    11 -> 00 [label = "0/1"];
    11 -> 10 [label = "1/0"];
    10 -> 00[label = "0/1"];
    
}
plaintext

Now, we can have the step to analyze a sequential circuit:

CircuitdiagramEquationsandStatetableStatediagramCircuit diagram \to Equations and State table\to State diagram

Lets look at another example.

Example_01 Analyze with DFF#

Look at this circuit, we can get:

DA=Axy    A(t+1)=A(t)x(t)y(t)\begin{align} D_A &= A\oplus x\oplus y \\ \implies A(t+1) &= A(t)\oplus x(t)\oplus y(t) \end{align}

Example_02 Analyze with JKFF#

We can find these equations:

JA=BKA=BXJB=XKB=AX\begin{align} J_A &= B \\ K_A &= BX' \\ J_B &= X' \\ K_B &= A \oplus X \end{align}

We then apply the characteristic equation Q(t+1)=JQ(t)+KQ(t)Q(t+1)=JQ'(t)+K'Q(t):

A(t+1)=JAA+KAA=BA+(BX)A=AB+AB+AXB(t+1)=JBB+KBB=XB+(AX)B=BX+ABX+ABX\begin{align} A(t+1) &= J_AA'+K_A'A= BA'+(BX')A \\ &= A'B + AB' + AX \\ B(t+1) &= J_BB'+K_B 'B = X'B' + (A\oplus X)'B \\ &= B'X' + ABX + A'BX' \end{align}

Complete the state table and diagram:

Example_03 Analyze with TFF#

By observation, we can get:

TA=xBTB=xy=AB\begin{align} T_A &= xB \\ T_B &= x \\ y &= AB \end{align}

Then by the characteristic equation Q(t+1)=TQQ(t+1)=T \oplus Q:

A(t+1)=(xB)A=AB+Ax+ABxB(t+1)=xB=xB+xBy=AB\begin{align} A(t+1) &= (xB)\oplus A \\ &= AB'+Ax'+A'Bx \\ B(t+1) &= x\oplus B \\ &= x'B+xB' \\ y &= AB \end{align}

Complete the state table and diagram:

Design#

Illustration#

There is a procedure to produce a sequential circuit: Info:

  1. Determine a state diagram or state table.

  2. State reduction if necessary.

  3. Assign binary values to the states. obtain binary-coded state table

  4. Choose the type of flip-flops. derive the simplified flip-flop input equations and output equations

  5. Obtain the logic diagram.

Without further ado, lets look at a example.

Example_01 String Detector#

Success:

Illustration#

Construct a recognizer that takes one bit at a time and generates an output Z=1Z=1 when and only when the sequence {1101}\{1101\} is detected at the input.

Input#

The input XX is the continous signal that you need to detect.

Output#

The output ZZ is 11 if there is a sequence {1101}\{1101\} and 00 otherwise.

Here is an example:

X=00110111001101101Z=00000100000001001\begin{align} X &= 0011011100\overline{110}\overline 1101\\ Z &= 00000100000001001 \end{align}

Lets define four states:

  • AA : there is no any char correspond to 11011101.
  • BB : so far, we have 11.
  • CC : so far, we have 1111.
  • DD : so far, we have 110110.

We can design like this:

First, we can construct the straight way to output 11.

digraph design{
    layout = circo
    node [shape = circle]
    
    A -> B [label = "1/0"];
    B -> C [label = "1/0"];
    C -> D [label = "0/0"];
    D -> B [label = "1/1"];
}
plaintext

Now, consider those fail condition.

digraph design{
    layout = circo
    node [shape = circle]
    
    A -> B [label = "1/0"];
    A -> A [label = "0/0", color = red];
    B -> C [label = "1/0"];
    B -> A [label = "0/0", color = red];
    C -> D [label = "0/0"];
    C -> C [label = "1/0", color = red];
    D -> B [label = "1/1"];
    D -> A [label = "0/0", color = red];
}
plaintext

Then we have the state diagram! Here is the corresponding state table:

For futher implementation, we need to use binary code to encode those states.

Remember that different binary code assignments may result in different final circuit with different time complexities.

Now, for example, we encode these four states like this, and thus we have:

Now, we are going to implement with D filp-flop. We use abab to represent the current state (If State is 0101, then a=0,b=1a = 0, b = 1). First, we need to write out the logic equations. details:

By using K-map: We can have reduced SOP form.

a(t+1)=Xb(t)+a(t)b(t)b(t+1)=XZ=abX\begin{align} a(t+1) &= Xb(t)+a(t)b(t)\\ b(t+1) &= X \\ Z &= ab'X' \end{align}

Then by a little reduction on a(t+1)a(t+1), we can have:

a(t+1)=(X+a(t))b(t)b(t+1)=XZ=abX\begin{align} a(t+1) &= (X+a(t))b(t)\\ b(t+1) &= X \\ Z &= ab'X' \end{align}

Since we want to use D flip-flop, we can use its characteristic equation Q(t+1)=DQ(t+1)=D to create the storage part.

Da=(X+a)bDb=XZ=abX\begin{align} D_a &= (X+a)b\\ D_b &= X\\ Z &= ab'X \end{align}

Hence, we can get the circuit.

Example_02 Vending Machine#

Success:

Illustration#

There are two kinds of coins, one is nickel and one is dime, the relationship is 1 dime = 2 nickels.

Now, design a circuit to determine whether to output a merchandise which price is 3 nickels.

Input#

There are three types of input:

  • NN (Nickel) : insert a nickel.
  • DD (Dime) : insert a dime.
  • ResetReset : back to the initial condition.

Output#

There is one output:

  • OpenOpen : 0 is not and 1 is output the merchandise.

First, we can obseve that there are only 5 possible sequence to activate open:

digraph vending{
    rankdir = LR
    node [shape = circle]
    k [shape = point]
    k -> s0 [label = "Reset"];
    s0 -> s1 [label = "N"];
    s0 -> s2 [label = "D"];
    s1 -> s3 [label = "N"];
    s1 -> s4 [label = "D"];
    s3 -> s7 [label = "N"];
    s3 -> s8 [label = "D"];
    s2 -> s5 [label = "N"];
    s2 -> s6 [label = "D"];
    s7, s8, s4, s5, s6 [color = "red"]
}
plaintext

Those states with red color means OpenOpen should output 1, otherwise should output 0.

By State reduction (let every state be the current dollor), we can obtain the state diagram like this:

We can encode as follow and get the state table:

ababNNDDa(t+1)b(t+1)a(t+1)b(t+1)OpenOpenababNNDDa(t+1)b(t+1)a(t+1)b(t+1)OpenOpen
00000001000100
00010101001110
00101001010110
0011xx01011xx0
01000101100001
01011001101001
01101101110001
0111xx01111xx1

Next, obtain the state equations: details:

By K-Map: We can have the SOP form:

a(t+1)=a(t)b(t)+Na(t)+Da(t)b(t)b(t+1)=DNb(t)+Da(t)b(t)+Na(t)b(t)Open=ab\begin{align} a(t+1) &= a(t)b'(t)+Na'(t)+Da'(t)b(t)\\ b(t+1) &= DN'b'(t)+D'a'(t)b(t)+Na(t)b'(t)\\ Open &= ab \end{align}

Using D flip-flop, we can have the characteristic equation $$ \begin{align} D_a &= ab’+Na’+Da’b\ D_b &= DN’b’+D’a’b+Nab’\ Open &= ab \end{align}

Hence, we can get the sequential circuit: ![](../../../../assets/book/logic-design-eecs1010/hnf31qI-4c98031e.png) #### Remark In practice, a vending machine’s coin-receptor is a mechanical device and is very slow compared to an electronic circuit․ Inserting a dime (nickel) would cause signal $sense_D$ ($sense_N$) to be asserted for a large number of clock cycles. And there may be an arbitrarily long time between insertion of two consecutive coins․ So, we need to generate a signal such that $D$ ($N$) that will be asserted for 1 clock cycle after $sense_D$ ($sense_N$) becomes 1. ![](../../../../assets/book/logic-design-eecs1010/BtZAyeM-28d5e3b8.png) ### Example_03 Circuit w/ JKFF Say we want to implement the following cicuit. ![](../../../../assets/book/logic-design-eecs1010/vm8jXrU-deb68d11.png) Then we need to derive the table with JK input value: ![](../../../../assets/book/logic-design-eecs1010/Guu0up2-a22250bf.jpg) Remember that $Q(t+1)=JQ'+K'Q$, then we should be able to get this table. Then by k-map, we get the following equations: **K-map:** ![](../../../../assets/book/logic-design-eecs1010/fKwVgwe-34e09c9f.jpg)

\begin{align} J_A &= BX’\ K_A &= BX \ J_B &= X \ K_B &= (A \oplus X)’ \ \end{align}

Then we can sketch the circuit. ![](../../../../assets/book/logic-design-eecs1010/98udMTw-dc015c39.jpg) ### Example_04 N-bit binary counter w/ TFF **Success:** ### Illustration An n-bit binary counter consists of n FFs that can count in binary from $0$ to $2^n-1$. Implement this counter using **TFF**. Here is the state diagram: ```graphviz digraph sta{ node [shape = circle] layout = neato; 000 -> 001 001 -> 010 010 -> 011 011 -> 100 100 -> 101 101 -> 110 110 -> 111 111 -> 000 } ``` Similarly, we need to derive the state table with FF inputs: ![](../../../../assets/book/logic-design-eecs1010/Yf20siw-fccc10b7.png) Also remember that $Q(t+1)=T\oplus Q$, then the table is quite straight-forward. By k-map: **K-map:** ![](../../../../assets/book/logic-design-eecs1010/9qbEHcL-69dc836f.jpg)

\begin{align} T_{A2} &= A_1A_0 \ T_{A1} &= A_0 \ T_{A0} &= 1 \ \end{align}

Then we can get the circuit: ![](../../../../assets/book/logic-design-eecs1010/gzbX3dU-70b902c1.jpg) ### Example_05 Arbiter **Success:** ### Illustration A device asserts its request signal to request for the resource. When the resource is not used, the arbiter selects the highest priority requesting device and asserts its grant signal. When a device finished using the resource, it deasserts its request signal. Implement an arbiter that is for three devices where the priority from high to low is $1\to2\to3$. ### Input Each device provides one input $R$ ( Request ) to the arbiter. ### Output The arbiter provides one output $G$ ( Grant ) for each device. First, we can draw the status diagram like this: ```graphviz digraph arbiter{ node [shape = circle] g1 [label = "G=100"] g2 [label = "G=010"] g3 [label = "G=001"] Idle -> g1 [label = "1xx"] Idle -> Idle [label = "000"] g1 -> g1 [label = "1xx"] g1 -> Idle [label = "0xx"] Idle -> g2 [label = "x1x"] g2 -> g2 [label = "x1x"] g2 -> Idle [label = "x0x"] Idle -> g3 [label = "xx1"] g3 -> g3 [label = "xx1"] g3 -> Idle [label = "xx0"] } ``` Here, rather than drawing the circuit, we use verilog to describe this module: ```verilog= module arbiter (r, Reset, Clock, g); input [1:3] r; // request signals input Reset, Clock; output wire [1:3] g; // grant signals reg [2:1] state, next; parameter Idle = 2'b00, gnt1 = 2'b01, gnt2 = 2'b10, gnt3 = 2'b11; // Sequential block always @(posedge Clock) if (Reset == 1) state <= Idle; else state <= next; // Define output (Decoder) assign g[1] = (state == gnt1); assign g[2] = (state == gnt2); assign g[3] = (state == gnt3); // Next state combinational circuit always @(r, state) case (state) Idle: casex (r) 3'b000: next = Idle; 3'b1xx: next = gnt1; 3'b01x: next = gnt2; 3'b001: next = gnt3; default: next = Idle; endcase gnt1: if (r[1]) next = gnt1; else next = Idle; gnt2: if (r[2]) next = gnt2; else next = Idle; gnt3: if (r[3]) next = gnt3; else next = Idle; default: next = Idle; endcase endmodule ``` ### Verilog code for FSM > There are more than one way to describe a FSM. In the sample code above (Example_05) - 1st always block introduces flip-flops into the circuit - 2nd always block describes the combinational circuit for computing the next state - The outputs are defined with conditional assignment statements - State transition should use non-blocking assignment (`&lt;=`)as FFs of synchronous sequential circuit are updated concurrently by a common clock ### Remark 1. **Heuristic State Assignment Guidelines** - States having the same next state for a given input should be given adjacent assignments. - States that are next states of a single state should be given adjacent assignments. - States having the same output for a given input should be given adjacent assignments. (2 states are adjacent if they differ in one variable) 2. **Unused States** - Unused states can be treated as don’t care conditions to simplify the circuit. - But, for more robust design it may be desirable to specify the next states and/or output values for the unused states upon a malfunction. 3. **Start State/Reset State** - A master reset signal is usually provided for initializing the flip-flop states. 4. **Timing Issues** - External input changes must be properly timed with respect to active edge to ensure correct operation. - Must give enough time for signals to be transmitted to flip-flop inputs before we sample the flip-flop inputs. ![](../../../../assets/book/logic-design-eecs1010/8Halkyc-570aabaa.png) ## Optimization ### State Reduction The main idea is to merge the equivalent state. **Info:** Define:

Two states of a FSM are equivalent if \the outputs produced for each possible input value are identical\and the next states for each possible input value are the same or equivalent

- Merits of state reduction : Can reduce number of flip-flops used. We use the following example to demonstrate state reduction. ![](../../../../assets/book/logic-design-eecs1010/GsSsO91-66e55ff0.png) We can see that $g$ and $e$ has the same output and also the same Next state, so we can merge those two status. Then we get: ![](../../../../assets/book/logic-design-eecs1010/dsaDDLx-85736faf.png) Here, we obtain new equivalent states $d = f$, so one can do merge again: ![](../../../../assets/book/logic-design-eecs1010/TgERlGb-a3726cf4.png) ### State Assignment Cost of final circuit depends on the state assignment. There are many possible binary state assignment(encode), for example: ![](../../../../assets/book/logic-design-eecs1010/buciBUc-1c9c48dd.jpg) We can see that One-hot encoding uses more FFs (Flip-Flop) but may lead to simpler decoding logic for next state and output. ###### tags: `Logic Design EECS1010`