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

Reply

VHDL - signal and varriable assignment

 
Thread Tools Search this Thread
Old 05-21-2004, 12:35 PM   #1
Default signal and varriable assignment


Could any explain the following:

Synthesis of following code doesnot generate any component for var3, but
will the code generate a latch or flipflop for var1 and var2 ?

Deep

....
signal s1,s2,s3,s4 : std_logic;
begin
process(clk, rst)
variable var1, var2,var3,var4 : std_logic;

begin
if rst='1' then
var1:='0' ; var2:='0';
elsif(clk'event and clk='1') then

var1:=s1;
var2:=s2;
s3<= var1 xor var2;

var3:= s3 xor s4;
s4<=var3;


end if;

end process;
...




deep
  Reply With Quote
Old 05-21-2004, 02:35 PM   #2
Jonathan Bromley
 
Posts: n/a
Default Re: signal and varriable assignment
On Fri, 21 May 2004 07:35:21 -0400, "deep" <> wrote:

>Synthesis of following code doesnot generate any component for var3, but
>will the code generate a latch or flipflop for var1 and var2 ?
>...
> signal s1,s2,s3,s4 : std_logic;
>begin
>process(clk, rst)
> variable var1, var2,var3,var4 : std_logic;
>
> begin
> if rst='1' then
> var1:='0' ; var2:='0';
> elsif(clk'event and clk='1') then
>
> var1:=s1;
> var2:=s2;
> s3<= var1 xor var2;
>
> var3:= s3 xor s4;
> s4<=var3;
>
>
> end if;
>
> end process;


Why not try it? Is this homework, interview puzzle, a
simplified version of something you're working on, or
just something you imagined in a quiet moment???

First off, the code is very flaky anyway. s3 and s4
are clearly synthesised to flipflops, but they don't
appear in the "reset" branch of the process. That
implies they must have (not rst) as a clock enable.
Most synth tools will issue a warning, or even an
error, for this style problem.

The rules for flip-flop inference are quite simple
(although it can sometimes be tricky to apply them,
if the code is complicated). If there is ANY path of
execution of the process that requires you to USE the
value of a variable BEFORE you assign to it, then
of course you're picking up the value that was given
to the variable on the previous clock cycle and so it
must be stored in a flip-flop. If, however, there
is NO path through the process that uses the variable's
value before assigning to it, then the variable simply
represents some intermediate stage in the combinational
logic driving the D inputs of your clocked process's
flipflops, and the variable itself will not infer
a storage element.

The assignments to var1 and var2 in the reset branch
of the process seem to imply a latch, but the latched
values are never used within the process and therefore
the synthesis tool should recognise that no latch is
required - or, just possibly, give you a warning
message. If you see a latch, then go out and get
a synthesis tool that works.

That's it. Easy. It's very easy to apply these
rules to your piece of code.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.


Jonathan Bromley
  Reply With Quote
Old 05-22-2004, 05:54 AM   #3
deep
 
Posts: n/a
Default Re: signal and varriable assignment

Thanks Jonathan. I got your point.

regards,

deep



deep
  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