SED VHDL2023 3 STD - Logic
SED VHDL2023 3 STD - Logic
Data Types
SISTEMES ELECTRÒNICS DIGITALS
Sebastià Bota
Data Types
A Data Type defines a set of values and related
operations.
VHDL is a strongly-typed Language. Types cannot be
mixed in Expressions or in assignements
DATA TYPES
ENUMERATED COMPOSITES
• BIT • Arrays
• STD_LOGIC • Records
1
Data Types
Data types and related operators are defined in Packages.
Packages are organised in libraries (A library is a directory and
each package is a file in that directory).
2
Standard Packages
Package STD.STANDARD
Types defined
BOOLEAN
BIT, BIT_VECTOR
INTEGER, NATURAL, POSITIVE
REAL
TIME, DELAY_LENGTH
STRING
CHARACTER
Standard Package
• boolean has two possible values FALSE and TRUE
if a = b then -- equal
if a /= b then -- not equal
if a > b then -- larger
if a < b then -- smaller
if a <= b then -- smaller or equal
if a >= b then -- larger or equal
3
Packages in library IEEE
The packages that you need, except for
"standard", must be specifically accessed by
• std_logic_1164.all; each of your source files with statements such
as:
• std_logic_textio.all;
• std_logic_arith.all; library IEEE;
use IEEE.std_logic_1164.all;
• numeric_bit.all; use IEEE.std_logic_textio.all;
use IEEE.std_logic_arith.all;
• numeric_std.all; use IEEE.numeric_bit.all;
use IEEE.numeric_std.all;
• std_logic_signed.all; use IEEE.std_logic_signed.all;
use IEEE.std_logic_unsigned.all;
• std_logic_unsigned.all; use IEEE.math_real.all;
• math_real.all; use IEEE.math_complex.all;
https://redirect.cs.umbc.edu/portal/help/VHDL/stdpkg.html
Types Types
BOOLEAN STD_LOGIC
BIT STD_ULOGIC
BIT_VECTOR STD_LOGIC_VECTOR
INTEGER STD_ULOGIC_VECTOR
REAL
TIME
STRING
CHARACTER
and =
nand /=
or Implicit >
Operators
nor operators >=
xor <
not <=
4
STD_LOGIC_1164 Types
Std_ulogic and std_logic Defined in IEEE package
STD_LOGIC_1164
uninitialized
unknown
forcing low
forcing high
high impedance
weak unknown
weak low
weak high
Don’t Care
10
5
STD_LOGIC versus STD_ULOGIC
11
STD_LOGIC
ENTITY nand_gate IS
PORT(
a : IN BIT;
b : IN BIT;
z : OUT BIT);
END nand_gate;
Add the IEEE library to the top of your VHDL file : LIBRARY ieee;
and then reference the needed package.
Library ieee; --the compile would know that the word ieee is a library name
use ieee.std_logic_1164.all;
12
6
STD_LOGIC
BEWARE WITH FILES WITH
MULTIPLE ENTITIES
13
STD_LOGIC
BEWARE WITH FILES WITH
MULTIPLE ENTITIES
14
7
More on STD_LOGIC Meanings
type std_logic is ('U' , 'X' , '0' , '1' , 'Z' , 'W' , 'L' , 'H' , '-‘);
‘U’ -- Uninitialized
Signal has not been assigned a value yet
15
A
B
Y <= not C;
Y Y <= A or B;
C
According to te resolution table, the simulator will assign the value ‘X’
(forcing unknown) to signal Y
8
Three state buffers
A three-state buffer (or tri-state) has a data input and an enable input.
Its enable input controls whether the three-state buffer is OFF and its
output is high impedance ('Z'), or whether it is ON and its output is driven by
its data input.
Thus, the output of a three-state buffer can be either '0', '1', or 'Z'.
18
19
9
Busses
Busses, on the other hand, can
be driven by one or more
sources ENB
Information on a Bus
Possible state for a BUS
Driven high (driven to a 1) ENB
impedance)
Capacitive high (H)
Capacitive low (L)
Conflict (one driver driving it ENB
to a 1, another a 0) (X)
Conflict of capacitive values
(W)
24
10
More on STD_LOGIC Meanings
26
11
Single Wire versus Bus
SIGNAL a : STD_LOGIC;
1 wire
8 bus
N
op Z
MSB LSB
28
12
y downto x vs x to y
....
y downto x SIGNAL z_bus: BIT_VECTOR (3 DOWNTO 0);
meaning y is the MSB, SIGNAL a_bus: BIT_VECTOR (1 TO 4);
....
x to y
meaning x is the MSB. z_bus <= a_bus;
29
Operators: Assignment
Assignment Operators
EXAMPLES
data_bit <= ‘1’;
data_bus <=“110011”;
30
13
Standard Logic Vectors
31
Operators: Concatenation
& is the concatenation operator. combines objects of same
type into an array, the order is preserved
14
Logical Operators
Logical operators Defined on types
and BOOLEAN
nand BIT
or BIT_VECTOR
nor STD_LOGIC
xor STD_LOGIC_VECTOR
not
xnor
VHDL 93
--should be...
result <= (a and b) or c;
--maybe
result <= (a nand b) nand c;
--or
result <= a nand (b nand c);
35
15
Precedence in Operators
Logic and relational operators precedence
Highest not
= /= < <= > >=
Lowest and or nand nor xor xnor
compare a = bc
36
'U' < 'X' < '0' < '1' < 'Z' < 'W' < 'L' < 'H' < '-'
16