Nearly every digital system includes Finite State Machines (FSMs). To identify FSMs and execute optimizations that may alter the encoding of the states, synthesis tools examine your code. Even if you meticulously choose and specify the values that embody your states in the code base, the synthesis tool may replace them with others that have a different bit length.
Common descriptors for the state encoding of an FSM include Binary (heavily encoded) and One-hot.
A binary-encoded FSM design uses only as many flip-flops as are required to encode the machine’s state count uniquely. The real quantity
The maximum number of flip-flops that may be used is limited by the logarithm of the FSM’s state count.
A one-hot FSM design needs a flip-flop for each state and only one flip-flop is set at a time in the design.
One-of-a-kind FSM design. A binary FSM needs 4 flip-flops for a state machine with 9 to 16 states, but a one-hot FSM requires only one per state in the design.
Flip-flops are abundant on an FPGA, and the combinational circuitry necessary to achieve a one-hot FSM architecture is often lower than that required for most binary-encoder techniques. Since FPGA speed is often proportional to the amount of the design’s combinational circuitry, one-hot FSMs typically operate faster than binary-encoded FSMs. FSM with more complex combinatorial logic modules.
Each encoding has advantages and disadvantages, so it boils down to an optimization issue that relies on a multitude of variables:
- If a relatively basic system gives identical outcomes regardless of encoding, then the initial encoding is the best option.
- If the FSM cycles through the states in a single route (similar to a counter), the Gray code is an excellent option.
- If the FSM contains an arbitrary number of state transitions or is anticipated to operate at a high frequency, python one-hot encoding is the best option. So avoid multi-hot encoding in this particular case.
However, these assertions are only best estimates, and solving the challenge of determining the best possible state assignment is difficult. Therefore, my official recommendation is to let the compiler decide.