Download presentation
Presentation is loading. Please wait.
1
ECE 352 Digital System Fundamentals
State Diagrams This presentation introduces state diagrams as a way to describe FSM behavior.
2
State Diagram A graphical depiction of the state table
Circles represent the states in the diagram In an FSM circuit with N flip-flops, the state is encoded as an N-bit binary number N bits can represent up to 2N states Directed lines represent the state transitions Arrows indicate the direction of the transition Labeled with input value(s) that cause the transition Each line of the state table corresponds to a transition Circuit outputs shown where they are relevant Moore machine: inside the state circle Mealy machine: on the transitions A state diagram is a graphical depiction of the same information contained in a state table. The state table is a very dense way to represent the behavior of a circuit, but it is difficult to look at the table and visualize what the machine does. In a state diagram, we represent each state with a circle. This means the state diagram of an FSM with N flip-flops can have up to 2^N state circles. Transitions between states are represented by unidirectional lines, where the arrowhead indicates the direction of the transition. Each transition is labeled with the input values that will cause that transition. There is a transition for each row of the state table. Where the circuit outputs are shown on the state diagram depends on the type of FSM it is. For a Moore machine, the output values are shown inside the state circle. For a Mealy machine, the output values are shown on the transitions because they are affected by the input values.
3
Example Moore Diagram Create state diagram based on state table
Two states (Q=0, Q=1) Next-state transitions based on input A and current state Let’s look at an example based on a Moore machine with one flip-flop. We can create a state diagram from a state table by first drawing a circle for each state and labeling it with the state number. Then we look at each line of the state table and add the transitions. Here, an input of 0 while in state 0 causes a next state of 0, so we add a transition from state 0 to state 0, and we label it 0 because that is the input value that can cause the transition. The next line of the state table says that if the input is 1 while in state 0, the next state should be state 1. So we add a transition pointing from state 0 to state 1, labeled with the input value 1.
4
Example Moore Diagram Create state diagram based on state table
Two states (Q=0, Q=1) Next-state transitions based on input A and current state On the third line, the state table indicates an input of 0 while in state 1 causes the next state to be 1. And we continue this until we have added a transition for each row of the state table.
5
Example Moore Diagram Create state diagram based on state table
Two states (Q=0, Q=1) Next-state transitions based on input A and current state Output depends only on current state We can see this is a Moore machine, so we add the output value for each state to the bottom of that state’s circle. The completed state diagram makes it much easier to see that the output will toggle at each active clock edge as long as A is 1, and will remain constant when A is 0.
6
Example Mealy Diagram Create state diagram based on state table
Two states (Q=0, Q=1) Now let’s look at a Mealy machine. We know it has two states, so we add the state circles.
7
Example Mealy Diagram Create state diagram based on state table
Two states (Q=0, Q=1) Next-state and output based on input A and current state Input / Resulting Output When we add the transitions, we label them with the input value that causes the transition and the corresponding output value. It is important to recognize what the output value on the transition means – it is the value the circuit will output while the circuit is in the state that the transition is leaving. Remember, the state does not update until the active clock edge, so the transition is not actually taken until then. The last transition we drew means that the output is 0 when the machine is in state 1 AND the input is 1.
8
Comparing State Machine Types
Note: these state diagrams do not have the same behavior! They show the differences between the two diagram types Moore Mealy Output depends only on the current state Output depends on current state and circuit inputs Here we can see the differences between Mealy and Moore state diagrams. Note that these two diagrams do NOT express the same behavior; we’re just comparing them to see how the diagrams represent information differently. Since Moore outputs depend only on the state, they are shown in the state. Since Mealy outputs depend on the state AND the circuit inputs, they are shown on the transitions. output shown in the state output shown on transitions
9
Comparing State Machine Types
Moore Mealy Output depends only on the current state Output depends on current state _______________ and circuit inputs The difference between Moore and Mealy machine behavior is apparent when we observe how—and more specifically, WHEN—their outputs can respond to state and input changes. With a Moore machine, the outputs can ONLY change when the state changes, so they can only change at the active clock edges. Mealy outputs, on the other hand, depend not only on the state, but also on the circuit inputs. This means they can change either when the state changes, or when the circuit input changes.
10
Another State Machine Example
Identify if the state machine is Mealy or Moore by looking at the output(s) Moore machine: Output depends only on the current state (Not affected by A!) Let’s look at another example of going from a state table to a state diagram. First we look to see if the machine is Moore or Mealy. Note that the output is not dependent upon the input A, so this is a Moore machine.
11
Another State Machine Example
Draw one state per state value Since this is a Moore machine, also annotate each state with the output in that state The machine has four states, so we add four state circles and label them with the four state numbers. Since this is a Moore machine, we also write the output value into each state circle.
12
Another State Machine Example
Draw the state transitions specified in the table Point from the current state to the next state, labeled with the input value causing that transition Next, we add the state transitions to the diagram. Since the circuit has one input, there are two transitions from each state, one for an input value of 0, and the other for an input value of 1.
13
Another State Machine Example
Also need to annotate the diagram with… The state the circuit starts in when it is reset The names of the input/output signals Input: A Output: Y There’s just a little more information we need. If the circuit has an asynchronous reset, we also need to add that to the diagram. Since this signal is unrelated to the clock, we usually show it as a curvy arrow that points to the initial state. This information isn’t shown in a state table, so it would be specified separately. We also need to add a legend so that we know the signal names in the circuit. The legend is particularly important for a circuit with multiple inputs or outputs, because it tells us which input values correspond to which inputs, and the same for outputs.
14
What Does It Do? Count up if input A is 1 Count down if input A is 0
Output 1 when the count is at 00 Up-down counter Direction controlled by input signal A Input: A Output: Y So, what does the machine do? It counts. If A is 1, the two-bit state number, the count, is incremented, and if A is 0, it is decremented. The output is 1 only when the count is 0. Not surprisingly, this machine is called an up-down counter!
15
Counters One of the simplest sequential circuits
Pre-determined sequence of values The current state is often also the circuit output These FSMs have relatively simple diagrams May only support moving forwards through sequence May also have an enable Enabled: moves to next value at clock edge Disabled: stays at the current value May also have an up/down control Move forward or backward in the sequence With or without enable Can count using different sequences… Counters are one of the simplest sequential circuits, where the state is often the output. They have relatively simple state diagrams, and include features such as an enable input or an up/down control, as we just saw. Although the counter example we showed used an arithmetic counting sequence, we can make counters that use any fixed sequence of values.
16
How Else Could We Design It?
Use a 2-bit adder circuit! Add 01 to current count if counting up (A is 1) Add 11 to current count if counting down (A is 0) What would happen if we contracted this circuit? Let’s think about how else we could have built the up-down counter—without even drawing a state diagram. Well, we could have used a 2-bit adder as an incrementer/decrementer, hooked up as shown here. When the input A is 1, we are adding 01, so it counts up at each active clock edge when the values in the flip-flops update. When A is 0, we are adding 11, which is negative 1, so it counts down at each active clock edge. You’ve seen how contraction simplifies circuits with constant inputs – what do you think would happen if you applied contraction to this circuit?
17
Another Counter 2-bit saturating up/down counter
Does not overflow past 0 or 3 Instead, stays at that state if told to go “further” Mealy machine: outputs 1 if already at largest value and told to count up (A is 1) Outputs a 0 otherwise Input: A Output: Y Here’s another counter example with slightly different behavior. It is also a type of 2-bit up-down counter, but when the count hits 0 or 3, it doesn’t continue counting past that point. We say that the counter “saturates” at its limits. Instead of wrapping around like the previous counter, it simply stays at the highest or lowest count until it’s told to go the other way. This is a Mealy machine, and the only time the output is 1 is when the count has saturated at 3 and input A is telling it to count up.
18
Diagrams Represent Hardware
The transitions on the diagram represent the state change that will occur if the input is that value at the active clock edge An output on the transitions is the output for the corresponding input, even between clock edges In a Mealy machine, if the input changes between edges, so might the output! Input: A Output: Y When thinking about the behavior of an FSM represented by a state diagram, it’s important to remember that the diagram represents hardware, and behaves the way the hardware would behave. When in a state, the input can change several times before the active clock edge, but the earlier values don’t affect which state the machine will enter next. Only the input value at the active clock edge determines which of the transitions is actually taken. The fact that we show output values on the transitions for Mealy machines does NOT mean the output can only change at the state transitions. We show the output values there because the output depends on both the current state and the input value, and we already need to show the input value on the transition. If the input changes between clock edges, the output may change as well.
19
Diagrams Represent Hardware
Input: A Output: Y Since the diagram represents hardware, we can create a waveform showing its behavior. Note that both the next state and output values can change between clock edges since they are functions of the state and the input. Remember, this is a Mealy machine. However, the next state value only matters at the active clock edge, because that is when the next state values at the flip-flops’ inputs are stored into the flip-flops to become the current state. Output and next state are functions of current state and input The next state only matters at the active clock edge
20
ECE 352 Digital System Fundamentals
State Diagrams This concludes our video on state diagrams.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.