Upcoming SlideShare
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Standard text messaging rates apply

# Designing State Machine

1,443

Published on

Lec8

Lec8

Published in: Education
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total Views
1,443
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
27
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. Designing State Machines Using State Diagrams&#x2022; Design a state machine to control the tail lights of a 1965 Ford Thunderbird. The tail lights are composed of three light on each side which operate for the turns in the manner shown in the picture next.
• 2. Designing State Machines Using State Diagrams&#x2022; The state machine has: &#x2013; Three inputs: left, and right turns, and hazard. &#x2013; Six outputs: LA, LB, LC, RA, RB, and RC. &#x2013; Free running clock with frequency equal to the flashing rate.
• 3. Designing State Machines Using State Diagrams&#x2022; State name represents &#x2022; LA = L1+L2+L3+LR3 a logic expression that &#x2022; is 1 only in that state LB = L2+L3+LR3&#x2022; The output equations &#x2022; LC = L3+LR3 may be written &#x2022; RA = R1+R2+R3+LR3 without assigning &#x2022; RB = R2+R3+LR3 coded states &#x2022; RC = R3+LR3
• 4. For the state diagram to be unambiguous: The transition expressions on the arcs leaving each state have to be mutually exclusive and all inclusive. That is, for each state, no two expressions are 1 for the same input combination, and some expression is 1 for every input combination. This can be confirmed algebraically by performing two steps Mutual exclusion: For each state, show that the logical product of each pair of transition expression on arcs leaving that state is zero. If there are n arcs, then there are n(n-1)/2 logical products to evaluate. All inclusion: For each state show that the logical sum of the transition expressions on all arcs leaving the state is 1.
• 5. The state diagram in not mutually exclusive because for some input combinations more than one transition expressions are 1. State IDLE I/p Transition Expressions combinations Le Ri Ha L R H L+R+H 0 0 0 0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 0 1 0 1 1 0 1 0 1 1 0 1 1 0 0 1 1 1 1 1 1 0
• 6. &#x2022; Some of the logical products for each pair of transition expression on arcs leaving IDLE state is not zero. For the state IDLE Arcs leaving the state: 4 L, R, H, L + R + H Logical products to evaluate:4*3/2 = 6 L&#xB7;R &#x2260; 0, L&#xB7;H &#x2260; 0, R&#xB7;H &#x2260; 0 L&#xB7; =0 L+R+H R&#xB7; =0 L+R+H H&#xB7; =0 L+R+H&#x2022; All inclusion: For each state the logical sum of the transition expressions on all arcs leaving the state is one. L+R+H+ L + R + H =1
• 7. Problem- The state diagram doesn&#x2019;t handle multiple inputs asserted simultaneously. That is, what happens in the IDLE state if both LEFT and HAZ are asserted? According to the state diagram the machine goes into two states L1 and LR3 which is impossible. The problem is avoided by giving HAZ input a priority. Also we treat both LEFT and RIGHT asserted simultaneously as a Hazard request, since the driver is completely confused and requires help.
• 8. The state diagram in now mutually exclusive State IDLE I/p comb- Transition Expressions inations L&#x22C5;R + H R&#x22C5;H &#x22C5;L Le Ri Ha L&#x22C5;H &#x22C5;R L+R+H 0 0 0 0 0 0 1 0 0 1 0 1 0 0 0 1 0 0 0 1 0 0 1 1 0 1 0 0 1 0 0 1 0 0 0 1 0 1 0 1 0 0 1 1 0 0 1 0 0 1 1 1 0 1 0 0
• 9. &#x2022; The logical products for each pair of transition expression on arcs leaving IDLE state is zero. For the state IDLE Arcs leaving the state: 4 L &#x22C5; H &#x22C5; R , L &#x22C5; R + H , R &#x22C5; H &#x22C5; L, L + R + H Logical products to evaluate:4*3/2 = 6 All 6 products are zero.&#x2022; For each state the logical sum of the transition expressions on all arcs leaving the state is one.&#x2022; Hence the state diagram now is both mutually exclusive and all inclusive
• 10. &#x2022; In the new state diagram we notice that once the turn has been initiated the state diagram allows the cycle to run to completion even if HAZ is asserted. This may have a certain aesthetic appeal, however it would be safer to allow the machine to go into Hazard mode as soon as possible.&#x2022; Hence the state diagram is modified as shown next.
• 11. State Assignment&#x2022; IDLE state of 000.&#x2022; Q1 and Q0 are used to count in gray code sequence (IDLE&#x2192;L1&#x2192;L2&#x2192;L3&#x2192;IDLE) (IDLE&#x2192;R1&#x2192;R2&#x2192;R3&#x2192;IDLE).&#x2022; Q2 identifies LEFT or RIGHT turn.&#x2022; HAZ state of 100.
• 12. &#x2022; Next step &#x2013; sort of transition table&#x2022; In this case the transitions are specified by expressions rather than an exhaustive tabulation of next states Transition List
• 13. Synthesis using transition List&#x2022; Develop a set of transition equations that define the next state variable S* in terms of current state S and inputs&#x2022; The transition list may be viewed as a sort of hybrid truth table in which the state-variable combinations for the current state are listed explicitly and input combinations are listed algebraically.&#x2022; Reading down a S* column find a sequence of 0s and 1s indicating the value of S* for various state/input combinations.&#x2022; A transition equation for a next state variable S* can be written using a sort of hybrid canonical sum.&#x2022; S* = &#x2211; (transition p-term) Transition list rows where S* = 1
• 14. Synthesis using transition List&#x2022; Transition p-term is the product of the current states min-term and the transition expression.&#x2022; The transition equation has one transition p-term for each row of the transition list that contains a &#x2018;1&#x2019; in the S* column.&#x2022; There is no guarantee that the transition equations obtained by this method are in any sense minimal.&#x2022; The equations are not even in the standard POS or SOP forms&#x2022; They only provide a starting point for whatever combinational design method one might choose to synthesize the excitation logic for the FSM
• 15. Synthesis using transition List&#x2022; Based on the transition list we get the following transition equations for Q2*, Q1* and Q0* ( )Q 2* = Q 2 &#x22C5; Q1&#x22C5; Q0 ( L &#x22C5; R + H ) + (Q 2 &#x22C5; Q1&#x22C5; Q0 )( L &#x22C5; R &#x22C5; H ) + (Q 2 &#x22C5; Q1&#x22C5; Q0 )( H ) + (Q 2 &#x22C5; Q1&#x22C5; Q0 )( H ) + (Q 2 &#x22C5; Q1&#x22C5; Q0 )( H ) + (Q 2 &#x22C5; Q1&#x22C5; Q0 )( H ) + ( Q 2 &#x22C5; Q1&#x22C5; Q0)( H ) + ( Q 2 &#x22C5; Q1 &#x22C5; Q0) ( H ) ( ) Q 2* = Q 2 &#x22C5; Q1&#x22C5; Q0 ( R + H ) ( ) + Q 2 &#x22C5; Q0 ( H ) + ( Q 2 &#x22C5; Q0)
• 16. Synthesis using transition List ( )( ) (Q1* = Q 2 &#x22C5; Q1 &#x22C5; Q0 H + Q 2 &#x22C5; Q1&#x22C5; Q0 H )( ) + (Q 2 &#x22C5; Q1&#x22C5; Q0 )( H ) + ( Q 2 &#x22C5; Q1&#x22C5; Q0) ( H )Q1* = Q0( H ) ( )( Q0* = Q 2 &#x22C5; Q1 &#x22C5; Q0 L &#x22C5; R &#x22C5; H ) + (Q 2 &#x22C5; Q1 &#x22C5; Q0)( L &#x22C5; R &#x22C5; H ) + (Q 2 &#x22C5; Q1&#x22C5; Q0 )( H ) + (Q 2 &#x22C5; Q1&#x22C5; Q0 )( H ) ( )( Q0* = Q 2 &#x22C5; Q1 &#x22C5; Q0 H ( L &#x2295; R ) ) + (Q1&#x22C5; Q0)( H )
• 17. Excitation equations&#x2022; On deriving the transition equations it is desirable to use the D flip flops as memory elements&#x2022; The transition equation directly gives the excitation equation in this case&#x2022; The excitation equations of other flip- flops are not so easy to derive&#x2022; Majority of the PLD &amp; ASIC based systems employ D flip flops.
• 18. Variations in the scheme&#x2022; If the column for a particular next state variable contains fewer 0s than 1s, it may be advantageous to write that variables transition equation in terms of 0s in its column S*= &#x2211; (transition p terms ) transition list rows where S *= 0&#x2022; That is S * = 1 for all the p terms for which S * = 0&#x2022; Thus a transition equation may be written for Q 2 * as the sum of 7 p-terms ( )(Q 2 * = Q 2 &#x22C5; Q1 &#x22C5; Q0 L + R + H ) + (Q 2 &#x22C5; Q1&#x22C5; Q0 )( L &#x22C5; R &#x22C5; H ) + (Q 2 &#x22C5; Q1&#x22C5; Q0 )( H ) + (Q 2 &#x22C5; Q1 &#x22C5; Q0 )( H ) + (Q 2 &#x22C5; Q1 &#x22C5; Q0)(1) + (Q 2 &#x22C5; Q1&#x22C5; Q0 )(1) + (Q 2 &#x22C5; Q1 &#x22C5; Q0)(1)
• 19. Variations in the scheme ( ) ( Q 2 * = Q 2 &#x22C5; Q1 &#x22C5; Q0 &#x22C5; H &#x22C5; R + Q 2 &#x22C5; Q0 &#x22C5; H ) ( ) ( + Q1&#x22C5; Q0 + Q 2 &#x22C5; Q0 )&#x2022; To obtain an expression for Q 2 * we simply complement both sides of the reduced equation&#x2022; To obtain an expression for a next state variable V * directly, using the 0s in the transition list, we can complement the right hand side of the general V * equation using DeMorgan&#x2019;s theorem, obtaining a sort of hybrid canonical product V* = &#x220F; (transition s terms) transition list rows where V *= 0&#x2022;Transition s-term is the sum of the currentstates max-term and the complement of thetransition expression.
• 20. Unused states&#x2022; In this problem there were no unused states&#x2022; However, in case there are some unused states in the problem then they do not reflect in the transition list&#x2022; They are treated as don&#x2019;t care in a very limited sense&#x2022; While writing equations for S*, the sum of p-terms for rows that had an explicit 1 in the corresponding column were taken&#x2022; Although we don&#x2019;t consider the unused states, the procedure implicitly treats them as if they had 0s in the corresponding column&#x2022; Conversely for S * the procedure implicitly treats unused states as if they had 1s in the corresponding column
• 21. Output-Coded state assignment&#x2022; The machines outputs are a function of state only&#x2022; A different output combination is produced in each named state&#x2022; We can use the outputs as state variables and assign each named state to the required output combination&#x2022; This sort of assignment is termed as output-coded state assignment&#x2022; Sometimes results in excitation equations that are simpler than the set of excitation and output equations obtained with a state assignment using minimum number of state variables&#x2022; It saves cost in a PLD based design since fewer PLD macrocells or outputs are needed overall&#x2022; Current State| Transition Exp| Next State
• 22. Decomposing State Machines&#x2022; Just like large programs being decomposed into procedures or subroutines, large state-machine problems are often solved with a collection of smaller state machines&#x2022; The original design problem is put into a natural hierarchical structure, so that the functions and uses of the sub-machines are obvious, making it unnecessary even to write a state table for the sub-machine&#x2022; The most commonly used sub-machine is a counter. The main machine usually STARTS the counter when it wishes to stay in a particular main state for n counts&#x2022; The counter counts the n counts and sends a DONE signal when the count is completed
• 23. Decomposing State Machines&#x2022; The main machine is designed to wait in the same state till it receives the DONE signal from the sub-machine&#x2022; This adds an extra output and input to the main machine (START and DONE) but saves n -1 states&#x2022; The simplest type of decomposition is shown in figure&#x2022; The Main machine provides the primary inputs and outputs and executes the top level control algorithm.&#x2022; The sub-machines perform the lower level functions under the control of the main machine and may also optionally handle some of the primary inputs and outputs
• 24. Decomposing State MachinesInputs Outputs Sub Machine Start 1 1 Done 1 Main Machine Start 2 Sub Done 2 Machine 2 Typical hierarchical state-machine structure