Counter in FSM doesn't work

  • Permalink
  • submit to reddit
  • Email
  • Follow


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 < 8) 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: .........

0
Reply cpudesigner703 (1) 6/26/2007 10:11:12 AM

See related articles to this posting

cpudesigner@gmx.at wrote:

> process(state)
> begin
> 	case(state) is
> 		when IDLE =>
> 			cnt <= 0;
> 			nextstate <= COUNT;
> 		when COUNT =>
> 			if (cnt < 8) 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, fb@frank-buss.de
http://www.frank-buss.de, http://www.it4-systems.de
0
Reply Frank 6/26/2007 10:26:02 AM

<cpudesigner@gmx.at> wrote in message 
news:1182852672.393000.317530@w5g2000hsg.googlegroups.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 < 8) 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. 


0
Reply Jyke 6/26/2007 10:32:17 AM

On Tue, 26 Jun 2007 03:11:12 -0700, cpudesigner@gmx.at 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
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which 
are not the views of Doulos Ltd., unless specifically stated.
0
Reply Jonathan 6/26/2007 10:36:47 AM

"Jonathan Bromley" <jonathan.bromley@MYCOMPANY.com> wrote in message 
news:irp183tvlhbbojsomlqtrsvn0i1dukul00@4ax.com...
>
> 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 


0
Reply KJ 6/26/2007 11:27:44 AM

On Tue, 26 Jun 2007 11:27:44 GMT, "KJ" 
<kkjennings@sbcglobal.net> 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
jonathan.bromley@MYCOMPANY.com
http://www.MYCOMPANY.com

The contents of this message may contain personal views which 
are not the views of Doulos Ltd., unless specifically stated.
0
Reply Jonathan 6/26/2007 11:59:29 AM
comp.lang.vhdl 6173 articles. 13 followers. Post

5 Replies
168 Views

Similar Articles

[PageSpeed] 59

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

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 < 8) then cnt <= cnt +1; else cnt <= 0; end if; nextstate <= COUNT; end case; end process; Now i get this warning: W...

Working on an FSM
Hello, I'm learning about FSMs and I'm having a hard time getting my code to run correctly. I'm getting errors that say the registers for my states won't hold outside of the clock edge, and another set of errors saying that i have multiple constant drivers that can't be resolved. Does anyone think that they could help me out with this code? I've truncated the switch, the full source can be found here http://paste.org/pastebin/view/26824 Thanks Malik **************************************************************************************************************** LIBRA...

why an FSM is not a counter?!
After some study and a lot of discussions with colleagues and friends I would like to pin down the reasons why I have always believed that a finite state machine (FSM) _is not_ a counter and at the same time try to explain why a counter is a very special FSM (hope the thread will not be too hot!). I will start with my definitions and proceed with conclusions. _Definition_: an FSM is a mathematical abstraction used to describe a particular process or model. It consists of states which carry no information about the history of the process (*1*) and of arcs which define the conditions to ...

Interface counters not working
I bought a used 2950 and everything seemed ok with it until I checked the interface counters. For some reason, none of the physical port's counters are working and they all stay at zero despite traffic passing through the switch. The routers and servers on the switch ports are working fine, but I dont get why no traffic is registering on the interface counters. The only one thats working is the vlan interface dukest#show int fa0/2 FastEthernet0/2 is up, line protocol is up (connected) Hardware is Fast Ethernet, address is 000d.bd02.60c2 (bia 000d.bd02.60c2) Description: pm-b MT...

working word counter
After getting some help working through my bugs, I have what seems to be a robust, working word counter script. I post it here to benefit others that might want this in the future and so that if I ever lose my copy I can come back here to find it :) Some other scripts that I used for inspiration failed when confronted with whitespace before the string or miscalculated when encountering linefeeds and other non-space spaces, so I made mine better. Definition of words for this exercise is contiguous groups of characters separated by whitespace. Maybe it will even be useful to somebody besides...

How does the power counter work?
Hi, I had a new Macbook bought last month, then found that the power counter stays at 6 times for quite a while. I didn't let the battery discharge too much, usually not less than 95%, but when the battery level approaches 93~95% the charging process will start,and then charge the battery to 100%, what's strange is that the power counter doesn't add up 1. I'm quite curious to find out why, and most importantly, does this mean that my battery will last longer as Apple guarantee the battery life of 300 charges (reflected by this power counter of 300). Jack ...

FSM stops working
Hi all I've been working on a project that has uses a FSM and have run out o ideas about why it's not working. There are four states, an inpu from off chip triggers the change between most states, except th "00" state which automatically changes to the "01" state on th rising edge of the clock. However, after running the design for while the state stops changing and is stuck in the "00" state, wher it should automatically change regardless of the input. Any ideas a to why this is happening would be much appreciated. Included below i my code Thanks ...

simple counter...why does it not work correctly
I'm trying to implement a extremely simple counter in my m-file. However, at 0.1 it doesn't work correctly while at all other values, it works fine. Can anyone tell me what coding mistake I've made? Thanks. Yuki Code is: d=0; i=0; while (d<=1000) i=i+1; if d < 0.001 d=d+0.0001 elseif d < 0.01 d=d+0.001 elseif d < 0.1 d=d+0.01 elseif d < 1 d=d+0.1 elseif d < 10 d=d+1 elseif d < 100 d=d+10 elseif d < 1000 d=d+100 end end Yuki Michii: <SNIP FP-evergreen... a hint: <http://www.mit....

Cannot get a session counter to work
Hi I cannot get sessions to work. I have the following code </body> <? session_start(); $counter++; print "You have visited this page $counter times during this session"; session_register("counter"); ?> </html> And get the following output Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/ted/ public_html/store/test/testsession.php:15) in /home/ted/public_html/ store/test/testsession.php on line 16 Warning: session_start() [function.session-start]: Cannot send session cac...

counter stops vi from working
Hello, &nbsp; I?m using a ni USB 6215 with labview 8.2, the problem i have is related to counters. I?m using two counters to measure two different shaft speeds as well as 3 analogue inputs. The problem i found was when the shaft is not turning or turning very slow that the vi does not take any readings. It basically freezes until the shaft start running. If I do not wire a time out value to the DAQ this error occures. Fehler -200284 ist bei DAQmx Read (Counter 1D DBL 1Chan NSamp).vi:1 aufgetreten How can i runn the vi constantly even when the safts are not turning Can somebody help me...

Got my counter finally working, but...
I finally got my counter working in my nested function, but now I can't get the output from the function to work with the counter. The code for the counter is below: function plotpoint(hObject,eventdata) handles = guidata(gcf); point = get(gca,'CurrentPoint'); x = point(1,1); y = point(1,2); hSymb = line(x,y,'Marker','o','Color','r'); xl = get(gco,'XData'); yl = get(gco,'YData'); if sum(isfinite(xl))==1 fin = find(isfinite(xl)); xv = xl(fin); yv = yl(fin); else %Normalize axes xlmin = min(xl); xlmax = max(xl);...

Please Help, Counter not work.
Hi All, I use ARM7, LPC2138. I write short code for COUNTER1 that capture on PO.21 (CAP1.3). But not work, T1TC = 0 all time. What is wrong ?. My code, main () { while (1) { PINSEL1 |= 0xC00; // P0.21 = CAP1.3 T1TCR = 0; // T1 Stop. T1IR = 0; // Disable all INT. T1CCR = 0x200; // CAP1.3 on rising edge. T1CTCR = 0xD; // Timer 1 as counter on rising edge. T1TCR = 1; // T1 Start } } Thanks in advance, YoD ...

verilog source code/ fsm for "divide by n counter"
Hello, I am looking for verilog source code/ fsm for "divide by n counter "(I did google search and I was not able to get the right links). Can anybody please help me? Thanks S45 wrote: > Hello, > > I am looking for verilog source code/ fsm for "divide by n counter "(I > did google search and I was not able to get the right links). Can > anybody please help me? > > Thanks You might as well be asking "how do I write a paragraph?" Your search is for such an extremely basic piece of code that the first method should b...

Counter-Strike won't work with 9.0.17
Odd problem. When trying to connect to an internet server in CS running on wine 9.0.17 I get the error "Your version does not match the servers. Please restart game". (Just to clarify, it is CS itself that throws this error) I also tried Team Fortress Classic with the same result. I can create a local game server without a problem, but can't connect to any internet game. Downgraded to wine 9.0.16 and everything works again. Anyone else encountered this problem? Mercury <nobody@nospam.null> wrote: > Odd problem. When trying to connect to an internet ...

Microsoft XP counter killer-app doesn't work on XP
To support Microsoft's "Retiring Windows XP" campaign: http://windowsteamblog.com/windows/b/springboard/archive/2011/07/11/with-only-1000-days-left-of-extended-support-don-t-you-think-it-s-time-to-retire-windows-xp.aspx http://tinyurl.com/6klzeqw Vole released a "brilliant" killer-app´┐Ż to the public, called the "Windows XP End of Support Countdown Gadget". https://www.microsoft.com/download/en/details.aspx?id=11662 http://tinyurl.com/66hdrs8 The goal of this Countdown Gadget is to remind people when Windows XP reaches End Of Life. The only problem is....

[News] GNU/Linux for 57,000 Operation Counters, 70,000 Working Places
Russian Red Hat Test Could Reach 57k ,----[ Quote ] | Linux, which continues to challenge Microsoft, is proving popular with many | large businesses. The present testing phase is expected to last from 2-3 | months. Russian Post says it hopes to install the new software in 57 thousand | operation counters and 70 thousand working places in over 42 thousand post | offices. `---- http://www.hellmail.co.uk/postalnews/templates/postal_global_news.asp?articleid=522&zoneid=11 Russian Post migrates to Linux for losses ,----[ Quote ] | Meanwhile, he told CNews, it was too early to speak ...

does work
Hi there! Thanks for your solution. I've noticed that Matlab is doing some weird things as "dx", the smallest difference between two levels, decreases. Can someone please help me to avoid this issue and maybe explain to me, why it occurs? my levels are: levels = 1.0e+003 * 0.0010 0.0032 0.0100 0.0316 0.1000 0.3162 1.0000 As you can see, dx is 2.2 here. (length(cmap2) is always = 1000/dx) I've uploaded some pictures for various manually changed dxs here: http://img580.imageshack.us/img580/4315/dx1.png Can anyone please help me? this was meant to be...

It works! It works!
Hey folks, Remember I posted some queries a while back about doing manipulations on directory trees and how tricky it was to keep everything consistent? Well, I've got a basic implementation up and running, and I'm proud to say that it works wonderfully. For those that are curious (Mr French?), I might divulge a bit about how it works :-) Many thanks for the help you folks have given me. I'll probably have a few more queries in the fairly near future, but it's great to get something up and running :-) MH. On Wed, 14 Jan 2004 02:16:31 +0000, "Martin Harve...

Module should not work, but works
Hello, This is a file named p.pl: #!/usr/bin/perl use strict; use warnings; use lib '/path/to/mm_e.pm/'; use mm_e; mm::printok(); printok(); sub printok { print "ok from p.pl\n"; } This is a file named mm_e.pm: package mm; sub printok { print "ok from mm_e.pm\n"; } 1; Result: % perl -w p.pl ok from mm_e.pm ok from p.pl % Why does this work fine ? Shouldn't "strict" or "warnings" give me at least an error about this kind of construction ? I 'm on perl 5.8.3 built for i386-freebsd. -- Bart Bart Van der D...

getimagesize() working and *not*working... why?
(as first - thank you for all your help several years ago, and second - please apologise me for my clumsy enlgish) so, preface: some users on my photo related site sometimes enter (link) giant photo in their post or coment, and while I was writting new bbcode for my forum, I have got idea to check size of linked pictures to scale them down if needed (matamethic of that part isn't written in folowing code and would not be a problem). and now, the problem: function getimagesize() worked fine while getting data from my other domains on same server, I tested it with some from other servers a...

getMethod() works and works not
Hi all, can anybody explain why the getMethod() call (in the line commented with "???" below) throws a NoSuchMethodException? Perhaps I'm doing something obvious wrong, but I couldn't find any hint. ################################################################ import javax.swing.*; import java.lang.reflect.*; public class F { public static void main(String[] args) throws Exception { JFrame frame = new JFrame("Title"); JPanel panel = (JPanel)frame.getContentPane(); JTextArea area = new JTextArea(10, 40); Method method...

BEGIN WORK
We have IDS 9.40. I am trying to put a lock on the order based on the certain criteria(order source) When the order is created with that criteria, it inserts the order id in ord_track table. Then periodically a procedure is called and it is supposed to update the status of the order to on hold and then delete that record so next time is not put again on hold for a second time. The update and delete actions are supposed to work together. If update fails the delete should fail too. So when I created the stored procedure, I created it within a transaction block with BEGIN WORK a...

mail working, not working.
In homage to Twane, I have a problem. This code does not work (mail returns true, but the mail is not received):-------------------------------------------- // mail notification to office $userx = urlencode($user); $emailTo = "office@example.com, william@example.com"; $message = "A new user registered. "; $subject = "A new user registered: $userx"; $headers = <<<END From:office@example.com\n END; mail($emailTo,$subject,$message,$headers); ----------------------------------------------------------- whereas this code does w...

RegSvr32 working but not working
This is a multi-part message in MIME format. --------------070208080805010909020909 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit G'day everyone, This is a weird one: I have a COM DLL that I wrote using ActiveState's Perl Developers Kit. It compiles okay. RegSvr32 says that it has registered it. But the object is not available to any user or application, and hunting through the registry on object name or on the various UIDs reveals that the object hasn't been registered .. at all. Has anyone encountered anything like...

commit work not working?
IDS 9.40.HC3 on HP-UX 11i (B.11.11) server We are having a strange situation with begin/commit work, the commit is taking place even though an error occurs between the begin & commit statements. We have a begin work then a load followed by an insert then the commit work. The load has a duplicate key error, but the second insert is being committed. So looks something like this in pseudo code Begin work; load from fname insert tableA; insert tableB; Commit work; The developer was expecting that when the insert into tableA failed because of the duplicate key the inse...