Go Back   Velocity Reviews > Newsgroups > VHDL
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

VHDL - Counter in FSM doesn't work

 
Thread Tools Search this Thread
Old 06-26-2007, 11:11 AM   #1
Default Counter in FSM doesn't work


Hello ng,

I have a problem with my fsm.
I use a counter to count numbers of the pass through.

here my vhdl code (simple version):

process(i_rst_n,i_clk_fpt)
begin
if (i_rst_n= '0') then
state <= IDLE;
elsif rising_edge(i_clk_fpt) then -- risign edge
state <= nextstate;

end if;
end process;


process(state)
begin
case(state) is
when IDLE =>
cnt <= 0;
nextstate <= COUNT;
when COUNT =>
if (cnt < then
cnt <= cnt +1;
else
cnt <= 0;
end if;
nextstate <= COUNT;

end case;

end process;

Now i get this warning:

Warning: Found 33 combinational loops!
Each loop is reported with an instance in the loop
and nets connected to that instance.
@W: BN134 :"d:\logik\counter\cnt.vhd":37:1:37:4|Found combinational
loop during mapping
1) instance o_count[31:0] work.cnt(behavioral)-o_count[31:0], output
net "o_count[0]" in work.cnt(behavioral)
input nets to instance: .........



cpudesigner@gmx.at
  Reply With Quote
Old 06-26-2007, 11:26 AM   #2
Frank Buss
 
Posts: n/a
Default Re: Counter in FSM doesn't work
wrote:

> process(state)
> begin
> case(state) is
> when IDLE =>
> cnt <= 0;
> nextstate <= COUNT;
> when COUNT =>
> if (cnt < then
> cnt <= cnt +1;
> else
> cnt <= 0;
> end if;
> nextstate <= COUNT;
>
> end case;
>
> end process;


This is not clocked, so it counts all the time while state = COUNT, which
doesn't lead to a useful schematic.

--
Frank Buss,
http://www.frank-buss.de, http://www.it4-systems.de


Frank Buss
  Reply With Quote
Old 06-26-2007, 11:32 AM   #3
Jyke
 
Posts: n/a
Default Re: Counter in FSM doesn't work
<> wrote in message
news: ups.com...
> Hello ng,
>
> I have a problem with my fsm.
> I use a counter to count numbers of the pass through.
>
> here my vhdl code (simple version):
>
> process(i_rst_n,i_clk_fpt)
> begin
> if (i_rst_n= '0') then
> state <= IDLE;
> elsif rising_edge(i_clk_fpt) then -- risign edge
> state <= nextstate;
>
> end if;
> end process;
>
>
> process(state)
> begin
> case(state) is
> when IDLE =>
> cnt <= 0;
> nextstate <= COUNT;
> when COUNT =>
> if (cnt < then
> cnt <= cnt +1;
> else
> cnt <= 0;
> end if;
> nextstate <= COUNT;
>
> end case;
>
> end process;
>
> Now i get this warning:
>
> Warning: Found 33 combinational loops!
> Each loop is reported with an instance in the loop
> and nets connected to that instance.
> @W: BN134 :"d:\logik\counter\cnt.vhd":37:1:37:4|Found combinational
> loop during mapping
> 1) instance o_count[31:0] work.cnt(behavioral)-o_count[31:0], output
> net "o_count[0]" in work.cnt(behavioral)
> input nets to instance: .........
>


Since cnt is not inside a clocked process, it is not a register. So when
state is COUNT you increase the cnt as fast as the simulator can do it (with
no clock involved). You should recode it so, that cnt is registered, you
probably want it to be increased only on clock egde.

Jyke.




Jyke
  Reply With Quote
Old 06-26-2007, 11:36 AM   #4
Jonathan Bromley
 
Posts: n/a
Default Re: Counter in FSM doesn't work
On Tue, 26 Jun 2007 03:11:12 -0700, wrote:

>Hello ng,
>
>I have a problem with my fsm.


<rant>
The problem arises because you are (imperfectly) following
the advice of idiotic textbooks, instead of following the
advice of experienced members of this newsgroup.
</rant>

>process(i_rst_n,i_clk_fpt)
>begin
> if (i_rst_n= '0') then
> state <= IDLE;
> elsif rising_edge(i_clk_fpt) then -- risign edge
> state <= nextstate;
> end if;
>end process;
>
>process(state)
>begin
> case(state) is
> when IDLE =>
> cnt <= 0;
> nextstate <= COUNT;

[and much more]

Your combinational process is trying to represent
a counter on "cnt", but I see no registers for "cnt"
anywhere. Hence the combinational loops.

Your combinational process is the process that...
* you don't need
* many people here quite correctly tell you not to use
* causes all the trouble
* is a PITA to write

However, let's take it at face value and see what we can do.
FIRST: This is a state machine. Consequently, in many
situations, the next state will be the same as the current
state. Therefore, it is a VERY good idea to start the
next-state combinational process with adefault assignment:

> process(state)
> begin

nextstate <= state; ----- DEFAULT ASSIGNMENT
> case(state) is
> when IDLE =>
> cnt <= 0;
> nextstate <= COUNT;


Second, we need registers on "cnt". So you better put those in
the registered process, along with the state variable. This means
that you now need two count signals: the registered version, and
the next-state signal (just like your state variable). This is
getting silly, isn't it?

Wouldn't it all be SO much easier to use a single process for the
whole mess?

If you really insist on keeping your evil do-like-the-textbook-says
two-process state machine, then please separate out the counter into
another clocked process, and use the state machine to create control
outputs that cause the counter to reset, count, decrement, bit-flip
or whatever. Then you have done something that many good designers
like to do - you have separated control logic from datapath.

Alternatively, if you want to merge the control logic and datapath,
put the whole thing in a single clocked process so that you don't
have absurd unnecessary next-state signals cluttering your
architecture. There have been many, many discussions here about
how to do that.

Sorry to flame you for something that's not your fault. Your
problem is a perfect example of why the textbook/undergraduate
two-process coding style is a diabolical mess. Leave it behind
you, ignore your prof's criticisms, get on with doing the job
in a sensible way.

Grrrr.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK

http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.


Jonathan Bromley
  Reply With Quote
Old 06-26-2007, 12:27 PM   #5
KJ
 
Posts: n/a
Default Re: Counter in FSM doesn't work

"Jonathan Bromley" <> wrote in message
news:...
>
> Sorry to flame you for something that's not your fault. Your
> problem is a perfect example of why the textbook/undergraduate
> two-process coding style is a diabolical mess. Leave it behind
> you, ignore your prof's criticisms, get on with doing the job
> in a sensible way.
>
> Grrrr.
> --
> Jonathan Bromley, Consultant


SOMEBODY is in a cranky mood today...chill out, relax

But I do agree with the technical aspects of your post.

KJ




KJ
  Reply With Quote
Old 06-26-2007, 12:59 PM   #6
Jonathan Bromley
 
Posts: n/a
Default Re: Counter in FSM doesn't work
On Tue, 26 Jun 2007 11:27:44 GMT, "KJ"
<> wrote:

>> Grrrr.

>
>SOMEBODY is in a cranky mood today...chill out, relax


Sorry. Too much blood in the caffeine-stream, or something.
Anyway, at my age I'm allowed the occasional curmudgeonly
rant before Matron comes round with the tea and biscuits.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL * Verilog * SystemC * e * Perl * Tcl/Tk * Project Services

Doulos Ltd., 22 Market Place, Ringwood, BH24 1AW, UK

http://www.MYCOMPANY.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.


Jonathan Bromley
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
The Counter Strikes... aihockey44 Gaming 0 04-29-2009 08:35 PM
Any help for maintaining the work flow of the system………. Zachar Software 1 08-04-2008 06:49 AM
Back button doesn't work when it is a secure page returning to a non secure page Miss Mary General Help Related Topics 1 09-21-2007 10:32 AM
Identity Theft at Work @ A True Review Silverstrand Front Page News 0 06-27-2006 03:56 PM
Free S/W needed: Supplied PowerDVD doesn't work maggie_g47@hotmail.com DVD Video 6 09-20-2005 04:56 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46