Combinational and Sequential Circuits Design
Combinational and Sequential Circuits Design
Combinational and Sequential Circuits Design
Example Informal specification: A radix-4 digit comparator module compares two radix-4 digits and produces one output with values G (grater), E(equal), and S(smaller). The high-level specification is: Inputs: x, y {0, 1, 2, 3} Outputs: z {G, E, S} Function (a conditional expression): G if x > y z = E if x = y S if x < y
G if x > y z = E if x = y S if x < y
To obtain a binary description we have to code the input and output values on bit vectors.
High-level specification
x
Coding
Binary specification
z
Decoding
The three-values output requires at least two binary variables. We use three binary variables. In this case, there are possible 8*7*6=336 code systems. We choose one of them At the logic level we must work with both logic expression and gate networks to find the best implementation of a function, keeping in mind the relationships: combinational logic expressions are the specification; logic gate networks are the implementation; area (number of gates), delay, and power are the cost (restrictions).
z z2 G 1 E 0 S 0
z1 z0 0 0 1 0 0 1
For input, we take the most used binary code in which the radix4 digit is represented by the correspondingradix-2 bit-vector ( x = 2*x1+x0; y =2 *y1+y0 )
x x1 ( y ) ( y1 ) 0 1 0 2 1 3 1 4
x2 ( y2 ) 0 1 0 1
Now, we can obtain the switching functions described by the following table (binary specification of combinational system): y1 y0 01 10 001 001 010 001 100 010 100 100 z2 z1 z0
x1 x0 00 01 10 11
C1
A1 A0 entity ONES_CNT is port (A: in BIT_VECTOR(2 downto 0); C: out BIT_VECTOR(1 downto 0)); end ONES_CNT; --Truth table:
------------------------------------- A2 A1 A0 C1 C0 ------------------------------------- 0 0 0 0 0 -- 0 0 1 0 1 -- 0 1 0 0 1 -- 0 1 1 1 0 -- 1 0 0 0 1 -- 1 0 1 1 0 -- 1 1 0 1 0 -- 1 1 1 1 1 -------------------------------------
C0
end ONES_CNT; architecture PURE_BEHAVIOR of ONES_CNT is begin process(A) variable NUM: INTEGER range 0 to 3; begin NUM := 0; for I in 0 to 2 loop if A(I) = '1' then NUM := NUM + 1; end if; end loop; case NUM is when 0 => C <= '00'; when 1 => C <= '01'; when 2 => C <= '10'; when 3 => C <= '11'; end case; end process; end PURE_BEHAVIOR;
5
A2
A1 A0 00 0 0 1 0
01 0 1
11 1 1
10 0 1
C1 = A1 A0 A2 A0 A2A1
A1 A0 00 0 0 1 1 01 1 0 11 0 1 10 1 0
A2
C0 is ODD-PARITY FUNCTION
--Macro-based architectural body: architecture MACRO of ONES_CNT is begin C(1) <= MAJ3(A); C(0) <= OPAR3(A); end MACRO; This architectural body implies the existence of MAJ and OPAR gates at the hardware level. In terms of a VHDL description, it requires that the functions MAJ3 and OPAR3 must have been declared and defined previously. architecture DATA_FLOW of ONES_CNT is begin C(1) <= (A(1) and A(0)) or (A(2) and A(0)) or (A(2) and A(1)); C(0) <= (A(2) and not A(1) and not A(0)) or (not A(2) and not A(1) and A(0)) or (A(2) and A(1) and A(0)) or (not A(2) and A(1) and not A(0)) end DATA_FLOW; Structural Design Hierarchy for the Ones Counter (ONES_CNT)
ONES_CNT
Structural Decomposition
MAJ3
OPAR3
AND2
OR3
AND3
OR4
Behavioral Modeling
7
AND2
X(0) X(2)
A2
AND2
OR3
X(1)
A3
AND2
X(2)
entity AND2 is port (I1, I2:in BIT; O out BIT); end AND2 architecture BEHAVIOR of AND2 is begin O <= I1 and I2; end BEHAVIOR;
entity OR3 is port(I1, I2, I3: BIT; O: out BIT); end OR3; architecture BEHAVIOR of OR3 is begin O <= I1 or I2 or I3;
end BEHAVIOR;
use work.all; entity MAJ3 is port(X: in BIT_VECTOR(2 downto 0); Z: out BIT); end MAJ3; architecture AND_OR of MAJ3 is component AND2C port (I1, I2: in BIT; O: out BIT); end component; component OR3C port (I1, I2, I3: in BIT; O: out BIT); end component for all: AND2C use entity AND2(BEHAVIOR); for all: OR3C use entity OR3(BEHAVIOR); signal A1, A2, A3: BIT; begin G1: AND2C port map (X(0), X(1), A1); G2: AND2C port map (X(0), X(2), A2); G3: AND2C port map (X(1), X(2), A3; G4: OR3C port map (A1, A2, A3, Z); end AND_OR;
use work.all; architecture STRUCTURAL of ONES_CNT is component MAJ3C port (X: in BIT_VECTOR(2 downto 0); Z: out BIT); end component; component OPAR3C port (X: in BIT_VECTOR(2 downto 0); Z: out BIT); end component; for all: MAJ3C use entity MAJ3 (AND_OR); for all: OPAR3C use entity OPAR3C (AND_OR); begin COMP1: MAJ3C port map (A, C(1)); COMP2: OPAR3C port map (A, C(0)); end STRUCTURAL;
Behavioral
Structural
Algorithmic
Data Flow
10
2.2. Sequential Logic A sequential circuit is a circuit with memory. A Finite State Machine (FSM) is a mathematical model of a system with discrete inputs, discrete outputs and a finite number of internal configurations or states. The state of a system completely summarizes the information concerning the past inputs to the system that is needed to determine its behavior on subsequent inputs. This high-level FSM model has only one input channel and only one output channel. Variables in the specification of a design are multiple-valued or symbolic. The symbolic variable takes on symbolic values.
Clk A sequential circuit is said to be synchronous if the internal state of the machine changes at specific instants of of time as governed by a clock. Circuits with an acyclic underlying topology are combinational. Feedback (cyclic) is a necessary condition for a circuit to be sequential.
11
FSM as algebraic system is a quintuple A = S, I, O, , , where S is a finite non-empty set of states, I is a finite non-empty set of inputs and O is a finite set of outputs. : I S S is called transition (or next state function) and is called the output function of A : I S O for Mealy type FSM, : S O for a Moore machine,. Note that any Moore machine can be converted into a Mealy machine with the same number of states and state transitions. A general logic-level synchronous sequential circuit
Primary Outputs
Present States
Latches (Flip-flops)
Next States
Logic-level description consists of a combinational logic block and state registers (latches or flip-flops) that hold the state information. The combinational block is an interconnection of gates that implements the mapping between the primary input (PI) and present-state (PS), and primary output (PO) and next-state (NS). A state is a bit vector of length equal to the number of memory elements (latches or flip-flops) in the sequential circuit. Each state has a unique bit vector representing that state, and this bit vector is known as the state code. The process of assigning a code to each state is known as state assignment or state encoding.
12
Example represetatations of the device which ditects two or more consecutive 1's or two consecutive 0' on its input X. X R CLK Block Diagram TWO_CON Z
CLK
Z Timing Diaram
13
X 1 S2 / 0 S2 / 0 S2 / 0 State Table
State Assignment X 0 0 0 0 1 1 1 1 Truth Table (K-map) X 0 1 1 1 1 1 1 1 Truth Table (K-map) X 0 0 1 0 1 0 0 1 Truth Table (K-map) Z
14
STOP
D CLK DONE
CLK
R A D DONE Z [4]
15
A Moore machine may require more states than the corresponding Mealy machine. Moore device isolates the outputs from the inputs Mealy machine can respond one clock period one clock period earlier than the Moore machine to input changes, but noise on the input lines may be transferred to the outputs. For the several to parallel converter (STOP), the output must be present during the clock period following the last input. Since the last input is no longer available, the outputs cannot depend on the inputs. Also, since the outputs are specified to be constant during the entire clock period, a Mealy machine cannot be used. Therefore we must design a Moore machine.
16
State S0: The Reset State. The device enters this state at the end of any clock period in which input R=1 regardless of the values of any input. The device will stay in this state until there is a logic 1 on line A. When in state S0, DONE = 0which means that the data on line Z will be ignored by the destination. This means that we are free to place anything at all on output Z. The next step is to decide what to do when device is in state S0 for various conditions that may exist on the device inputs. If the device is in state S0, it will stay in S0 if R=1 regardless of the values of any other input. When R=0, the device also will stay in state S0 when A=0. The complete condition for the device to state in state S0 is
R (R&A) = R A
If R = 0 and A = 1 during some clock period, then the device must get ready to receive data on line D during the next 4 clock periods. This means that it must enter a new state at the end of clock period.
State S1.
The device enters this state from state S0 when R = 0 and A = 1. When the device is in state S1 the first data value will be present on line D and must be saved at the end of clock period for later output. When in state S1, output DONE = 0 and Z is unspecified.
R & A S1 0S0 0R A
17
State S2.
State S1 transitions to state S2 when R = 0. When in state S2, the second data value will be present on line D and must be saved at the end of clock period. In state S2, the output DONE = 0 and Z is unspecified. Therefore, a new node is added to the state diagram under construction for state S2. An arc from S1 to S2 with label R indicates the desired state transition.
S2 0-
R R S1 0R & A R A S0 0-
18
This figure shows the final state diagram (STG) for device STOP. R
S2 S3
00R R R R
R
S4
0R
S1
R
S0
00R&A R A
R A
S5
1Z
R&A
19
3.2. Transition List Approach Present state S0 S0 S1 S1 S2 S2 S3 S3 S4 S4 S5 S5 Transition Expression R A R & A R R R R R R R R R & A R A Next State S0 S1 S2 S0 S3 S0 S4 S0 S5 S0 S1 S0 Data Transfers None Output
DONE =0 Z unspec. DONE = 0 Z unspec. DONE = 0, Z unspec. DONE = 0, Z unspec. DONE = 0 Z unspec.
Store bit 1
Store bit 2
Store bit 3
Store bit 4
None
Principle of Mutual Exclusion. No two expressions on different arcs can be true simultaneously. For example for node S0, (R & A)&( R A) = RAR RAA = 0
20
entity STOP is port (R, A, D, CLK: in BIT; Z: out BIT_VECTOR (3 downto 0); DONE: out BIT); end STOP; architecture FSM_RTL of STOP is type STATE_TYPE is (S0, S1, S2, S3, S4, S5); signal STATE: STATE_TYPE; signal SHIFT_REG: BIT_VECTOR (3 downto 0); begin STATE: process (CLK) begin if CLK = 1 then case STATE is when S0 => if R = 1 or A = 0 then STATE <= S0; elsif R = 0 and A = 1 then STATE <= S1; end if; when S1 => SHIFT_REG <= D & SHIFT_REG(3 downto 1); if R = 0 then STATE <= S2; elsif R = 1 then STATE <= S0; end if; when S2 => SHIFT_REG <= D & SHIFT_REG (3 downto 1); if R = 0 then STATE <= S3; elsif R = 1 then STATE <= S0; end if;
21
when S3 => SHIFT_REG <= D & SHIFT_REG (3 downto1); if R = 0 then STATE <= S4; elsif R = 1 then STATE <=S0; end if; when S4 => SHIFT_REG <= D & SHIFT_REG (3 downto1); if R = 0 then STATE <= S5; elsif R = 1 then STATE <=S0; end if; when S5 => if R = 0 and A =1 then STATE <= S1; elsif R = 1 or A = 0 then STATE <= S0; end if; end case; end if; end process STATE; OUTPUT: process (STATE) begin case STATE is when S0 to S4 => DONE <= 0; when S5 => DONE <= 1; Z <= SHIFT_REG; end case; end process OUTPUT; end FSM_RTL;
22
Control Unit
Block diagram for model of a state machine.
TO STATE S0 S0 S0 S0 S0 S0 S1 S1 S2 S3 S4 S5
FROM STATE S0 S1 S2 S3 S4 S5 S0 S5 S1 S2 S3 S4
CONDITION
R + A R R R R R + A R A R A R R R R
23
1
S5 R A S1 S2 S3 S4
& 1
R &
1
R A & S5
Q Q
S2 S1
S3
S4
S5
&
R
Q Q
&
Q Q
&
Q Q
&
Q Q
24
Data Transfer
SHIFT_REG <= D & SHIFT_REG (3 downto 1) SHIFT_REG <= D & SHIFT_REG (3 downto 1) SHIFT_REG <= D & SHIFT_REG (3 downto 1) SHIFT_REG <= D & SHIFT_REG (3 downto 1)
State
S1 S2 S3 S4
Condition
1 1 1 1
D S1 SH S1 S2 S3 S4 SHIFT = S1+S2+S3+S4
D3 D2 D1 D0
SHIFT REGISTER
25