In this lab, we are going to talk about the syntax of VHDL, and learn how to write a structural description for our hardware, then we will talk about test benches and how to write a VHDL code that tests our VHDL code.
We will start this section by writing a small VHDL example, this example will be a half-adder using a structural description.
notice that at lines 1
& 2
, we've imported the IEEE std logic package, which is the IEEE standard for describing digital logic values in VHDL.
The entity here describes what is the outer shape of our hardware, what are the inputs and outputs of this design, we give each entity a name, which will be used to create components of this entity, and we can set this entity as the top-level entity.
After declaring the entity name, we will define the ports of this entity and the direction of each port, notice that a
& b
has the type std_logic
and the direction in
.
For now, you should know how to use std_logic
type, which means a single bit, and could have 9 values:
U
: uninitialized. This signal hasn't been set yet.X
: unknown. Impossible to determine this value/result.0
: logic 01
: logic 1Z
: High ImpedanceW
: Weak signal, can't tell if it should be 0 or 1.L
: Weak signal that should probably go to 0H
: Weak signal that should probably go to 1-
: Don't care.and std_logic_vector
, which is a bus (a string of bits), to define one you could write:
The architecture is the implementation of our entity, we define the architecture with a name, then assign it to an entity with the of
keyword.
Note that this is a structural architecture, which will we describe the logic in it literally, please note that this code is not a programming language, so it's not executed sequentially!
In this section, we are going to talk about the concurrent VHDL statements, which are the statements we write inside the architecture body without creating a process.
The signal assignment statement will put a value in a signal.
Notice that we will use single quotes '
for std_logic value, and double quotes "
for strings (e.g array of std_logic).
the signal assignment could have conditions using one of the following syntaxes:
So the code above will assign y to a.b
when c equals 0
, and a+b
when others.
Note that you could have multi cases after the else part.
In this task, you should write an entity named (my_first_entity), which has 2 inputs, and export 3 outputs, the outputs should be the and
& or
& xor
operation between the two inputs.
In this task, you should design an entity with 3 inputs:
and 1 output:
The output should be:
VHDL
IUG