![]() |
|
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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 |
|
|
|
#3 |
|
Posts: n/a
|
<> 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 |
|
|
|
#4 |
|
Junior Member
Join Date: Mar 2009
Posts: 9
|
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. |
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |