Two Verilog FSM style compare

Hi all,

There is a problem on How to write FSM in Verilog

formatting link
Most synthesis tools recommend second "Using Two Always Blocks" style. But I would like to use third "Single Always" style. It seems more compact.

What's the pros and cons between the two styles? I see that the third style may have state transition latency. But does the third style gain higher frequency and shorter critical path? Thanks!

Best regards, Davy

Reply to
Davy
Loading thread data ...

It is. It works fine. Try it and see.

A state transition takes one clock tick, no matter how you do it. Input synchronization should be handled as a separate issue.

There are no performance differences for synchronous designs.

The single process controller does not allow unregistered outputs and makes long-winded textbooks unnecessary.

-- Mike Treseler.

Reply to
Mike Treseler

Hi Davy,

This is really a question for the synthesis tools on the matter of how your code is interpreted. If any of the coding styles would produce different results, the corresponding synthesis tool should have fixed this deficiency by now :)

However, there is no really benefit in terms of what you will eventually get, but rather what is more convenient. Personally, I always prefer a single "always", especially if the state machine has MANY outputs.

Going a bit further than your question, in my group, I am not enforcing any of those ways. The coding style is completely at the designer's choice. Instead, I enforce the designer to very-well document the "bubbles" stuff, so that he knows what this state machine is doing and it is coded only once.

Hope this helps.

Vladislav

Reply to
Vladislav Muravin

Some more things which are OK, and which help with the single always block style:

Multiple non-blocking assigns to the same register: the last one wins:

always @(posedge clk) begin out > style may have state transition latency.

--
/*  jhallen@world.std.com (192.74.137.5) */               /* Joseph H. Allen */
int a[1817];main(z,p,q,r){for(p=80;q+p-80;p-=2*a[p])for(z=9;z--;)q=3&(r=time(0)
 Click to see the full signature
Reply to
Joseph H Allen

True. A blocking assignment is like a local variable. However, you *can* make the always block as big as you like with as many registers as you like.

-- Mike Treseler

Reply to
Mike Treseler

So... you should make the entire design in just one always block? :-)

Verilog is a crazy language. I write code in order, but you really don't have to:

// Move ~c into a

always @(b or c) begin a = b; b = c; b = ~c; end

A change in c triggers the always block: ~c moved into b. Change in b retriggers the always block: b moved into a. I guess synthesis tools have to make a dependency graph to figure out the dataflow.

--
/*  jhallen@world.std.com (192.74.137.5) */               /* Joseph H. Allen */
int a[1817];main(z,p,q,r){for(p=80;q+p-80;p-=2*a[p])for(z=9;z--;)q=3&(r=time(0)
 Click to see the full signature
Reply to
Joseph H Allen

It can be done.

formatting link

-- Mike Treseler

Reply to
Mike Treseler

That sort of construct, with blocking variables, is bound to bite you in the ass!

-a

Reply to
Andy Peters

I know someone who never ever makes more than one assignment to a variable in a single always block (no defaulting at all for maximized typing). Instead he makes an assignment to each register in each decision branch, so that you get one decision branch or less per editor screen: tiny state machines end up being 10,000 lines. He also uses non-blocking assigns in combinatorial always blocks, which is just weird. He also does the out of order thing above: there will be some code at the end whose outputs are used by a state machine case at the top. Finally, he never uses "if": only "casex", always with "// synthesis full_case parallel_case". Usually, the casex's are three levels deep. Finally he always uses positional arguments in instantiations for modules with 100s of signals (sometimes the wire names even match the port names). Oh yeah: he never uses parameters- only `defines all in one giant include file, even for state machine states. There is not one comment in 100,000 lines of code. I am not making this up.

Hmm... should I just edit the code and get it over with or should I make that Verilog refactoring program I always knew would come in handy... hmm...

Well on the positive side, his_signals_look_like_this, NotLikeThis. He uses the default emacs verilog mode, so the begins and ends are at the same indentation level. Some other person's annoying code looks like this:

if (theSignal) begin stuff end // if (theSignal)

Whoever wrote the elisp macros which put in these useless VHDLish comments should be shot. His files all begin with a long boilerplate comment with no useful information (but he does put comments in his code, unlike the first person).

Sorry, I'll stop ranting now.

--
/*  jhallen@world.std.com (192.74.137.5) */               /* Joseph H. Allen */
int a[1817];main(z,p,q,r){for(p=80;q+p-80;p-=2*a[p])for(z=9;z--;)q=3&(r=time(0)
 Click to see the full signature
Reply to
Joseph H Allen

Hi Joseph.. First this guy works for a company and is allowed to get away with it? It sounds like a true nightmare to even look at his code, let alone interpret it!

But > > >Joseph H Allen wrote:

Reply to
John McGrath

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.