Digital IC Design – Detailed Explanation of Finite State Machines

Digital IC Design - Detailed Explanation of Finite State Machines

Click the blue text to follow us

Digital IC Design - Detailed Explanation of Finite State Machines

A state machine is a commonly used implementation method in digital IC development using Verilog. A state machine is a universal model for sequential circuits, and any sequential circuit can be represented by a state machine.

In the actual digital circuit design process, the choice between using sequential logic or a state machine should be based on specific design requirements. For example, if I want to implement a simple counter, there is no need to write a state machine.

Below, I summarize several situations where a state machine is needed::

(1) Complex logic with state changes

When the design involves many different states, with complex transition conditions between different states, and different outputs for different states, using a state machine is a better choice.

(2) Requires state memory and condition-driven actions

When the design needs to determine the next operation based on the current state and input signals, a state machine can effectively meet this requirement.

(3) Implementing specific protocols or algorithms

In scenarios where some communication protocols or control algorithms are implemented, a state machine can accurately simulate the execution flow of the protocol or algorithm. For example, in the implementation of the I2C protocol, defining idle state, sending address state, sending data state, receiving data state, waiting state, etc., and specifying data processing and state transitions for each state according to protocol requirements can clearly achieve I2C communication.

(4) Insensitive to resource usage

A state machine implements functionality by breaking down complex logic into ordered state transitions, requiring additional registers to store state information and combinational logic circuits to handle state transitions and outputs, which willoccupy more chip area. Moreover, the operation of a state machine relies on sequential state transitions, and each state transition requires a certain number of clock cycles, thusincreasing time overhead.

Classification of State Machines

  • Moore State Machine:The output depends only on the current state, so the output remains stable throughout a complete clock cycle, even if the input signal changes; the effect of the input on the output will only be reflected in the next clock cycle.

Digital IC Design - Detailed Explanation of Finite State Machines

Structure of Moore State Machine

  • Mealy State Machine:The output depends on both the current state and the input. When the input signal changes, the output signal changes immediately. Therefore,under the same logic, the output response of a Mealy state machine to input will be faster by one clock cycle than that of a Moore state machine.

Digital IC Design - Detailed Explanation of Finite State Machines

Structure of Mealy State Machine

In fact, whether a state machine is Mealy or Moore, these concepts are more often used in exams or interviews; in actual work, writing state machines rarely involves these concepts.

Writing State Machines

State machines can be written in one-stage, two-stage, or three-stage formats.I strongly recommend the three-stage writing method.In the source code of mature commercial IP, the implementation of state machines adopts the three-stage writing method. This method makes the code logic clear and easy to read, while also helping synthesis tools achieve better timing performance circuits.

Three-stage Writing Method for State Machines:

(1) Encode the state machine based on the number of states defined by the state machine.Common encoding methods include: binary encoding, Gray code, and one-hot code.

  • Binary Encoding: N flip-flops can form 2n states, using fewer flip-flops and saving resources; however, multiple bits may change simultaneously during state transitions, causing glitches.

  • Gray Code: N flip-flops can form 2n states, and only one bit changes during state transitions, reducing the possibility of glitches.

  • One-Hot Code: N flip-flops can only form n states, increasing the number of flip-flops used; however, this encoding method simplifies subsequent decoding and can effectively save and simplify combinational circuits.

(2) In the first stage of the state machine,use sequential logic with non-blocking assignments, declaring current_state and next_state to pass the state of the registers.

Digital IC Design - Detailed Explanation of Finite State Machines

(3) In the second stage of the state machine,use combinational logic with blocking assignments. First, draw the state transition diagram, and determine the next state of the state machine based on the current state and input.

Digital IC Design - Detailed Explanation of Finite State Machines

(4) The third stage of the state machine describes the output logic. Although this is called the third stage of the state machine,it does not necessarily have to be described using only one always block. Some output logic may use sequential logic, while others may use combinational logic.

Digital IC Design - Detailed Explanation of Finite State Machines

The use of state machines is to make complex logic clearer and designs more reliable. I hope this article helps everyone gain a deeper understanding of the use of state machines in digital IC design.

Thank you for reading my article. If you find it helpful, please give me afollow.

>/ Author: Xiao Xin Ji

Leave a Comment