VHDL Language Basics
VHDL Language Basics
Language Basics
Example: 2 (Home) Show whether the following two pieces of code are
equivalent or not by evaluating the value of s at the end of the code.
Comment!
BUFFER
IN
INOUT
IN
OUT
x
simulator time
t t+δ
• If, however, the new value of s is different from its old value, an
event is said to have occurred on s.
a
a c
b b
When simulation time reaches 1000 ps, and the final transaction is applied, the
driver queue is left empty.
After statement 2 s (1,1 ns) (3,3 ns) (3,4 ns) (4,5 ns)
0 10 20 (ns)
p1: PROCESS IS
BEGIN
a <= ’0’;
WAIT FOR 10 ns;
a <= ’1’;
WAIT FOR 10 ns;
a <= ’0’;
WAIT;
END PROCESS p;
p2: PROCESS IS
BEGIN
a <= ’0’, ’1’ AFTER 10 ns, ’0’ AFTER 20 ns;
WAIT;
END PROCESS p2;
• Before we can use such objects one has to declare the composite type
first.
• Typically, we lump composite type declarations in a package that we
use later.
TYPE std ulogic vector IS ARRAY (natural RANGE <>) OF std ulogic;
TYPE std logic vector IS ARRAY (natural RANGE <>) OF std logic;
t q
LIBRARY ieee;
USE ieee.std logic 1164.ALL;
clk
ENTITY t ff IS clear
PORT( t: IN std logic;
clk, clear: IN std logic;
q: OUT std logic);
END ENTITY t ff;
.
.
.
ENTITY driver IS
PORT( a, b, x, y: IN std logic;
q: OUT std logic);
END ENTITY driver;
U X 0 1 Z W L H -
U U U U U U U U U U
X U X X X X X X X X
0 U X 0 X 0 0 0 0 X
1 U X X 1 1 1 1 1 X
Z U X 0 1 Z W L H X
W U X 0 1 W W W W X
L U X 0 1 L W L W X
H U X 0 1 H W W H X
- U X X X X X X X X
Rule: Do not allow more than one process, concurrent signal assignment,
or component instance to drive (assign values) to the same signal.
Otherwise, a resolution function will be required.
Example: 31 (email) Simulate the RS-flip-flop model below by applying
the operations: set, no change, reset, no change, and set, in sequence.
Explain the simulation results. How would the output look like if only one
of the two processes is included. Suggest how to fix any problem in the
code with minimal changes.
Copyright © 2002-2020 VHDL: Language Basics 71 of 93
Std Logic Resolution (Cont.)
Example 31: (Cont.)
LIBRARY ieee;
USE ieee.std logic 1164.ALL;
ENTITY rs ff IS
PORT( r, s: IN std logic;
q: OUT std logic);
END ENTITY rs ff;
ARCHITECTURE wrong OF rs ff IS BEGIN
ps: PROCESS (r, s) IS BEGIN
IF ( s = ’1’ AND r = ’0’) THEN
q <= ’1’;
END IF;
END PROCESS ps;
LIBRARY ieee;
USE ieee.numeric bit.ALL;
LIBRARY ieee;
USE ieee.numeric bit.ALL;
Some useful functions are also defined on signed and unsigned data type:
FUNCTION "+" (L, R: signed) RETURN signed;
FUNCTION "*" (L: signed, R: signed) RETURN signed;
FUNCTION "<" (L, R: signed) RETURN boolean;
S
signed
to_integer(S) std_logic_vector(S)
to_signed(I,S’length) signed(V)
I V
Integer std_logic_vector
to_unsigned(I,U’length) unsigned(V)
to_integer(U) std_logic_vector(U)
U
unsigned
• The conv integer function from the std logic arith library
converts its argument (signed, unsigned, or std logic) to an integer.
• The conv integer function provided by the std logic arith library
cannot convert a std logic vector to an integer because it is
impossible to determine if it represents an unsigned or signed value.
• The conv std logic vector function from the std logic arith
library converts its argument (integer, signed, unsigned, or std logic)
to a std logic vector value with a specific size in bits.
• If conv std logic vector argument is unsigned or positive, it is treated
as an unsigned value; if it is negative, it is converted to 2’s
complement signed form.
• The conv unsigned function from the std logic arith library
converts its argument (integer, signed, or std logic) to a unsigned
value with a specific size in bits.
• The conv signed function from the std logic arith library converts
its argument (integer, unsigned, or std logic) to a 2’s complement
signed value with a specific size in bits.
LIBRARY ieee;
USE ieee.std logic 1164.ALL;
USE ieee.std logic unsigned.ALL;
USE ieee.std logic arith.ALL;
TYPE my module IS
RECORD
rise time: time;
size: integer RANGE 0 TO 200;
data: bit vector (15 DOWNTO 0);
END RECORD my module;
SIGNAL a, b: my module;
To access values or assign values to records, one can use one of the
following methods:
Typically, we lump all our type declarations in a package that we use later.
PACKAGE my types IS
TYPE small int IS RANGE 0 TO 255;
END PACKAGE my types;
• Types address bus and data bus are seen by all design units that use
package my package.
• Constant word size is seen by all design units that use package
my package.
• Constant pi is seen by all processes and statements inside architecture
sample.
• Variable counter is seen only by process p1.
Copyright © 2002-2020 VHDL: Language Basics 92 of 93
Declarative Part Usage