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

Reply

VHDL - latches again

 
Thread Tools Search this Thread
Old 05-06-2005, 02:35 PM   #1
Default latches again


Hi,

I'm implementing a very simple memory with serial input in vhdl.

The serial bus I use is a simple SPI: I first receive the instruction
(read,write,erase) then the address then I send/receive data.

But I'm having some latches warning I would like to remove.

I'm using a FSM to model the memory, here is part of the code:


FSM: process (STATE)
variable TMP_RECV_INST:std_logic_vector(7 downto 0);
variable TMP_RECV_ADDR:std_logic_vector(15 downto 0);
variable TMP_RECV_DATA:std_logic_vector(7 downto 0);

begin
NEXTSTATE<=STATE;
case STATE is
when FS_RECV_INST => if curr_indx/=inst_length-1 then
TMP_RECV_INST(curr_indx):=SI; -- SI is the serial input
curr_indx:=curr_indx+1;
NEXTSTATE<=FS_RECV_INST;
else
curr_indx:=0;
NEXTSTATE<=FS_RECV_ADDR;
end if ;
SO<='Z';
when FS_RECV_ADDR => if curr_indx/=addr_length then
and so on

I'm getting a 1-bit latches warning on each tmp_recv_inst index
(because I'm probably changing only 1 bit at a time?). I even tried to
put TMP_RECV_INST(curr_indx):=SI; before the beginning of the if
clause just to test and see if the problem was that tmp_recv_inst
wasn't assigned in both if and else blocks. But the warning was still
there.

The only way I could think about to avoid this latches warning is
this:

change
variable TMP_RECV_INST:std_logic_vector(7 downto 0); to variable
tmp_recv_inst: integer range 0 to 2**7;

and instead of TMP_RECV_INST(curr_indx):=SI; use
tmp_recv_inst=tmp_recv_inst+2**curr_indx;

I'm a real VHDL beginner so I don't know if this *workaround* is
usable and what are the pros and cons.

Thanks for help,
Tomas


Tomas
  Reply With Quote
Old 05-06-2005, 03:09 PM   #2
Ralf Hildebrandt
 
Posts: n/a
Default Re: latches again
Tomas wrote:

> But I'm having some latches warning I would like to remove.


Ask yourself:
Does the target architecture support latches?
Does your guidelines for this project allow to use latches?
Did you model a latch?

> ...
> I'm getting a 1-bit latches warning on each tmp_recv_inst index
> (because I'm probably changing only 1 bit at a time?).


No. A latch is

process(enable)
begin
if (enable='1') then
my_latch<=my_input;
end if;
end process;

In contrast if you model pure combinational logic the signal you write
to has to be assigned a value in every case e.g.

process(enable)
begin
if (enable='1') then
my_output<=my_input;
else
my_output<='0';
end if;
end process;

This means: Somewhere in your case statement there is (at least) one
case of choice, that is not covered.
A latch warning is given by some synthesis tools, because you may have
forgotten one case of choice and the combinational logic you wanted to
bodel became a latch.


> The only way I could think about to avoid this latches warning is
> this:
> ...
> I'm a real VHDL beginner so I don't know if this *workaround* is
> usable and what are the pros and cons.


Do not "avoid latch waningings". Threat them as
* eigther an error report, because there is a latch where no latch was
modeled
* or as a not-so-useful information that there is a latch where you did
model one

Try to model hardware with VHDL - do not "program VHDL". You should know
everytime what will be inferred. This is not hard, because there are
only 3 choices: combinational logic, latch or flipflop.



And last of all: Latches are really nice, but hard to implement because
of some problems that arise while using them (e.g. muxed latch problem).
In most cases a fully synchronous design is preferrable (only comb.
logic and flipflops).

Ralf


Ralf Hildebrandt
  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




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