5 VHDL (I)
5 VHDL (I)
VHDL
A Full Adder
- Before introducing you to VHDL, let’s build a simple circuit, so that we can use it to calculate
binary adder.
A B SUM Carry
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
- Compare the truth table with the ones of those basic gates
• Carry is AND
• SUN is XOR
- This is a half adder. Why “half”? [A full adder would have a carry in as well]
• A full adder can be implemented as two half-adders and one OR gate.
• The SUM output of the full add is XOR on the SUM output of the half add and the carry in.
• The Carry out is 1 if either A and B are both 1(left input to the OR gate) or exactly one of
them is 1 and the Carry In bit is also 1.
1
CS232 Lecture Notes VHDL Fall 2020
- Now, we know how to design a full adder using a pencil and paper and validate it by setting
different values at inputs and checking the output values manually.
- The validate is do-able if the circuit is simple. But, if we have a more complex circuit, we need
to leverage some tools to help with the validation.
- In this course, we use VHDL to assist our circuit design.
- What is VHDL?
• An acronym for Very High Speed Integrated Circuit Hardware Description Language.
• A program language used to describe a logic circuit by function, data flow behavior, or
structure.
- What is GHDL?
• Like Java and C, VHDL programs need to be compiled before running.
• GHDL is a compiler for VHDL.
• GHDL is short for G Hardware Design Language. Currently, G has no meaning.
- Now, let’s see how to use VHDL to describe the full adder.
- Now, we need a test program for the circuit so that we can tell whether the circuit works
correctly.
-- Ying Li
-- A testbench for the full adder
library ieee;
use ieee.std_logic_1164.all;
begin
-- component instantiation
-- connect the inputs and outputs of the entity to the local signals
adder1 : adder port map (A=>I0, B=>I1, Ci=>I2, Co=>O0, S=>O1);
I0 <= '0', '1' after 4 ns; -- send signals to port a, the signal is 0 in the first 4 ns
and 1 afterward
I1 <= '0', '1' after 2 ns, '0' after 4 ns, '1' after 6 ns;
I2 <= '0', '1' after 1 ns, '0' after 2 ns, '1' after 3 ns, '0' after 4 ns, '1' after 5
ns, '0' after 6 ns, '1' after 7 ns, '0' after 8 ns;
end behavior;
3
CS232 Lecture Notes VHDL Fall 2020
- Open the adder.vcd file using gktwave, you will get a window like this
- Select the all the signals and click “Insert”, then click the “Zoom Fit” button. You will get a
window like this. The green signals can help us to validate the full adder.