Hi,
i am new in VHDL and i not understand what advantage in use types
std_logic/std_ulogic and std_logic_vector/std_ulogic_vector? I always
use types bit and bit_vector, but i always see in examples the use of
these types.
Thanks.
std_logic and std_ulogic bring along the concepts of unknown values,
strong and weak driving as well as high impedance. Whereas a 'bit'
can only be '0' or '1', a std_logic/std_ulogic has the following
definition
TYPE std_ulogic IS ( 'U', -- Uninitialized
'X', -- Forcing Unknown
'0', -- Forcing 0
'1', -- Forcing 1
'Z', -- High Impedance
'W', -- Weak Unknown
'L', -- Weak 0
'H', -- Weak 1
'-' -- Don't care
The 'weak' values 'W', 'L' and 'H' somewhat model the way a resistor
on a board behaves. While you can't tie two outputs together and not
expect conflicts, you can tie them together through a resistor. The
resolution rule if there is more than one driver for a signal is that
'forcing' beats 'weak', so a '1' or '0' would trump a 'L' or an 'H'.
Search the source file that contains the ieee std_logic_1164 package
for the function called 'resolved' and you'll find the code that does
it, which then defines the entire set of 81 rules for when these 9
values crash together.
'Z' is used to model tri-state outputs.
'X' results when you have two drivers for a signal and they are going
in different directions. So a '0' driver combined with a '1' driver
cause the signal to be 'X'.
'U' models the reality that not all signals power up with a known
value. Sometimes it may power up as a '0', other times as a '1'.
What 'U' does is say that the value is unknown.
While most people generally think of digital systems in terms of '0'
and '1' (i.e. type 'bit'), it is generally quite helpful to use
std_logic/std_ulogic instead because a design that really does get
everything initialized properly will have a designed in mechanism to
change any 'U' into a known value. If you use 'bit' instead, you
might find yourself in the situation where the simulation appears to
be working, but that is because it is using a default value of '0' for
a signal, and that '0' might not be something that happens in the
normal course of events. In other words, you think everything is
fine, but it's not...or at least it's not guaranteed to be working the
way you expect. There are a few downsides to std_logic/std_ulogic,
but for the most part the benefits outweigh the drawbacks.
Kevin