In this lab, we are going to talk about how to use components, which allows you to create and use/reuse your old component and to organize your design into multiple components, then we will talk about test benches, which allows you to easily verify and test your VHDL code.
The first thing we will talk about is ssignals, which are wires, we will use these s to connect components together, and more!
To create a signal, you will need to write
for example:
Notice that we've created a signal called not_a
and its type is std_logic
.
To use an entity as a component, you should declare this component in the architecture that will use that entity, for example:
Now after declaring the components you want to use, you can now create instances of this component and map its ports to your signals, for example:
Notice in lines 19
,20
, we created two instances of the half_adder
component.
We named the first instance ha1
, and we mapped it to our signals a
, b
, s1
, c1
, which will be mapped in the component declaration order.
In line 20
, we created ha2
and mapped each signals with its name.
A Test bench is just a regular VHDL file, which will use your entities and assert expected results, to write a test bench you will create a new VHDL file, then change its type to VHDL Test Bench File
.
Figure 1: VHDL File Proparites.
Then you should edit your simulation settings and choose Compile test bench
.
Figure 2: Simulation Settings.
Then click on Test Benches
, and add your test bench to the list of test benches.
Figure 3: Adding a file as a test bench.
To write a test code, you will create an empty entity (doesn't have any inputs or outputs), then you will create an architecture for that entity.
The architecture of a test bench will usually contain processes, the processes behave like a sequential code, so don't expect a test bench to be synthesised.
And don't forget that you will use the tested entity as a component, so you should declare it and create an instance of it inside the architecture, for example:
Notice that we have signals declared, so we could change the inputs and read the outputs of the component.
Now, we will create a process, which contains some signal assessment, waiting statements, and assertion statements, notice that this is just a simple test bench.
Now after running the simulator, you will notice that the signals will show up in the wave view, and if there is any fail assertion it will be reported in the console.
Figure 4: Wave view
In this task, you should create 3 entites, half_adder
, full_adder
, and adder_4bit
.
As you might expect, the adder_4bit
, should use the full_adder
, and it should have 3 inputs and 2 outputs:
a
4-bit inputb
4-bit inputc
1-bit inputs
4-bit outputcout
1-bit outputIn this task, you should create a test bench for your full adder, and it should cover all possible values.
VHDL
IUG