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

Reply

VHDL - State machine incrementing

 
Thread Tools Search this Thread
Old 03-13-2009, 11:06 PM   #1
Default State machine incrementing


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;


zooplibob@gmail.com
  Reply With Quote
Old 03-13-2009, 11:35 PM   #2
Jeff
 
Posts: n/a
Default Re: State machine incrementing
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


Jeff
  Reply With Quote
Old 03-14-2009, 12:50 AM   #3
KJ
 
Posts: n/a
Default Re: State machine incrementing

<> wrote in message
news:cfda7a27-6949-48a8-9fad-...
>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




KJ
  Reply With Quote
Old 03-15-2009, 09:29 PM   #4
Ukanbal
Junior Member
 
Join Date: Mar 2009
Posts: 9
Default
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


Ukanbal

Last edited by Ukanbal : 03-15-2009 at 09:32 PM.
Ukanbal is offline   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
combinational lock state machine harikanth General Help Related Topics 0 04-06-2009 05:38 AM
Using BRAM in state machines zoki111 Hardware 0 09-18-2007 09:38 AM
pcAnywhere and Brother fax machine on same phoen line bem522 Software 0 07-20-2007 04:20 PM
Judge: File-swapping tools are legal Citizen Bob DVD Video 140 11-08-2006 06:42 PM
BUSH WILL LIKELY INSTALL A DRAFT Jas DVD Video 165 10-20-2004 09:39 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