Interested In VHDL Training? Click Here

0 votes
in Verilog by (240 points)

What is the best way to code a finite state machine in Verilog?

2 Answers

0 votes
by (220 points)

There are 4 fsm encoding types:
- Binary encoding - states are represented in binary code: 0000, 0001, 0010, 0011, etc. Less flip-flops then in the One hot/cold style, more gates (the cause is the to decode binary states) then in the One hot/cold style. Less performance than in One hot/cold.
- Gray encoding - states are represented in Gray code: 0000, 0001, 0011, 0010, .. . Each state is different from another only by a single bit. This gives several advantages: lower power consumption (less switching), and makes the FSM asynchronous outputs resilient to glitches. But the cost is in increased gate usage. But in practice I rarely see a FSM with asynchronous outputs. And in most of cases we have been targeting low power consumption as well as performance so we used other ways to reach it.
- One Hot - one bit is high, the rest are low: 0001, 0010, 0100, 1000. N states - N of flipflops, but less gate utilization and higher performance than with binary encoding because of not needing any combinational logic for the state decoding. Practically, I've never seen a FSM where for One-hot state encoding needed significantly more bits then the binary encoding.
- One Cold - the one bit is low, the rest are high: 1110, 1101, 1011, 0111. Actually the same as the One-hot. But I never used it and never saw the usage of it. I think that this coding style may be fabric-dependent. For example if in a ASIC design library the best performance reachs by using an active low level.

In most cases the One-hot encoding is used. And I think this is the best way in almost all designs.

0 votes
by (220 points)

There are two types of finite state machines: Mealy and Moore. In a Mealy state Machine, the value of output depends on both current state and current input while in a Moore state machine the output value depends on the current state only.

The mealy state machine is most commonly used. There various encoding methods for representing the states of FSM like Binary encoding, Gray encoding, One Hot and One Cold. The most commonly used method is the 'One Hot' method in which only one bit is high at a time.

A sample code can be found here: http://ftp.smart-dv.com/tidbits/verilog_fsm.html

Want to improve your VHDL skills?

Click Here - Sign Up For VHDL Training

© 2022 by Hardware Coder. User contributions are licensed under cc by-sa 4.0 with attribution required. Attribution means a link to the question, answer, user, etc on this site.

This site is owned and operated by Hardware Coder in McKinney, Texas.

Send Us A Message
About Us

By using this site, you agree to the following:

Privacy Policy
Terms and Conditions
DMCA Policy
Earnings Disclaimer
Legal Disclaimer

...