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

Reply

VHDL - Help: what does this VHDL code mean?

 
Thread Tools Search this Thread
Old 06-22-2005, 03:24 AM   #1
Default Help: what does this VHDL code mean?


process(clock) is
begin
if clock'event and clock = '1'
then
o <= '1';
if (<some conditional>)
then
o <= '0';
end if;
end if;
end process;

My question is how to interpret this: is the value of o is first set to
'1' and then set to '0' or is it that o is set to '0' or '1' depending on
whether the condition is true. Is it a good VHDL coding style? If so, why
don't I see a single example/explanation of it in Peter Ashendon's book?
Thanks in advance.

- Pratip.


Pratip Mukherjee
  Reply With Quote
Old 06-22-2005, 03:59 AM   #2
newsgroup
 
Posts: n/a
Default Re: what does this VHDL code mean?
Hi Pratip,

The code will infer a mux and a flip flop.
For all cases in which <condition> is true output will be zero else one.

There is nothing wrong in this coding style, except for readability and
straightforwardness. It is equivalent to this code.
process(clock) is
begin
if clock'event and clock = '1' then
if (<some conditional>) then
o <= '0';
else
o <= '1' ;
end if;
end if;
end process;



"Pratip Mukherjee" <> wrote in message
news:062dner0G_B2ViXfRVn-...
> process(clock) is
> begin
> if clock'event and clock = '1'
> then
> o <= '1';
> if (<some conditional>)
> then
> o <= '0';
> end if;
> end if;
> end process;
>
> My question is how to interpret this: is the value of o is first set to
> '1' and then set to '0' or is it that o is set to '0' or '1' depending on
> whether the condition is true. Is it a good VHDL coding style? If so, why
> don't I see a single example/explanation of it in Peter Ashendon's book?
> Thanks in advance.
>
> - Pratip.





newsgroup
  Reply With Quote
Old 06-22-2005, 05:52 AM   #3
Neo
 
Posts: n/a
Default Re: what does this VHDL code mean?
More probably it will infer an NOT of condition to the 'd' input of
the FF.



Neo
  Reply With Quote
Old 06-22-2005, 08:25 AM   #4
Klaus Falser
 
Posts: n/a
Default Re: Help: what does this VHDL code mean?
In article <062dner0G_B2ViXfRVn->,
says...
> process(clock) is
> begin
> if clock'event and clock = '1'
> then
> o <= '1';
> if (<some conditional>)
> then
> o <= '0';
> end if;
> end if;
> end process;
>
> My question is how to interpret this: is the value of o is first set to
> '1' and then set to '0' or is it that o is set to '0' or '1' depending on
> whether the condition is true. Is it a good VHDL coding style? If so, why
> don't I see a single example/explanation of it in Peter Ashendon's book?
> Thanks in advance.
>
> - Pratip.
>


This coding style is less useful together with an if statement,
but very useful in conjunction with a case statement
(when programming FSM's).

It allows you to assign a default value and set your output
signal only under certain conditions.

In the following example you have a output_enable signal
which must always be '0', exept when writing.

process(clock) is
begin
if rising_edge(clock) then
output_enable <= '0';
case (state) is
when idle =>
<do nothing, output_enable remains at '0'>
when writing =>
output_enable <= '1';
when reading =>
<something else, output_enable remains at '0'>
when someOtherState =>
<something else too, output_enable remains at '0'>
end case;
end if;
end process;

Without this style you had to assign a value for "output_enable"
in all states, blowing up your code.

The signal output_enable itself is NOT set first to '0' and
then to '1' when then when writing, but is set cleanly to '0'
or '1'.

Remember, in VHDL the new values for the signals are assigned
only at the end of the simulation cycle.
During the calculation of the new value for the signal there is an
intermediate result of '0', evenually replaced by '1' when we are
in the writing state, but the signal itself gets only the RESULT of
the calculus.

Best regards
Klaus Falser


Klaus Falser
  Reply With Quote
Old 06-22-2005, 09:53 AM   #5
fred
 
Posts: n/a
Default Re: Help: what does this VHDL code mean?
In article <>, Klaus Falser
<> writes
>In article <062dner0G_B2ViXfRVn->,
>says...
>> process(clock) is
>> begin
>> if clock'event and clock = '1'
>> then
>> o <= '1';
>> if (<some conditional>)
>> then
>> o <= '0';
>> end if;
>> end if;
>> end process;
>>
>> My question is how to interpret this: is the value of o is first set to
>> '1' and then set to '0' or is it that o is set to '0' or '1' depending on
>> whether the condition is true. Is it a good VHDL coding style? If so, why
>> don't I see a single example/explanation of it in Peter Ashendon's book?

Maybe he doesn't think it is a good way to code, I would agree with him.
>
>This coding style is less useful together with an if statement,
>but very useful in conjunction with a case statement
>(when programming FSM's).

IMO, dirty programming

>It allows you to assign a default value and set your output
>signal only under certain conditions.
>
>In the following example you have a output_enable signal
>which must always be '0', exept when writing.
>
>process(clock) is
>begin
> if rising_edge(clock) then
> output_enable <= '0';
> case (state) is
> when idle =>
> <do nothing, output_enable remains at '0'>
> when writing =>
> output_enable <= '1';
> when reading =>
> <something else, output_enable remains at '0'>
> when someOtherState =>
> <something else too, output_enable remains at '0'>
> end case;
> end if;
>end process;
>
>Without this style you had to assign a value for "output_enable"
>in all states, blowing up your code.

Any reason for not covering this with:
when (others) =>
output_enable <= '0';
which I think is a far cleaner.

>Remember, in VHDL the new values for the signals are assigned
>only at the end of the simulation cycle.
>During the calculation of the new value for the signal there is an
>intermediate result of '0', evenually replaced by '1' when we are
>in the writing state, but the signal itself gets only the RESULT of
>the calculus.

But life (hardware) isn't a simulation, I'd rather write something that follows
the way hardware will actually perform (albeit at a high level) than make
use techniques like those above.
--
fred


fred
  Reply With Quote
Old 06-22-2005, 12:45 PM   #6
Kim Enkovaara
 
Posts: n/a
Default Re: Help: what does this VHDL code mean?
fred wrote:

>>Without this style you had to assign a value for "output_enable"
>>in all states, blowing up your code.

>
> Any reason for not covering this with:
> when (others) =>
> output_enable <= '0';
> which I think is a far cleaner.


That is different code at functional level, it should create latches.
In VHDL the case statements are mutually exclusive (1076-1993 8.8 Note 1).
So in your code the output_enable value comes from the previous round in
the undefined cases.

Setting the default value at the beginning and changing it inside
the case clauses makes the code easier to read in very complex state
machines. It's easier to see, what values are important. Also in very
deep if-clauses that style usually cuts down the needed else branches.


>>Remember, in VHDL the new values for the signals are assigned
>>only at the end of the simulation cycle.

>
> But life (hardware) isn't a simulation, I'd rather write something that follows
> the way hardware will actually perform (albeit at a high level) than make
> use techniques like those above.


Simulation follows hardware, if synthesis subset of the language is used.
Setting default value is normal way of doing this for synthesizable code.

--Kim


Kim Enkovaara
  Reply With Quote
Old 06-22-2005, 03:08 PM   #7
fred
 
Posts: n/a
Default Re: Help: what does this VHDL code mean?
In article <whcue.8035$7%>, Kim
Enkovaara <> writes
>fred wrote:
>
>>>Without this style you had to assign a value for "output_enable"
>>>in all states, blowing up your code.

>>
>> Any reason for not covering this with:
>> when (others) =>
>> output_enable <= '0';
>> which I think is a far cleaner.

>
>That is different code at functional level, it should create latches.

I disagree, a case is a decoder, the others term (the brackets were a
mistake btw) just fills in the empty slots, I see no latches.

>In VHDL the case statements are mutually exclusive (1076-1993 8.8 Note 1).
>So in your code the output_enable value comes from the previous round in
>the undefined cases.

Nope

>Setting the default value at the beginning and changing it inside
>the case clauses makes the code easier to read in very complex state
>machines. It's easier to see, what values are important. Also in very
>deep if-clauses that style usually cuts down the needed else branches.

From a real world hardware perspective I look upon this sort of thing as
multiple sources (even though in VHDL it is not) and so won't do it;
irrespective of whether tools 'know what I mean'.

>>>Remember, in VHDL the new values for the signals are assigned
>>>only at the end of the simulation cycle.

>>
>> But life (hardware) isn't a simulation, I'd rather write something that follows
>> the way hardware will actually perform (albeit at a high level) than make
>> use techniques like those above.

>
>Simulation follows hardware, if synthesis subset of the language is used.
>Setting default value is normal way of doing this for synthesizable code.

In hardware, the signal does not set to one level and then change to
another one (or how ever many) deltas later so in that way simulation does
not follow hardware.
--
fred


fred
  Reply With Quote
Old 06-22-2005, 03:30 PM   #8
Klaus Falser
 
Posts: n/a
Default Re: Help: what does this VHDL code mean?
In article <>, says...
> In article <>, Klaus Falser
> <> writes
> ...
> >Remember, in VHDL the new values for the signals are assigned
> >only at the end of the simulation cycle.
> >During the calculation of the new value for the signal there is an
> >intermediate result of '0', evenually replaced by '1' when we are
> >in the writing state, but the signal itself gets only the RESULT of
> >the calculus.

> But life (hardware) isn't a simulation, I'd rather write something that
> follows the way hardware will actually perform (albeit at a high level)
> than make use techniques like those above.
>


This has nothing to do with simulation vs. hardware but is the way VHDL
works.
VHDL is simply NOT a programming language, an assignment to a signal in
VHDL is something completely different from an assigning of a value to a
variable (they exist in VHDL too !).
Be assured, if written this way the hardware will do exactly the same as
the code says.

Best regards
Klaus Falser





Klaus Falser
  Reply With Quote
Old 06-22-2005, 03:45 PM   #9
fred
 
Posts: n/a
Default Re: Help: what does this VHDL code mean?
In article <>, Klaus Falser
<> writes
>In article <>, says...
>> In article <>, Klaus Falser
>> <> writes
>> ...
>> >Remember, in VHDL the new values for the signals are assigned
>> >only at the end of the simulation cycle.
>> >During the calculation of the new value for the signal there is an
>> >intermediate result of '0', evenually replaced by '1' when we are
>> >in the writing state, but the signal itself gets only the RESULT of
>> >the calculus.

>> But life (hardware) isn't a simulation, I'd rather write something that
>> follows the way hardware will actually perform (albeit at a high level)
>> than make use techniques like those above.
>>

>
>This has nothing to do with simulation vs. hardware but is the way VHDL
>works.
>VHDL is simply NOT a programming language, an assignment to a signal in
>VHDL is something completely different from an assigning of a value to a
>variable (they exist in VHDL too !).

Yes, I know

>Be assured, if written this way the hardware will do exactly the same as
>the code says.

I didn't say it wouldn't, I said that I thought it was dirty programming and
that I don't write my code that way, you do not have to agree with that.

--
fred


fred
  Reply With Quote
Old 06-22-2005, 03:59 PM   #10
Ben Jones
 
Posts: n/a
Default Re: Help: what does this VHDL code mean?
> VHDL is simply NOT a programming language

I respectfully disagree. Rather:

VHDL is not SIMPLY a programming language.

-Ben-




Ben Jones
  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
Phase locked loop VHDL code mreddy.a Hardware 0 09-16-2007 09:43 AM
VHDL code for SPI Master shah_satish2002 Hardware 2 07-22-2007 08:12 PM
Writing Register code in vhdl amirster Hardware 2 06-11-2007 03:22 PM
vhdl code amirster Hardware 0 05-10-2007 07:28 AM
VHDL code of odd parity checker shakeelsultan Hardware 0 10-27-2006 06:27 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