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 difficulties

 
Thread Tools Search this Thread
Old 11-05-2006, 07:24 PM   #1
Default State machine difficulties


Hello all,

I'm having difficulties with the code below on my Spartan 3.

I've created an 8-bit RAM with 256 locations. It has the following
inputs:
wr_en
addr
data_in

My goal is to write the numbers 1 - 4 to addresses 1 - 4 of the RAM
(and then read them back).

In the code below, I never get out of the state SETUP_WRITE. I have a
feeling this has something to do with the way I'm using variables (as
opposed to signals), but I just don't see what I'm doing wrong.

In the code below, data_out is tied to some LEDs on my board.

Thanks,
Dave

seq: process(clk)
begin
if (rising_edge(clk)) then
if (reset = '1') then
current_state <= INIT;
else
current_state <= next_state;
end if;
end if;
end process seq;

comb: process(current_state)
variable addr_to_write: natural;
begin
case current_state is
when INIT =>
addr_to_write := 1;
next_state <= SETUP_WRITE;
when SETUP_WRITE =>
wr_en <= '1';
addr <= addr_to_write;
data_in <= std_logic_vector(to_unsigned(addr_to_write, );
addr_to_write := addr_to_write + 1;

if (addr_to_write /= 5) then
next_state <= SETUP_WRITE;
else
next_state <= READ_ADDR_1;
end if;
.
.
.



better_cs_now@yahoo.com
  Reply With Quote
Old 11-06-2006, 02:55 AM   #2
Mike Treseler
 
Posts: n/a
Default Re: State machine difficulties
wrote:

> My goal is to write the numbers 1 - 4 to addresses 1 - 4 of the RAM
> (and then read them back).


I would do this using simulation, not synthesis.
The problem with designing another hardware
entity to test the ram is that it needs
to be debugged and verified as well.

If you just want to see something on the
scope, instance an UP counter and wire
wr_en to the count LSB Q0,
then data_in to Q1-8, then addr to Q9-17

-- Mike Treseler


Mike Treseler
  Reply With Quote
Old 11-07-2006, 12:06 PM   #3
jmaniac
 
Posts: n/a
Default Re: State machine difficulties


> comb: process(current_state)
> variable addr_to_write: natural;
> begin
> case current_state is
> when INIT =>
> addr_to_write := 1;
> next_state <= SETUP_WRITE;
> when SETUP_WRITE =>
> wr_en <= '1';
> addr <= addr_to_write;
> data_in <= std_logic_vector(to_unsigned(addr_to_write, );
> addr_to_write := addr_to_write + 1;
>
> if (addr_to_write /= 5) then
> next_state <= SETUP_WRITE;
> else
> next_state <= READ_ADDR_1;
> end if;



Hey.. check up your sensitivity list in the combination logic... I
guess the sensitvity never trigers once it enters SETUP_WRITE state



jmaniac
  Reply With Quote
Old 11-10-2006, 12:09 PM   #4
Al
 
Posts: n/a
Default Re: State machine difficulties


wrote:
> comb: process(current_state)
> variable addr_to_write: natural;
> begin
> case current_state is
> when INIT =>
> addr_to_write := 1;
> next_state <= SETUP_WRITE;
> when SETUP_WRITE =>
> wr_en <= '1';
> addr <= addr_to_write;
> data_in <= std_logic_vector(to_unsigned(addr_to_write, );
> addr_to_write := addr_to_write + 1;
>
> if (addr_to_write /= 5) then
> next_state <= SETUP_WRITE;
> else
> next_state <= READ_ADDR_1;
> end if;


I think the problem sits on the fact that addr_to_write is inside a
combinational process. Have you tried to simulate the code and check the
behaviour of this variable? To me it will be inferred as a latch rolling
up to the 5, at that point the next_state will go to READ_ADDR_1.
Then you better check the RAM timing specifications, I don't really
understand if changing the addr and data_in when wr_en is active is a
correct way of writing into a ram (but I don't know much of Spartan 3 so
I may be wrong).

Either you include all in a one-process FSM, or you'll have to change
approach moving the addr and the data_in out of the combinational
process and handling them as counters in a sequential one.

Good luck

Al

--
Alessandro Basili
CERN, PH/UGC
Hardware Designer


Al
  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