Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > State machine incrementing

Reply
Thread Tools

State machine incrementing

 
 
zooplibob@gmail.com
Guest
Posts: n/a
 
      03-13-2009
I have the following code in my state machine for an I2C controller.
Basically when I get to state data_out4, I want to increment the
variable "datacount" by 1. However I stay in that state for many clock
cycles and it increments many times. How can I code it so that it
increments the variable only once when I'm in that state? Thanks

elsif state = data_out1 then
sda_sig <= 'Z';
scl_sig <= '0';
elsif state = data_out2 then
if data_out(7-datacount) = '0' then
sda_sig <= '0';
else
sda_sig <= 'Z';
end if;
scl_sig <= '0';
elsif state = data_out3 then
if data_out(7-datacount) = '0' then
sda_sig <= '0';
else
sda_sig <= 'Z';
end if;
scl_sig <= '1';
elsif state = data_out4 then
if data_out(7-datacount) = '0' then
sda_sig <= '0';
else
sda_sig <= 'Z';
end if;
scl_sig <= '0';
datacount:=datacount+1;
 
Reply With Quote
 
 
 
 
Jeff
Guest
Posts: n/a
 
      03-13-2009
Its interesting that it simulates correctly in the Xilinx simulator,
but when running on the CPLD, it increments as fast as possible.
I think this is more of a synthesis problem, because I could just
expand those lines instead of using the variable "datacount" hardcode
it from 0 to 7 and just copy and paste the whole thing 7 times, but it
seems like I should be able to write it like this and have it
synthesize properly
 
Reply With Quote
 
 
 
 
KJ
Guest
Posts: n/a
 
      03-14-2009

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have the following code in my state machine for an I2C controller.
> Basically when I get to state data_out4, I want to increment the
> variable "datacount" by 1. However I stay in that state for many clock
> cycles and it increments many times. How can I code it so that it
> increments the variable only once when I'm in that state? Thanks
>


1. Use a synchronous process
process(Clock)
begin
if rising_edge(Clock) then
... -- Put your code here
end if;
end process;

2. Synchronize all inputs the the clock before using
3. Simulate
4. Perform static timing analysis

Kevin Jennings


 
Reply With Quote
 
Ukanbal Ukanbal is offline
Junior Member
Join Date: Mar 2009
Posts: 9
 
      03-15-2009
Kevin,

I don't think synchronizing it with a clock will work. His problem is that he stays inside the 4th state for more then 1 clock cycle and as long as he is in there he doesn't want more than 1 increment to occur.

I am not sure if my solution is going to work or not but give this a try.
First create a 1 bit signal and set it to '1' in all the other states and when it comes to state 4 before the increment check that signal with an if statement. This way unless it goes into another state the newsignal that u set will stay as 0 and there wont be any increments


elsif state = data_out1 then
sda_sig <= 'Z';
scl_sig <= '0';
NEWSIGNAL <= '1';
elsif state = data_out2 then
if data_out(7-datacount) = '0' then
sda_sig <= '0';
else
sda_sig <= 'Z';
end if;
scl_sig <= '0';
NEWSIGNAL <= '1'
elsif state = data_out3 then
if data_out(7-datacount) = '0' then
sda_sig <= '0';
else
sda_sig <= 'Z';
end if;
scl_sig <= '1';
NEWSIGNAL <= '1'
elsif state = data_out4 then
if data_out(7-datacount) = '0' then
sda_sig <= '0';
else
sda_sig <= 'Z';
end if;
scl_sig <= '0';

if NEWSIGNAL = '1' THEN
datacount:=datacount+1;
NEWSIGNAL <= '0';

I hope this helps,

Ugur KANBAL
 

Last edited by Ukanbal; 03-15-2009 at 09:32 PM..
Reply With Quote
 
 
 
Reply

Thread Tools

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
State machine - Vending machine - strange behaviour fenster VHDL 3 12-23-2011 09:53 AM
How to print a state flow graph for a state machine using Xilinx ISE or ModelSim Weng Tianxiang VHDL 3 07-25-2006 01:19 PM
What is the state of state machine after power-up without reset conditions Weng Tianxiang VHDL 7 11-25-2003 06:24 PM
State machine: how to stay in a state? David Lamb VHDL 1 09-15-2003 05:24 PM



Advertisments