ENGG 23 Tutorial Simplification using K-map Combinational Logic (II) and Sequential Logic (I) 8 Feb Learning Objectives Apply Karnaugh map for logic simplification Design a finite state machine News HW (Feb 22, 23, :55pm) Ack.: HKU ELEC8, ISU CprE 28x, PSU CMPEN27, Wikipedia Simplify the Boolean expression of the circuit Change each NAND gate in the circuit to a NOR gate, and simplify the Boolean expression of the circuit M N Q x 2 (a) (b) M N Q x NQ M M N Q x NQ M From truth table to K-map x = MQ + NQ x = MN + Q 3 4
Finite State Machine (FSM) A simple Finite State Machine (FSM) State transition diagram Truth table K-Map Circuit State Present state: before the register Next state: after the register State transition: during clock 2 n states: n FFs Turnstile Control access Depositing a token in a slot on the turnstile unlocks the arms, allowing a single customer to push through. After the customer passes through, the arms are locked again until another coin is inserted. Current State Input Next State Output Locked Unlocked coin Unlocked Release turnstile so customer can push through push Locked None coin Unlocked None push Locked When customer has pushed through, lock turnstile 5 6 A simple FSM Steps in designing a state machine Current State Input Next State Output Locked Unlocked Specification FSM coin Unlocked Release turnstile so customer can push through push Locked None coin Unlocked None push Locked When customer has pushed through, lock turnstile State Arm: Arm: Transition Transition condition Draw a state transition diagram An initial state Other states to keep track of various activities Transitions Generate a state transition table and a output table Write state transition table and output table in binary State assignment, i.e., the code used for each state Derive canonical sum-of-product expressions Draw the circuit 7 8
From state transition diagram to truth table Four states Two-bit state q: Present state q*: Next state z: Output From truth table to K-map A B D A D B D A D B Condition/Output 9 From K-map to circuit A simple FSM design State register Logic for state transition Logic for output Design a state machine that will repeatedly display in binary values (), 3 (), 5 (), and 7 () How many states we need? S, S, S2, S3 Simplified state transition diagram? 2
Output table L2 = XY'+XY = X L = X'Y+XY = Y L = X'Y'+X'Y+XY'+XY = State transition table X = X'Y+XY' Y = X'Y+XY' = Y' Current state Output S () () S () 3 () S2 () 5 () S3 () 7 () Current state Next state S () S () S () S2 () S2 () S3 () S3 () S () Current Output X Y L2 L L Current Next X Y X Y A complicated FSM design Vending Machine Collect money, deliver product and change Vending machine may get three inputs Inputs are nickel (5c), dime (c), and quarter (25c) Only one coin input at a time Product cost is 4c Does not accept more than 5c Returns 5c or c back Exact change appreciated 3 4 We are designing a Mealy state machine (i.e., output depends on both current state and inputs). Suppose we ask the machine to directly return the coin if it cannot accept an input coin. Input specification: I I 2 Represent the coin inserted - no coin ( cent), nickel (5 cents), dime ( cents), quarter (25 cents) Output specification: C C 2 P C C 2 represent the coin returned,,, P indicates whether to deliver product, States: S S 2 S 3 Represent the money inside the machine now 3 bits are enough to encode the states S ( cents) S5 (5 cents) S S5 S2 S25 S3 S35 5 6
Input Next state Output / / / / S35 / S35 / S / S / S35 S35: Currently the machine has 35 cents e.g. / : If we insert a quarter (), then the machine should return one quarter and zero product () 35c (35 cents inside the machine now) + 25c (insert 25 cents) = 35c (35 cents inside the machine in the next state) + 25c (return 25 cents) + c (return no product) 7 8 / / / / S35 / S35 / S / S / S35 e.g. /: If we insert a dime (), then the machine should return one nickel and one product () 35c (35 cents inside the machine now) + c (insert cents) = c (zero cent inside the machine in the next state) + 5c (return 5 cents) + 4c (return one product) e.g. /: If we insert a nickel (), then the machine should return zero coin and one product () 35c (35 cents inside the machine now) + 5c (insert 5 cents) = c (zero cent inside the machine in the next state) + c (return zero cent) + 4c (return one product) (Appendix) Simplification using K-map Simplify the following Boolean expressions using Karnaugh map. i) ( A + B)( A + B) ii) B + BC + ABC + AB 9 2
(Appendix) Counter i) ii) A/B A/BC ( A + B)( A + B) = A B + BC + ABC + AB = B + A Figure a) shows a complete four-bit parallel adder with registers and b) shows the signals used to add binary numbers from memory and store their sum in the accumulator. Suppose the numbers being added are and. Also assume that C o =. Describe what happen at t, t 2, t 3, t 4 and t 5. 2 22 At time t, is active low FF at the bottom will be cleared 23 24
At time t 2, load is active high Set A numbers will be loaded into the upper register At time t 3, transfer is active high Adder process between A 3 A 2 A A = and B 3 B 2 B B = At time t 4, the load is active high, the set B numbers will be loaded into register B on PGT of LOAD pulse B 3 B 2 B B = At time t 5, A 3 A 2 A A = and B 3 B 2 B B =, the adder produces S 3 S 2 S S =. This sum is transferred into register A when TRANSFER pulse occur at t 5. The sum S 3 S 2 S S = are transferred to register A on PGT due to this transfer pulse at t 3 25 26 (Appendix) State changing in FSM Design a 2-bit counter with input x that can be A down counter when x = ( ) A Johnson counter when x = ( ) 27 28
(Appendix) A typical FSM FSM Truth table Circuit State register Logic for state transition Logic for 29 output