1 / 17

Electronics II Physics 3620 / 6620

Electronics II Physics 3620 / 6620. Jan 28, 2009 Part 1 Finite State Machine (continued). 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.

iola-valdez
Télécharger la présentation

Electronics II Physics 3620 / 6620

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Electronics IIPhysics 3620 / 6620 Jan 28, 2009 Part 1 Finite State Machine (continued)

  2. 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 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) A even odd start A anything but A anything but A Example I: Even or odd

  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

  4. 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 1: the “Init” state that has only one possible transition. State Transition • Case 2: the “init” state has two possible transitions, “Shut Down” or “Power Up”. Programming  Comparison : Select

  5. 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 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. More Cases

  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

  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

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

  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

  10. (docount++ (docount=1 start OK )andcount==1docount=0 )andcount>1 docount-- Nested parentheses III • This machine is based on a state machine, but it obviously is not just a state machine

  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 Machine2.) WAIT FOR EVENT – where the machine waits for coins3.) RETURN CHANGE – where the machine returns change4.) COKE PRODUCT – when the machine has received 50 or more cents it will dispense the beverage5.) QUARTER – when the customer enters a quarter6.) DIME – when the customer enters a dime7.) NICKLE – when the customer enters a nickel8.) EXIT – after the change is returned and/or beverage dispensed, the machine will power down (application will terminate)

  12. The State Diagram

  13. Mealy and Moore machines • Moore machine • 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.

  14. Example: Alarm clock state table • 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..)

  15. Alarm clock state table • 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

  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

  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

More Related