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

Reply

VHDL - Sequential Machines

 
Thread Tools Search this Thread
Old 10-28-2004, 07:13 PM   #1
Default Sequential Machines


Hello,

I have basic questions regarding sequential machines

Q.1: Is the following way is the right way to define sequential
machine?

signal State : unsigned(7 downto 0);
signal nextstate : unsigned(7 downto 0);
constant E0 : unsigned(7 downto 0):="00000000";
constant E1 : unsigned(7 downto 0):="00000001";
constant E2 : unsigned(7 downto 0):="00000010";
constant E3 : unsigned(7 downto 0):="00000011";

Process (State,nextstate)
Begin

Case State is


When E0=>
..............
nextstate<=E1;

When E1=>
...............
nextstate<=E2;


When E2 =>
...............
nextstate<=E3;
When E3=>

................
nextstate<=E0;

When others =>
nextstate <= E0;
End case;
End Process;

Process (DPR_CLK,State,nextstate)
Begin

If (CLK'event And CLK='1') Then

State <= nextstate;
End If;
End Process;
End DPR_ARCH;

------------------------------------------------------------------------------

Q.2: some times the sequential mahine loose its direction. like state
E0 to E2,
What would be the solution?

Q.3: And whats the difference between
When others =>

nextstate <= E0;

AND
When others =>

nextstate <= NULL;

When we power up the CPLD, then by default the cpld goes to the state
E0, if
we use
When others =>

nextstate <= E0;
or the state machine will never run if we use

When others =>

nextstate <= NULL;
Please adivce me that I am right or wrong?
------------------------------------------------------------------------------

Q.3 Is sequential machine is the only best way to generate the cycles
for reading and
writing the Memory or is there an another way to do it?


john
  Reply With Quote
Old 10-28-2004, 10:00 PM   #2
rickman
 
Posts: n/a
Default Re: Sequential Machines
john wrote:
>
> Hello,
>
> I have basic questions regarding sequential machines
>
> Q.1: Is the following way is the right way to define sequential
> machine?


There are many ways to implement a FSM (Finite State Machine). This one
is fine. But why do you only have four states, but use an 8 bit vector
to indicate state?


> signal State : unsigned(7 downto 0);
> signal nextstate : unsigned(7 downto 0);
> constant E0 : unsigned(7 downto 0):="00000000";
> constant E1 : unsigned(7 downto 0):="00000001";
> constant E2 : unsigned(7 downto 0):="00000010";
> constant E3 : unsigned(7 downto 0):="00000011";
>
> Process (State,nextstate)
> Begin
>
> Case State is
>
>
> When E0=>
> ..............
> nextstate<=E1;
>
> When E1=>
> ...............
> nextstate<=E2;
>
>
> When E2 =>
> ...............
> nextstate<=E3;
> When E3=>
>
> ................
> nextstate<=E0;
>
> When others =>
> nextstate <= E0;
> End case;
> End Process;
>
> Process (DPR_CLK,State,nextstate)
> Begin
>
> If (CLK'event And CLK='1') Then
>
> State <= nextstate;
> End If;
> End Process;
> End DPR_ARCH;
>
> ------------------------------------------------------------------------------
>
> Q.2: some times the sequential mahine loose its direction. like state
> E0 to E2,
> What would be the solution?


The code looks ok, so I would suspect some hardware issues. Do you have
clean power, clean clock. What board is this on? Does it work
correctly in simulation?


> Q.3: And whats the difference between
> When others =>
>
> nextstate <= E0;
>
> AND
> When others =>
>
> nextstate <= NULL;


This is not valid code unless you have defined NULL to be an 8 bit SLV
constant. You mean...

When others =>
NULL;

This is like saying NOP. The compiler will interpret that as hold the
previous state which will infer a latch separate from the register you
are inferring in the clocked process. I don't think that is what you
want. This is also true if you fail to account for all the posible
synthesizable states of your signal. That means you don't have to
consider X's and U's, etc, but you have to consider all possible
combination of 1's and 0's.


> When we power up the CPLD, then by default the cpld goes to the state
> E0, if
> we use
> When others =>
>
> nextstate <= E0;


No, it can power up in state E1 and then procede through E2 and E3
before getting to state E0. You may not care, but the point is that you
are not resetting to state E0. Even if it reaches E0 after one clock
cycle, it first had to start in an invalid state on power up. To
initialize to a specified state, you need to add a reset signal of some
sort or specify an initial state. How to do this depends on your
tools.


> or the state machine will never run if we use
>
> When others =>
>
> nextstate <= NULL;
> Please adivce me that I am right or wrong?


Again, this will create a latch from your process with the case
statement. And it will lock up in the invalid state.

> ------------------------------------------------------------------------------
>
> Q.3 Is sequential machine is the only best way to generate the cycles
> for reading and
> writing the Memory or is there an another way to do it?


This FSM is just a counter. Why not use a counter?

--

Rick "rickman" Collins


Ignore the reply address. To email me use the above address with the XY
removed.

Arius - A Signal Processing Solutions Company
Specializing in DSP and FPGA design URL http://www.arius.com
4 King Ave 301-682-7772 Voice
Frederick, MD 21701-3110 301-682-7666 FAX


rickman
  Reply With Quote
Old 10-29-2004, 07:27 AM   #3
thomas
 
Posts: n/a
Default Re: Sequential Machines
rickman wrote:
> john wrote:
>
>>Hello,
>>
>>I have basic questions regarding sequential machines
>>
>>Q.1: Is the following way is the right way to define sequential
>>machine?

>
>
> There are many ways to implement a FSM (Finite State Machine). This one
> is fine. But why do you only have four states, but use an 8 bit vector
> to indicate state?
>
>
>
>>signal State : unsigned(7 downto 0);
>>signal nextstate : unsigned(7 downto 0);
>>constant E0 : unsigned(7 downto 0):="00000000";
>>constant E1 : unsigned(7 downto 0):="00000001";
>>constant E2 : unsigned(7 downto 0):="00000010";
>>constant E3 : unsigned(7 downto 0):="00000011";
>>
>>Process (State,nextstate)
>>Begin
>>
>> Case State is
>>
>>
>> When E0=>
>> ..............
>> nextstate<=E1;
>>
>> When E1=>
>> ...............
>> nextstate<=E2;
>>
>>
>> When E2 =>
>> ...............
>> nextstate<=E3;
>> When E3=>
>>
>> ................
>> nextstate<=E0;
>>
>> When others =>
>> nextstate <= E0;
>> End case;
>>End Process;
>>
>>Process (DPR_CLK,State,nextstate)
>>Begin
>>
>>If (CLK'event And CLK='1') Then
>>
>> State <= nextstate;
>>End If;
>>End Process;
>>End DPR_ARCH;
>>
>>------------------------------------------------------------------------------
>>
>>Q.2: some times the sequential mahine loose its direction. like state
>>E0 to E2,
>>What would be the solution?

>
>
> The code looks ok, so I would suspect some hardware issues. Do you have
> clean power, clean clock. What board is this on? Does it work
> correctly in simulation?
>
>
>
>>Q.3: And whats the difference between
>> When others =>
>>
>> nextstate <= E0;
>>
>> AND
>> When others =>
>>
>> nextstate <= NULL;

>
>
> This is not valid code unless you have defined NULL to be an 8 bit SLV
> constant. You mean...
>
> When others =>
> NULL;
>
> This is like saying NOP. The compiler will interpret that as hold the
> previous state which will infer a latch separate from the register you
> are inferring in the clocked process. I don't think that is what you
> want. This is also true if you fail to account for all the posible
> synthesizable states of your signal. That means you don't have to
> consider X's and U's, etc, but you have to consider all possible
> combination of 1's and 0's.
>
>
>
>>When we power up the CPLD, then by default the cpld goes to the state
>>E0, if
>>we use
>> When others =>
>>
>> nextstate <= E0;

>
>
> No, it can power up in state E1 and then procede through E2 and E3
> before getting to state E0. You may not care, but the point is that you
> are not resetting to state E0. Even if it reaches E0 after one clock
> cycle, it first had to start in an invalid state on power up. To
> initialize to a specified state, you need to add a reset signal of some
> sort or specify an initial state. How to do this depends on your
> tools.
>
>
>
>>or the state machine will never run if we use
>>
>> When others =>
>>
>> nextstate <= NULL;
>>Please adivce me that I am right or wrong?

>
>
> Again, this will create a latch from your process with the case
> statement. And it will lock up in the invalid state.
>
>
>>------------------------------------------------------------------------------
>>
>>Q.3 Is sequential machine is the only best way to generate the cycles
>>for reading and
>>writing the Memory or is there an another way to do it?

>
>
> This FSM is just a counter. Why not use a counter?
>


you can also write it like this

http://toolbox.xilinx.com/docsan/xil...sim/vtex9.html


thomas
  Reply With Quote
Old 10-29-2004, 06:28 PM   #4
rickman
 
Posts: n/a
Default Re: Sequential Machines
thomas wrote:
>
> you can also write it like this
>
> http://toolbox.xilinx.com/docsan/xil...sim/vtex9.html


I noticed that this doc puts the FSM case statement into a clocked
process. This will work fine if you don't mind your output signals
being clocked (and therefor delayed). Otherwise it can be easier to use
a non-clocked process for the FSM case statement. Then you can define
outputs that depend on the current state and optionally the inputs
(Mealy vs. Moore). Of course the downside is that a non-clocked process
requires you to specify the *entire* sensitivity list!

--

Rick "rickman" Collins


Ignore the reply address. To email me use the above address with the XY
removed.

Arius - A Signal Processing Solutions Company
Specializing in DSP and FPGA design URL http://www.arius.com
4 King Ave 301-682-7772 Voice
Frederick, MD 21701-3110 301-682-7666 FAX


rickman
  Reply With Quote
Old 10-30-2004, 03:09 AM   #5
Mike Treseler
 
Posts: n/a
Default Re: Sequential Machines
rickman wrote:

> I noticed that this doc puts the FSM case statement into a clocked
> process. This will work fine if you don't mind your output signals
> being clocked (and therefor delayed).


Synchronized outputs may be worth the wait.

> Otherwise it can be easier to use
> a non-clocked process for the FSM case statement. Then you can define
> outputs that depend on the current state and optionally the inputs
> (Mealy vs. Moore). Of course the downside is that a non-clocked process
> requires you to specify the *entire* sensitivity list!


The other downside is that the outputs might glitch.

-- Mike Treseler


Mike Treseler
  Reply With Quote
Old 11-04-2004, 07:43 PM   #6
john
 
Posts: n/a
Default Re: Sequential Machines
Hello,
I did not understand which document you are reffering! would you
please clear your point...

Thanks
Regards
jim

rickman <> wrote in message
news:<>...
> thomas wrote:
> >
> > you can also write it like this
> >
> > http://toolbox.xilinx.com/docsan/xil...sim/vtex9.html

>
> I noticed that this doc puts the FSM case statement into a clocked
> process. This will work fine if you don't mind your output signals
> being clocked (and therefor delayed). Otherwise it can be easier to use
> a non-clocked process for the FSM case statement. Then you can define
> outputs that depend on the current state and optionally the inputs
> (Mealy vs. Moore). Of course the downside is that a non-clocked process
> requires you to specify the *entire* sensitivity list!
>
> --
>
> Rick "rickman" Collins
>
>
> Ignore the reply address. To email me use the above address with the XY
> removed.
>
> Arius - A Signal Processing Solutions Company
> Specializing in DSP and FPGA design URL http://www.arius.com
> 4 King Ave 301-682-7772 Voice
> Frederick, MD 21701-3110 301-682-7666 FAX



john
  Reply With Quote
Old 11-05-2004, 05:24 AM   #7
rickman
 
Posts: n/a
Default Re: Sequential Machines
john wrote:
>
> Hello,
> I did not understand which document you are reffering! would you
> please clear your point...
>
> Thanks
> Regards
> jim
>
> rickman <> wrote in message
> news:<>...
> > thomas wrote:
> > >
> > > you can also write it like this
> > >
> > > http://toolbox.xilinx.com/docsan/xil...sim/vtex9.html

> >
> > I noticed that this doc puts the FSM case statement into a clocked
> > process. This will work fine if you don't mind your output signals
> > being clocked (and therefor delayed). Otherwise it can be easier to use
> > a non-clocked process for the FSM case statement. Then you can define
> > outputs that depend on the current state and optionally the inputs
> > (Mealy vs. Moore). Of course the downside is that a non-clocked process
> > requires you to specify the *entire* sensitivity list!


This took me awhile to find what you were unclear about. I see now that
the example uses a non-clocked process for the next state and output
specifications. The style of formatting did not make it clear where one
process began and the other left off. I use more white space in such
cases and I did not see the start of the combinatorial process.

--

Rick "rickman" Collins


Ignore the reply address. To email me use the above address with the XY
removed.

Arius - A Signal Processing Solutions Company
Specializing in DSP and FPGA design URL http://www.arius.com
4 King Ave 301-682-7772 Voice
Frederick, MD 21701-3110 301-682-7666 FAX


rickman
  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
How to set another machine's environment variable? vinay.babu Software 0 10-16-2008 12:54 PM
networking wireless xp machines roknight General Help Related Topics 0 06-18-2008 09:44 PM
Using BRAM in state machines zoki111 Hardware 0 09-18-2007 09:38 AM
As growth slows, Hollywood faces a DVD standoff. Allan DVD Video 0 07-11-2005 02:10 PM
Field Sequential DVD Question moviemaniac2003@hotmail.com DVD Video 0 06-07-2005 09:20 PM




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