850 likes | 977 Views
ENG241 Digital Design. Week #10 Sequencing and Control. Week #10 Topics. The Control Unit Algorithmic State Machines ASM Elements Hardwired Control One Flip-Flop Per State Sequence Register and Decoder VHDL Representation. Resources. Chapter #8, Mano Sections
E N D
ENG241 Digital Design Week #10 Sequencing and Control
Week #10 Topics • The Control Unit • Algorithmic State Machines • ASM Elements • Hardwired Control • One Flip-Flop Per State • Sequence Register and Decoder • VHDL Representation ENG241/Digital Design
Resources • Chapter #8, Mano Sections • 8.1 The Control Unit • 8.2 Algorithmic State Machines • 8.3 ASM Examples • 8.4 Hardwired Control ENG241/Digital Design
The Control Unit • The binary information stored in a digital computer can be classified as either data or control information. • Data is manipulated in a data-path • To perform arithmetic, logic, shifting, and other data-processing tasks. • These operations are implemented with ALUs, registers, multiplexers, and busses. • The control unit • Provides signals that activate the various micro-operations in the data-path to perform the specified data processing tasks. • The control unit also determines the sequence in which the various actions are performed (i.e. when they are to be performed) ENG241/Digital Design
Parts of CPUs • Datapath • The registers and logic to perform operations on them • Control unit • Generates signals to control datapath Control Data Path ENG241/Digital Design
Memory and I/O • Are connected to the data/control in and out lines • Example: register to memory ops ENG241/Digital Design
Control Unit Types • Two distinct classes: • Programmable • Non-programmable. • A programmable control unit has: • An external ROM or RAM array for storing instructions and control information • A program counter (PC) or other sequencing register with contents that points to the next instruction to be executed • Decision logic for determining thesequence of operations and logic to interpret the instructions • A non-programmable control unit (hardwired Control) does not fetch instructions from a memory but just determines the operations to be performed and the sequence of those operations based only on inputs and status bits. • In ENGG2410 we are mainly concerned with the design of a non-programmable control unit. ENG241/Digital Design
Algorithmic State Machines • The function of a state machine (or sequential circuit) can be represented by a state table or a state diagram. • A flowchart is a way of showing actions and control flow in an algorithm. • An Algorithmic State Machine (ASM) is simply a flowchart-like way to specify state diagrams for sequential logic and, optionally, actions performed in a datapath. • While flowcharts typically do not specify “time”, an ASM explicitly specifies a sequence of actions and their timing relationships. ENG241/Digital Design
State Box (a rectangle) Scalar Decision Box (a diamond) Vector Decision Box (a hexagon) Conditional Output Box (oval). The State Box is a rectangle, marked with the symbolic state name, containing register transfers and output signals activated when the control unit is in the state. The Scalar Decision Box is a diamond that describes the effects of a specific input condition on the control. It has one input path and two exit paths, one for TRUE (1) and one for FALSE (0). The Vector Decision Box is a hexagon that describes the effects of a specific n-bit (n > 2) vector of input conditions on the control. It has one input path and up to 2n exit paths, each corresponding to a binary vector value. The Conditional Output Box is an oval with entry from a decision block and outputs activated for the decision conditions being satisfied. ASM Primitives ENG241/Digital Design
State Box • A rectangle with: • The symbolic name for the state marked outside the upper left top • Containing register transfer operations and outputs activated within or while leaving the state • An optional state code, if assigned, outside the upper right top (Optional state code) (Symbolic Name) IDLE 0000 (Register transfers or outputs) R ← 0 RUN ENG241/Digital Design
Scalar Decision Box • A diamond with: • One input path (entry point). • One input condition, placed in the center of the box, that is tested. • A TRUE exit path taken if the condition is true (logic 1). • A FALSE exit path taken if the condition is false (logic 0). (True Condition) (False Condition) (Input) 0 1 START ENG241/Digital Design
Vector Decision Box • A hexagon with: • One Input Path (entry point). • A vector of inputconditions, placed in thecenter of the box, that istested. • Up to 2n output paths. The path taken has a binary vector value that matches the vector input condition (Binary Vector Values) (Binary Vector Values) (Vector of InputConditions) 00 10 01 Z, Q0 ENG241/Digital Design
Conditional Output Box From Decision Box(es) • An oval with: • One input path from a decision box or decision boxes. • One output path • Register transfers or outputs that occur only if the conditional path to the box is taken. • Transfers and outputs in a state box are Moore type - dependent only on state • Transfers and outputs in a conditional output box are Mealy type - dependent on both state and inputs (Register transfers or outputs) R← 0 RUN ENG241/Digital Design
IDLE R← 0 AVAIL 0 1 START PC ← 0 INIT Connecting Boxes Together • By connecting boxes together, we begin to see the power of expression. • What are the: • States? • Inputs? • Outputs? • Conditional Outputs? • Transfers? • Conditional Transfers? ENG241/Digital Design
Entry IDLE ASM BLOCK AVAIL START R← R + 1 R ← 0 Exit 0 1 Q0 Exit Exit MUL1 MUL0 ASM Blocks • One state box alongwith all decision andconditional outputboxes connectedto it is called an ASMBlock. • The ASM Blockincludes all items on thepath from the currentstate to the same or otherstates. ENG241/Digital Design
From State Diagram to ASM S = 0 Z = 1 A B C S = 1 Z = 0 ENG241/Digital Design
From State Diagram to ASM A 00 S = 0 Z = 1 0 1 S A B C B 01 S = 1 10 C Z = 0 0 1 Z ENG241/Digital Design
Example (1) • Find the ASM chart corresponding to the following description • There are two states A, B • If in state A and input X is `0’ then the next state is A • If in state A and input X is `1’ then the next state is B • If in state B and input Y is `1’ then the next state is B • If in state B and input Y is `0’ then the next state is A • Output Z is equal to `1’ while the circuit is in state B • Solution: • Total States 2 • Two Inputs X, Y • One Output Z ENG241/Digital Design
ASM for Example (1) A 0 1 X B Z = 1 1 0 Y ENG241/Digital Design
Hardwired Control • Designing the Control Unit: • One Flip-flop per StateA flip-flop is assigned to each of the states and at any time, only one of the flip flops contains a 1, with all the rest containing 0. • Sequence Register and DecoderUses a sequence register for the control states and a decoder to provide an output signal corresponding to each of the states. ENG241/Digital Design
I. One Flip-Flop per State • As the name implies the method uses one flip-flop per state and a simple set of transformation rules to implement the circuit. • The design starts with the ASM chart, • Then all you do is replace: • A State Box with a D flip-flop, • A Scalar Decision Box with a demultiplexer with 2 outputs, • A Vector Decision Box with a (partial) demultiplexer • Any Junction with an OR gate, and • Any Conditional Output with an AND gate (for a Mealy Machine!!) ENG241/Digital Design
State Box Transformation Rules • Each state box transforms to a D Flip-Flop • Entry point is connected to D FF input. • Exit point is connected to the D FF `Q’ output. ENG241/Digital Design
Scalar Decision Box Transformation Rules • Each Decision box transforms to a Demultiplexer • Entry points are "Enable" inputs. • The Condition is the "Select" input. • Decoded Outputs are the Exit points. ENG241/Digital Design
(Binary Vector Values) (Binary Vector Values) (Vector of InputConditions) 00 10 01 X1, X0 Entry DEMUX Exit 0 D0 EN Exit 1 X1 D1 A1 Exit2 X0 A0 D2 Exit 3 D3 Vector Decision Box Transformation Rules • Each vector decision box transforms to a Demultiplexer • Entry point is Enable inputs. • The Conditions are the Select inputs. • Demultiplexer Outputs are the Exit points. ENG241/Digital Design
Junction Transformation Rules • Where two or more entry points join, connect the entry variables to an OR gate • The Exit is the output of the OR gate ENG241/Digital Design
Conditional Output Box Rules • Entry point is Enable input. • The Condition is the "Select" input. • Demultiplexer Outputs are the Exit points. • The Control OUTPUT is the same signal as the exit value. ENG241/Digital Design
Implement using 1 Flip Flop Per State • Note: One FF is assigned to each of the states, and at any time, only one of the FFs contains a 1, with all the rest containing 0. • When a 1 is in the FF assigned to a particular state, the sequential circuit is in that same state. • The single 1 propagates from one FF to another under the control of decision logic A 00 0 1 S B 01 10 C 0 1 Z ENG241/Digital Design
One Flip Flop Per State 00 OR OR A 0 1 D S D 01 C C B 10 Z S DeMux DeMux C D 0 1 Z C ENG241/Digital Design
Sequence Register and Decoder • This method uses a decoder and a set of flip flops (or a register) to implement the circuit. • The design starts with the ASM chart, • According to the number of states 2n, we will use n flip flops (log2 # state) • Construct State Table (directly from ASM) • Use an n-to-2n decoder has 2n outputs ENG241/Digital Design
Implement Sequence Register/Decoder A 00 0 1 S B 01 How many Flip Flops? 10 C Decoder Size? 0 1 Z ENG241/Digital Design
Implement Sequence Register/Decoder Decoder D A 0 A0 C B 1 C A1 2 X D 3 C ENG241/Digital Design
State Table: Construction ENG241/Digital Design
Sequence Register and Decoder ENG241/Digital Design
Implement Sequence Register/Decoder DM0 = A.S DM1 = B + C.Z’ ENG241/Digital Design
Implement Sequence Register/Decoder Decoder A D 0 B S A0 C 1 DM0 = A.S DM1 = B + C.Z’ C A1 2 D 3 C Z’ ENG241/Digital Design
One FF per State vs. Sequence Register and Decoder • At first glance, it may seem that the one FF per state method would increase the cost of the system, since more flip-flops are used. • But the method offers some cost advantages that may not be apparent: • One advantage is the simplicity with which the logic can be designed – merely by inspection of the ASM chart or state diagram. • No state or excitation tables are needed if D flip-flops are employed. • This offers a savings in design effort, an increase in logic simplicity. ENG241/Digital Design
VHDL Code P2 P1 Process that will depend on clock event to reset system to Idle State and implement state_register based on CLK Process that will act as a sequencer that will dictate the state you are in given the input Process that will control your data path (If you have a data path!) P3 Similar to Sequencer ENG241/Digital Design
Implement Using VHDL X IDLE 00 0 1 G What are the Inputs? Remember that this is a state machine and we have to start somewhere at power up! Y 01 LOAD 10 ADD Z 0 1 S ENG241/Digital Design
VHDL Code -- VHDL Code entity declaration library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity sequential_machine is port (CLK, RESET, G, S : in std_logic; X,Y, Z : out std_logic); end sequential_machine; ENG241/Digital Design
VHDL Code: Architecture -- VHDL Code Architecture architecture behavior of sequential_machine is type state_type is (IDLE, LOAD, ADD); signal state, next_state : state_type; begin State_register: process (CLK) ..... Next_state_func: process (G,S,state) ...... Datapath_func: process (CLK) ...... endbehavior; ENG241/Digital Design
VHDL Code: State-Register Process -- VHDL Code State Register Process State_Register: process (CLK, RESET) begin if (RESET = ‘1’) then state <= IDLE; elseif(CLK'event and (CLK = '1'))then state <= next_state; end if; end process; ENG241/Digital Design
VHDL Code: Next-State Process -- VHDL Code for next_state_func next_state_func: process (G,S,state) begin case state is when IDLE => if G = ‘1’ then next_state <= LOAD; else next_state <= IDLE; end if; when LOAD => next_state <= ADD; when ADD => if S = ‘1’ then next_state <= IDLE; else next_state <= ADD; end if; end case end process; ENG241/Digital Design
VHDL Code: datapath Process -- VHDL Code for datapath_func Output_func: process (state) begin case state is when IDLE => X <= 1; when LOAD => Y <= 1; when ADD => Z < =1 end case end process; ENG241/Digital Design
Multiplier Example: ASM Chart IDLE MUL0 0 1 G 0 1 Q 0 C ← 0, A ← 0 P ← n – 1 A ← A + B, C ← C out MUL1 C ← 0, C || A || Q ← sr C || A || Q, 1 P ← P – 0 1 Z
Multiplier Example: Control Unit • In implementing a complex control unit, designers usually have to deal with (separate) two distinct aspects • The generation of the control signals • Sequencing of the operations (what will happen next) • We can separate the two aspects by dividing the original ASM specification into two parts: • A table that defines the control signals in terms of states and inputs • A simplified ASM chart that represents only transitions from state to state ENG241/Digital Design
Multiplier Example: ASM Chart IDLE MUL0 0 1 G 0 1 Q 0 C ← 0, A ← 0 P ← n – 1 A ← A + B, C ← C out MUL1 C ← 0, C || A || Q ← sr C || A || Q, 1 P ← P – 0 1 Z
Example - Sequencing Part of ASM IDLE 00 1 0 G MUL0 01 MUL1 10 0 1 Z
2 DEMUX D EN 0 D A 1 0 Multiplier Example: Flip-flop per State Design Logic Diagram 4 5 START Initialize IDLE 1 D 4 5 C Clear _C 2 MUL0 Q 1 0 DEMUX Load D D EN 0 G A D C 0 1 MUL1 1 5 D Shift_dec Clock C Z
Sequencer and Decoder Design START Initialize G M 0 D Clear_C Z C DECODER IDLE A0 0 MUL0 1 MUL1 Shift_dec 2 A1 3 M 1 D C Load Q 0 ENG241/Digital Design
Summary m Microoperations from T a Binary C o o • Control units are an essential part of any CPU. • Control units can either be programmable or non-programmable. • Non-programmable CU: • One FF per state • Sequence Register and Decoder. • Obtaining the ASM is the key to designing any control unit. • Use the process statement to implement any sequential circuit, state diagrams and algorithmic state machines. ENG241/Digital Design