Presentation is loading. Please wait.

Presentation is loading. Please wait.

Electronics II Physics 3620 / 6620

Similar presentations


Presentation on theme: "Electronics II Physics 3620 / 6620"— Presentation transcript:

1 Electronics II Physics 3620 / 6620
Jan 28, 2009 Part 1 Finite State Machine (continued) 11/23/2018

2 Example I: Even or odd The following machine determines whether the number of “A”s in a string is even or odd A circles represents a state (also known as a vertex); an arrow (or “arc”) represents a transition A even odd start anything but A This is an example of a “State Diagram” In Labview we represent different states using the “case structure” Inputs are the characters of a string The “output” is the resultant state: see in-class example implemented in Labview (even_odd.vi) 11/23/2018

3 Labview Implementation
Implementation in Labview is based on a “case” structure (whi8ch represents the state machine itself, and a while-loop around it The actual “state” is kept by a “shift register” within the while loop The shift register shows up as an input (initialize) and output pair Programming  Numeric  Enum Const,. In some cases you can specify an exit state (as shown) to stop 11/23/2018

4 State Transition There are different methods to determine which state to transition to next. Four common methods are discussed below (Note – in the following method examples, “Init” could transition to any state): Case 2: the “init” state has two possible transitions, “Shut Down” or “Power Up”. Case 1: the “Init” state that has only one possible transition. Programming  Comparison : Select 11/23/2018

5 More Cases Case 4 “Init” state using an inner loop and case structure to transition to the next state. The inner case structure contains one diagram for each transition that leaves the current state. Each of the cases in the inner case structure has two outputs – a boolean value, which specifies whether or not the transition should be taken, and an enumerated constant, which specifies the state to which the transition goes. By using the loop index as an input to the case structure, this code effectively runs through each transition case one by one, until it finds a diagram with a “True” boolean output. After the “True” boolean output is found, the case outputs the new state to which the transition goes. Though this method may appear slightly more complicated than the previous methods, it does offer the ability to add names to transitions by “casting” the output of the loop index to an enumerated type. This benefit allows you to add “automatic documentation” to your transition code. Case 3 “Init” state using a boolean array along with an array of enum constants. There is a boolean in the boolean array corresponding to each transition “Init” can make. The array of enum constants represents each transition name. The index of the first “True” boolean in the boolean array corresponds to the index of the new state in the array of enums. See programming  Arrays  * to see the different types of arrays 11/23/2018

6 Error states Some state machines may have a error state with the following characteristics: An unexpected input will cause a transition to the error state All subsequent inputs cause the state machine to remain in the error state 11/23/2018

7 Simplifying State Diagrams I
State machines can get pretty complicated We can simplify the “State Diagram” by leaving out the error state The error state is still part of the machine Any input without a transition on our drawing is assumed to go to the error state Another simplification: Use * to indicate “all other characters” This is a convention when drawing the machine—it does not mean we look for an asterisk in the input 11/23/2018

8 Example II: Nested parenthesis
The following example tests whether parentheses are properly nested (up to 3 deep) start ) ( OK Error * How can we extend this machine to handle arbitrarily deep nesting? 11/23/2018

9 Nested parentheses II Question: How can we use a state machine to check parenthesis nesting to any depth? Answer: We can’t (with a finite number of states) We need to count how deep we are into a parenthesis nest: 1, 2, 3, ..., 821, ... The only “memory” a “pure” state machine has is which state it is in However, if we aren’t required to use a pure state machine, we can add memory (such as a counter) and other features 11/23/2018

10 Nested parentheses III
OK ( do count=1 ) and count==1 do count=0 ( do count++ ) and count>1 do count-- start This machine is based on a state machine, but it obviously is not just a state machine 11/23/2018

11 Example from NI: Coke Machine
Specifications: This application has the following requirements: All Coke products are sold for 50 cents (This was still true on campus in 2004) The machine only accepts nickels, dimes, and quarters. Exact change is not needed. Change can be returned at anytime during the process of entering coins. The States: 1.) INIT – initialize our Coke Machine 2.) WAIT FOR EVENT – where the machine waits for coins 3.) RETURN CHANGE – where the machine returns change 4.) COKE PRODUCT – when the machine has received 50 or more cents it will dispense the beverage 5.) QUARTER – when the customer enters a quarter 6.) DIME – when the customer enters a dime 7.) NICKLE – when the customer enters a nickel 8.) EXIT – after the change is returned and/or beverage dispensed, the machine will power down (application will terminate) 11/23/2018

12 The State Diagram 11/23/2018

13 Mealy and Moore machines
Associates its outputs with states The outputs are represented either within the vertex corresponding to a state or adjacent to the vertex Mealy machine: Associates its outputs with the transitions In addition to the input values, each arc also shows the output values generated during the transition; the format of the label of each arc is Inputs/Outputs Both can be used to represent any sequential system and each has its advantages. 11/23/2018

14 Example: Alarm clock state table
Present State Alarm Weekday Next State Turn off alarm Asleep On X Awake in bed Yes Off Awake and up No When you are asleep and alarm goes on, you go from being asleep to being awaked in bed; you also turn off the alarm The next two rows encode your actions: You get up You go back to sleep This table doesn’t cover what you wouldn’t do…(i.e. if you are asleep and the alarm doesn't go off, you remain asleep, etc..) 11/23/2018

15 Alarm clock state table
Present State Alarm Weekday Next State Turn off alarm Asleep Off X No On Awake in bed Yes Awake and up Covers all the cases First row covers the situation you are asleep, the alarm doesn’t go off and you remain asleep Last row covers the situation you are awake and up and you remain awake and up The third row covers the case you are already up and the alarm goes off. You turn it off and remain Awake in bed 11/23/2018

16 Moore machine diagram Self arcs can be missing (since it outputs are associated with the states and not with the arcs) Offers a simpler implementation when the output values depend only on the state and not on the transitions It requires less hardware to produce the output values than does a Mealy machine, since its outputs depend only on its state and its input values It is well suited for representing the control units of microprocessors 11/23/2018

17 Mealy machine diagram Self arcs must be shown (because the output values are shown on the arcs) Can be more compact than Moore machine, especially when two or more arcs with different output values go into the same state 11/23/2018


Download ppt "Electronics II Physics 3620 / 6620"

Similar presentations


Ads by Google