Hello all,
In a recent thread (where the O.P. looked for a HDL "Code Complete" substitute) an interesting discussion arised regarding the style of coding state machines. Unfortunately, the discussion was mostly academic without much real examples, so I think there's place to open another discussion on this style, this time with real examples displaying the various coding styles. I have also cross-posted this to c.l.vhdl since my examples are in VHDL.
I have written quite a lot of VHDL (both for synthesis and simulation TBs) in the past few years, and have adopted a fairly consistent coding style (so consistent, in fact, that I use Perl scripts to generate some of my code :-). My own style for writing complex logic and state machines in particular is in separate clocked processes, like the following:
type my_state_type is ( wait, act, test );
signal my_state: my_state_type; signal my_output;
... ...
my_state_proc: process(clk, reset_n) begin if (reset_n = '0') then my_state if (some_input = some_value) then my_state ... when test =>
... when others =>
my_state