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

Reply

VHDL - Beyond Newbie Question

 
Thread Tools Search this Thread
Old 09-13-2007, 03:45 PM   #1
Default Beyond Newbie Question


I will not even consider myself a newbie in VHDL. I am trying to hack
someone else's code to do what I need it to do...which is trivial. I
am using Xilinx tools by the way.

I have a signal coming into a module:

USB_FIFODATA_I : std_logic_vector(31 downto 0);

All I want to do is make a trigger signal that asserts whenever that
input is NOT '0'.

So I have tried all the tricks I know (I don't know any tricks) and my
parser keeps giving me fits. Here's some examples of my stupidity:

trigger <= USB_FIFODATA_I /= '0';
trigger <= USB_FIFODATA_I(31 downto 0) /= '0';
trigger <= USB_FIFODATA_I /= "00000000000000000000000000000000";

Obviously, I don't know what I am doing. I have a book, but I can't
seem to find what I am looking for. Could someone please help me out
so I can debug what I need to!

Thanks!!



mottoblatto@yahoo.com
  Reply With Quote
Old 09-13-2007, 04:36 PM   #2
Ralf Hildebrandt
 
Posts: n/a
Default Re: Beyond Newbie Question
schrieb:

> trigger <= USB_FIFODATA_I /= '0';


use IEEE.numeric_std.all;

trigger<='1' when ( to_01(unsigned(USB_FIFODATA_I)) /= 0 ) else '0';

Conversion to unsigned is needed for the comparison. With Numeric_std an
integer can be compared to an unsigned vector. Comparison with an
integer value is independent of the bit width, but restricted to 32 bits.

The function to_01() is used to avoid comparisons of an integer with a
'X', 'Z', 'U' value, which occurs at least at the start of the
simulation. It is a way to suppress annoying warnings during simulation.


Note that trigger is a hazarderous signal!

Ralf


Ralf Hildebrandt
  Reply With Quote
Old 09-13-2007, 04:53 PM   #3
Paul Uiterlinden
 
Posts: n/a
Default Re: Beyond Newbie Question
wrote:

> I will not even consider myself a newbie in VHDL. I am trying to hack
> someone else's code to do what I need it to do...which is trivial. I
> am using Xilinx tools by the way.
>
> I have a signal coming into a module:
>
> USB_FIFODATA_I : std_logic_vector(31 downto 0);
>
> All I want to do is make a trigger signal that asserts whenever that
> input is NOT '0'.
>
> So I have tried all the tricks I know (I don't know any tricks) and my
> parser keeps giving me fits. Here's some examples of my stupidity:
>
> trigger <= USB_FIFODATA_I /= '0';
> trigger <= USB_FIFODATA_I(31 downto 0) /= '0';
> trigger <= USB_FIFODATA_I /= "00000000000000000000000000000000";
>
> Obviously, I don't know what I am doing. I have a book, but I can't
> seem to find what I am looking for. Could someone please help me out
> so I can debug what I need to!


The first two examples do not work because your are comparing an array
(std_logic_vector) with a scalar (std_logic).

The third example probably (you did not give the error message and the
declaration of trigger) does not work because you assign a boolean (the
result of the /= operator) to a signal of type std_logic. If signal trigger
was boolean, it would be correct.

As a side note: I do not like long strings such
as "00000000000000000000000000000000". Is it not one bit short/long? I
don't like counting bits.

More convenient is:
trigger <= USB_FIFODATA_I /= x"0000_0000";
This uses a hex bit-string literal, where each character represents four
bits. Underscores may be added to improve readability.

Or even:
trigger <= USB_FIFODATA_I /= (USB_FIFODATA_I'range => '0');
Now you don't need to count bits at all!

--
Paul Uiterlinden
www.aimvalley.nl
e-mail addres: remove the not.


Paul Uiterlinden
  Reply With Quote
Old 09-13-2007, 05:00 PM   #4
Shannon
 
Posts: n/a
Default Re: Beyond Newbie Question
On Sep 13, 8:36 am, Ralf Hildebrandt <Ralf-Hildebra...@gmx.de> wrote:
> Note that trigger is a hazarderous signal!
>
> Ralf


Can you explain why?

Shannon



Shannon
  Reply With Quote
Old 09-13-2007, 05:45 PM   #5
Ralf Hildebrandt
 
Posts: n/a
Default Re: Beyond Newbie Question
Shannon schrieb:

>> Note that trigger is a hazarderous signal!
>>
>> Ralf

>
> Can you explain why?


Ok maybe not in this particular case.
* The comparison with zero is a OR-operation over all bits, with should
not produce hazards.
* There is an even number of bits to compare with results in a
"symmetric OR-tree" during synthesis

But I guess the synthesis tool will not use OR gates. NORs and NANDs are
preferrable. Because the bit width is even and if there are 4-input NORs
and NADs in the target library this again will result in a symmetrical
tree with no hazards.
But what if the routing is not symmetrical or there are only 3-input
NORs and NADs? I guess it is safe to say that hazards /may/ occur.



And if USB_FIFODATA_I is hazarderous, then trigger is it too.

And if one changes the comparison to a different number other than zero,
one almost certainly gets an asymmetrical combinational tree which may
produce hazards.

Ralf


Ralf Hildebrandt
  Reply With Quote
Old 09-13-2007, 08:41 PM   #6
Andy
 
Posts: n/a
Default Re: Beyond Newbie Question
Along the lines of what Paul said, I _hate_ typing and counting
digits, and I prefer code that adapts automatically to changes (like
width of the vector, etc.)

The following example will also work (assume boolean trigger):

trigger <= unsigned(usb_fifodata) /= 0;

or with std_logic trigger (concurrent statement):

trigger <= '1' when unsigned(usb_fifodata) /= 0 else '0';

or (sequential statement):

if unsigned(usp_fifodata) /= 0 then
trigger <= '1';
else
trigger <= '0';
end if;

Andy



Andy
  Reply With Quote
Old 09-13-2007, 09:59 PM   #7
Paul Uiterlinden
 
Posts: n/a
Default Re: Beyond Newbie Question
Andy wrote:

> Along the lines of what Paul said, I _hate_ typing and counting
> digits, and I prefer code that adapts automatically to changes (like
> width of the vector, etc.)
>
> The following example will also work (assume boolean trigger):
>
> trigger <= unsigned(usb_fifodata) /= 0;
>
> or with std_logic trigger (concurrent statement):
>
> trigger <= '1' when unsigned(usb_fifodata) /= 0 else '0';


Expanding on that, I'm not so fond of this kind of selected signal
assignments. It gets even worse if it was a sequential statement (so in a
process):

if unsigned(usb_fifodata) /= 0 then
trigger <= '1';
else
trigger <= '0';
end if;

Too many words and (shudder!) repetition of the target name.

I like to use a function in those cases. This works equally well for
concurrent an sequential statements:

trigger <= bool2sl(unsigned(usb_fifodata) /= 0);

Where bool2sl is a function that comes out of a package with all this kind
of small but oh so handy subprograms:

function bool2sl(val: boolean) return std_ulogic is
begin
if val then
return '1';
else
return '0';
end if;
end function bool2sl;

--
Paul Uiterlinden
www.aimvalley.nl
e-mail addres: remove the not.


Paul Uiterlinden
  Reply With Quote
Old 09-13-2007, 11:26 PM   #8
Andy
 
Posts: n/a
Default Re: Beyond Newbie Question
On Sep 13, 3:59 pm, Paul Uiterlinden <puit...@notaimvalley.nl> wrote:
> Andy wrote:
> > Along the lines of what Paul said, I _hate_ typing and counting
> > digits, and I prefer code that adapts automatically to changes (like
> > width of the vector, etc.)

>
> > The following example will also work (assume boolean trigger):

>
> > trigger <= unsigned(usb_fifodata) /= 0;

>
> > or with std_logic trigger (concurrent statement):

>
> > trigger <= '1' when unsigned(usb_fifodata) /= 0 else '0';

>
> Expanding on that, I'm not so fond of this kind of selected signal
> assignments. It gets even worse if it was a sequential statement (so in a
> process):
>
> if unsigned(usb_fifodata) /= 0 then
> trigger <= '1';
> else
> trigger <= '0';
> end if;
>
> Too many words and (shudder!) repetition of the target name.
>
> I like to use a function in those cases. This works equally well for
> concurrent an sequential statements:
>
> trigger <= bool2sl(unsigned(usb_fifodata) /= 0);
>
> Where bool2sl is a function that comes out of a package with all this kind
> of small but oh so handy subprograms:
>
> function bool2sl(val: boolean) return std_ulogic is
> begin
> if val then
> return '1';
> else
> return '0';
> end if;
> end function bool2sl;
>
> --
> Paul Uiterlindenwww.aimvalley.nl
> e-mail addres: remove the not.


Paul... Didn't you ever learn that subprograms should have exactly one
exit point? ;^)

function bool2sl(val: boolean) return std_ulogic is
retval : std_logic := '0';
begin
if val then
retval := '1';
end if;
return retval;
end function bool2sl;

or, you don't even need a subprogram:

type bool2sl_t is array (boolean) of std_ulogic;
constant bool2sl : bool2sl_t := (true => '1'; false => '0');

But I agree, we all need one of those packages with all our little
tricks

Some of my favorites:

subtype slv is std_logic_vector; -- abbreviation
subtype sl is std_logic; -- abbreviation
function is1()... -- convert sl to bool with assertion against
metavalues
function is0()...

The is1() & is0() functions have an optional severity level argument.

Andy



Andy
  Reply With Quote
Old 09-14-2007, 09:49 AM   #9
Paul Uiterlinden
 
Posts: n/a
Default Re: Beyond Newbie Question
Andy wrote:
>
>> Where bool2sl is a function that comes out of a package with all this
>> kind of small but oh so handy subprograms:
>>
>> function bool2sl(val: boolean) return std_ulogic is
>> begin
>> if val then
>> return '1';
>> else
>> return '0';
>> end if;
>> end function bool2sl;

>
> Paul... Didn't you ever learn that subprograms should have exactly one
> exit point? ;^)


Yes, but rules are there to be bent occasionally.

> function bool2sl(val: boolean) return std_ulogic is
> retval : std_logic := '0';
> begin
> if val then
> retval := '1';
> end if;
> return retval;
> end function bool2sl;
>
> or, you don't even need a subprogram:
>
> type bool2sl_t is array (boolean) of std_ulogic;
> constant bool2sl : bool2sl_t := (true => '1'; false => '0');


True, but there is a subtle difference: only the function bool2sl may be
used directly in a port map. The table bool2sl may not. For a general
package I choose the function for that reason. For local conversion
functions I use indeed a table.

> But I agree, we all need one of those packages with all our little
> tricks
>
> Some of my favorites:
>
> subtype slv is std_logic_vector; -- abbreviation
> subtype sl is std_logic; -- abbreviation
> function is1()... -- convert sl to bool with assertion against
> metavalues
> function is0()...


min(), max(), inc(), dec(), reverse(), sl2bool(), rand_num_gen(),
rand_vec_gen(), and_reduce(), or_reduce(), xor_reduce() ...

> The is1() & is0() functions have an optional severity level argument.


Instead of your is1 and is0 I use the sl2bool function, with (surprise!) an
optional argument to enable checking against metavalues.

All great people think alike.

--
Paul Uiterlinden
www.aimvalley.nl
e-mail addres: remove the not.


Paul Uiterlinden
  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
Sorry for the painfully newbie question Chip L DVD Video 2 03-20-2007 03:25 PM
Newbie PC DVD region question Geoff B DVD Video 8 03-11-2006 05:48 AM
Another newbie question Jerold Pearson DVD Video 1 12-11-2004 02:25 AM
Newbie Question: DVD Capacities Chris Kotchey DVD Video 3 09-29-2004 03:49 PM
Newbie Question Jeff Turl A+ Certification 6 10-18-2003 10:16 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