1.4 Hardware Implementation

An alternative approach to implementing a state machine is to do so completely in hardware. In a hardware-based implementation, the state of the machine is typically implemented via flip-flops, and the state transitions and outputs are determined by discrete logic elements such as logic gates and look-up tables. The state time is usually derived from a hardware-based timer/counter. Figure 1-8 illustrates a typical state machine implemented in hardware.

The hardware-based solution provides many advantages over the firmware-based solution. Since the entire state machine is implemented completely in hardware that is independent of the core, it frees up the CPU to perform other important functions. In addition, the CPU can be put to sleep without affecting the state machine operation to save power.

Figure 1-8. Hardware-Based State Machine Example

Hardware state machines can be encoded in two ways: binary encoded and one-hot-one encoded. Table 1-3 shows an example of how different states can be binary encoded using flip-flops, and Table 1-4 shows how the same states can be one-hot-one encoded. While binary encoded states take fewer flip-flops to implement, their next-state logic and output logic functions tend to be more complex. On the other hand, one-hot-one encoded states require a higher number of flip-flops to implement the same number of states. Their next-state logic and output logic functions are extremely simple to implement and are usually best implemented when there is a clear sequence of events/states. Ultimately the best method of implementation depends on the individual application design.

Table 1-3. Binary Encoded States
StateFlip Flops (X1,X0)Encoding
State 1000
State 2011
State 3102
State 4113
Table 1-4. One-Hot-One Encoding
StateFlip Flops (X3X2X1X0)Encoding
State 100011
State 200102
State 301004
State 410008