1. What Is VHDL?
VHDL = VHSIC (Very High Speed Integrated Circuit) Hardware Description Language. It is at once:
- a design description language,
- a design documentation language,
- a simulation language,
- an IEEE standard (IEEE 1076 for the language, IEEE 1164 for the std_logic types).
Why Use It?
- Fast time-to-market: designs of tens of thousands of gates; high-level constructs for complex logic; modular, hierarchical design.
- One language for design, documentation and simulation.
- Device-independent: portable across Programmable Logic Device (PLD) vendors — any synthesis tool, vendor or device.
History
| Year | Event |
|---|---|
| 1980 | Project starts, funded by the US DoD |
| 1982 | Contract to Intermetrics, IBM and Texas Instruments |
| 1985 | Version 7.2 released to the public domain |
| 1987 | IEEE 1076 (VHDL-87) |
| 1993 | VHDL-93 |
| 2001 | VHDL-2001 |
| 2008 | VHDL-2008 |
Designs and testbenches can be simulated online at edaplayground.com.
2. Basic Syntax
- Strongly typed (types checked at compile time); user-defined types allowed.
- Not case sensitive (
END,End,endare the same). - Comments start with
--. - Statements end with
;.
Rule – Legal Identifiers
- Letters, digits and underscores only.
- First character must be a letter; last character cannot be
_. - No two consecutive underscores; no reserved words.
| Legal | Not legal (why) |
|---|---|
tx_clk, Three_State_Enable, sel7D, HIT_1124 | _tx_clk (starts with _), 8B10B (starts with digit), large#num (#), register (reserved), clk_ (ends with _) |
3. Design Units: ENTITY + ARCHITECTURE
A VHDL design = an ENTITY declaration (the I/O — the “black box”) + an ARCHITECTURE body (the contents/function). Every architecture belongs to an entity, so they are called an entity/architecture pair.
flowchart LR subgraph ENTITY["ENTITY (black box: ports)"] subgraph ARCH["ARCHITECTURE (what's inside)"] G["C <= A and B"] end end A["A"] --> G B["B"] --> G G --> C["C"]
3.1 The Entity
ENTITY entity_name IS PORT (
-- optional generics
name : mode type ;
...
name : mode type -- no ';' after the last port
); -- ';' after the closing parenthesis
END entity_name;- The entity name is user-defined; naming the file after it is recommended (
AND_entity→AND_entity.vhd). - Generics are constants that control the structure or behaviour of the entity.
- Ports of the same mode and type can share one line, separated by commas.
⚠️ No semicolon after the last port, but one after the closing
).
Example – AND Gate Entity
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
entity AND_entity is
port( A: in std_logic;
B: in std_logic;
C: out std_logic
);
end AND_entity;3.2 Ports: Name, Mode, Type
Ports are the entity’s communication points (usually device pins). Each has a name, a mode and a type.
| Mode | Direction |
|---|---|
IN | data goes into the entity only |
OUT | data goes out only (not readable internally) |
INOUT | bidirectional |
BUFFER | goes out and is fed back internally |
3.3 Types
IEEE 1076 types
| Type | Values / use |
|---|---|
BIT | '0' or '1' |
BIT_VECTOR | group of bits, e.g. bit_vector(7 downto 0) or (0 to 7) |
INTEGER | loop indices, constants, arithmetic: K: out integer range -2**4 to 2**4-1; (** = power) |
BOOLEAN | TRUE / FALSE |
| Enumerated | user-defined: TYPE traffic_light IS (red, yellow, green); |
signed | vector representing a signed binary number: M: in signed(4 downto 0); |
Vector literals use double quotes, single bits single quotes:
b <= "0111"; -- b(3)='0', b(2)='1', b(1)='1', b(0)='1' (if declared 3 downto 0)
c <= "0101";⚠️ With
downto, the leftmost character is the highest index. (The slide listsb(0) = '0', which corresponds to a0 to 3declaration — check the direction your vector is declared with.)
IEEE 1164 – STD_LOGIC / STD_LOGIC_VECTOR
A package that fixes the limits of BIT: nine values instead of two. Now the industry standard, and required for tri-state ('Z'). Needs:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;| Value | Meaning |
|---|---|
'0' / '1' | hard 0 / hard 1 |
'Z' | high impedance |
'L' / 'H' | weak 0 / weak 1 |
'-' | don’t care |
'U' | uninitialized |
'X' | strong drive, unknown |
'W' | weak drive, unknown |
'U', 'X', 'W' are simulation-only (not synthesizable).
Exercise – Entity Declaration
Ports: D 12-bit input bus; OE, CLK input bits; AD 12-bit bidirectional bus; A 12-bit output bus; INT output; AS output also used internally.
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY Exercise_1 IS PORT (
d : IN std_logic_vector(11 DOWNTO 0);
oe, clk : IN std_logic;
ad : INOUT std_logic_vector(11 DOWNTO 0);
a : OUT std_logic_vector(11 DOWNTO 0);
int : OUT std_logic;
as : BUFFER std_logic);
END Exercise_1;3.4 The Architecture
ARCHITECTURE arch_name OF entity_name IS
-- optional declarations (internal signals, components…)
BEGIN
-- VHDL statements
END arch_name;Three description styles (they can be mixed):
| Style | Content | Example |
|---|---|---|
| Dataflow | concurrent assignments, Boolean expressions | x <= (a OR b) AND c; |
| Behavioral | sequential statements inside a process (algorithmic) | IF a = b THEN state <= state5; |
| Structural | instances of components + port maps (a textual schematic) | u1: and2 port map(...) |
3.5 Signals
Signals model wires. Ports are a special kind of signal. A signal has a name and a type but no mode, and is declared in the architecture before BEGIN:
ARCHITECTURE signal_example OF an_entity IS
SIGNAL count : std_logic_vector(3 DOWNTO 0); -- internal 4-bit bus
BEGIN
...
END signal_example;4. The Three Description Styles
4.1 Dataflow
Statements are concurrent: whenever an input changes, the new value propagates to the output. <= is the signal assignment operator.
architecture example of AND_entity is
begin
C <= A and B;
end example;4.2 Behavioral (Process)
Models things that are sequential in nature. A process holds sequential statements and runs only when a signal in its sensitivity list changes. Inside a process you can declare variables (assigned with :=) and use wait/after to model delays.
mux: PROCESS (a, b, s) -- sensitivity list
BEGIN
IF s = '0' THEN x <= a;
ELSE x <= b;
END IF;
END PROCESS mux;4.3 Structural
Instantiate existing modules (each with a unique label) and connect them with a port map.
Example – g = ab + de from AND2/OR2 Components
entity and_or is port(
a, b, d, e : in std_logic;
g : out std_logic);
end and_or;
architecture and_or_a of and_or is
component and2 port(a, b : in std_logic; c : out std_logic); end component;
component or2 port(a, b : in std_logic; c : out std_logic); end component;
signal c, f : std_logic; -- internal wires
begin
u1: and2 port map(a => a, b => b, c => c);
u2: and2 port map(a => d, b => e, c => f);
u3: or2 port map(a => c, b => f, c => g);
end and_or_a;flowchart LR a --> u1["u1: and2"] b --> u1 d --> u2["u2: and2"] e --> u2 u1 -->|"c"| u3["u3: or2"] u2 -->|"f"| u3 u3 --> g
In a => d, the left side is the component’s port, the right side is the signal it connects to.
5. Describing Combinational Logic (4-to-1 MUX Five Ways)
All five examples implement
Example 1 – Boolean Equations (concurrent)
Operators: NOT, AND, OR, NAND, NOR, XOR, XNOR. NOT has the highest precedence; all others are equal → use parentheses.
x <= (a AND NOT(s(1)) AND NOT(s(0))) OR
(b AND NOT(s(1)) AND s(0) ) OR
(c AND s(1) AND NOT(s(0))) OR
(d AND s(1) AND s(0) );⚠️ Unlike Boolean algebra, VHDL gives AND and OR the same precedence:
a or b and cis nota + bc. Always parenthesize.
Example 2 – Selected Assignment WITH … SELECT … WHEN (concurrent)
with s select
x <= a when "00",
b when "01",
c when "10",
d when others;WHENchoices must be mutually exclusive; useWHEN OTHERSto avoid latches.- One target signal, one
<=. - Choices can be ranges or lists:
with int_value select
x <= a when 0 to 3, -- range
b when 4 | 6 | 8, -- list
c when 10, -- single value
d when others; -- defaultExample 3 – Conditional Assignment WHEN … ELSE (concurrent)
x <= a when (s = "00") else
b when (s = "01") else
c when (s = "10") else
d;- Any expression can be a condition; priority = order of appearance.
- End with a final
ELSEto avoid latches.
WITH-SELECT vs. WHEN-ELSE
WITH-SELECT-WHEN tests one control signal; WHEN-ELSE can test many — e.g. a priority encoder:
j <= w when (a = '1') else
x when (b = '1') else
y when (c = '1') else
z when (d = '1') else
'0';Example 4 – IF-THEN-ELSE (sequential → inside a process)
mux4_1: process (a, b, c, d, s)
begin
if s = "00" then x <= a;
elsif s = "01" then x <= b;
elsif s = "10" then x <= c;
else x <= d;
end if;
end process mux4_1;Example 5 – CASE-WHEN (sequential → inside a process)
mux4_1: PROCESS (a, b, c, d, s)
BEGIN
CASE s IS
WHEN "00" => x <= a;
WHEN "01" => x <= b;
WHEN "10" => x <= c;
WHEN OTHERS => x <= d;
END CASE;
END PROCESS mux4_1;| Statement | Kind | Where |
|---|---|---|
| Boolean equation | concurrent | architecture body |
WITH-SELECT-WHEN | concurrent | architecture body |
WHEN-ELSE | concurrent | architecture body |
IF-THEN-ELSE | sequential | inside a process |
CASE-WHEN | sequential | inside a process |
6. Concurrent vs. Sequential Statements
Concurrent Statements
Executed in parallel; their order does not matter.
Example – Two Orders, Same Circuit
ARCHITECTURE concurrent_architecture_1 OF concurrent IS
SIGNAL e : std_logic;
BEGIN
e <= a and b;
d <= e or c;
END concurrent_architecture_1;
ARCHITECTURE concurrent_architecture_2 OF concurrent IS
SIGNAL e : std_logic;
BEGIN
d <= e or c; -- swapped
e <= a and b;
END concurrent_architecture_2;Both simulate to identical waveforms for .
Sequential Statements and Processes
To describe a function as an algorithm, use sequential statements, where order matters. They live inside a process, and each process counts as one big concurrent statement (an architecture may contain many processes, linked by signals).
label: PROCESS (sensitivity list)
-- variable declarations
BEGIN
-- sequential statements
END PROCESS label;- A process is asleep until a signal in its sensitivity list changes; it then wakes up, runs its statements, updates its outputs at the end, and goes back to sleep.
- The label and variable declarations are optional; the order of signals in the sensitivity list doesn’t matter.
- Processes can model combinational or synchronous logic.
⚠️
IF-THEN-ELSEandCASE-WHENare sequential — they are only legal inside a process.
Variables vs. Signals
| Signal | Variable | |
|---|---|---|
| Declared | architecture (before BEGIN) | inside a process |
| Assignment | <= | := |
| Takes effect | scheduled (at the end of the process) | immediately |
| Visible to other processes | yes | no |
PROCESS
VARIABLE b : std_logic;
BEGIN
WAIT UNTIL clock = '1';
b := a; -- immediate
c <= b; -- scheduled
END PROCESS;7. Operators, Aggregates and Don’t-Cares
Native Operators (IEEE 1076)
| Class | Operators | Defined for |
|---|---|---|
| Logical | AND NAND OR NOR XOR XNOR NOT | bit, bit_vector, boolean (overloaded for std_logic) |
| Relational | = /= < <= > >= (return boolean) | bit, bit_vector, integer (overloaded for std_logic) |
| Arithmetic | + - * | INTEGER |
| Concatenation | & | strings (std_logic_vector is a string) |
Any operator can be overloaded for other types (std_logic didn’t exist when 1076 was written).
⚠️ Vectors of different lengths are compared left to right like strings:
"111" > "10111"is TRUE.
⚠️
<=means “less than or equal” in a condition but “signal assignment” in a statement — context decides.
Aggregates and Slices
tmp <= (a, b, c, d); -- aggregate: build a bus
tmp <= a & b & c & d; -- same with concatenation
rw <= ctrl(0); ce <= ctrl(1); oe <= ctrl(2); -- extract bits
highcount <= count(7 DOWNTO 4); -- sliceSizes on both sides of <= must match.
Behavioral Don’t-Cares
Assigning '-' lets synthesis choose the optimal value:
IF (a = '1') AND (b = '1') THEN x <= c;
ELSE x <= '-';
END IF;⚠️
"1101" = "11-1"returns FALSE (the'-'is compared literally). Usestd_match(a, "11-1")(from the numeric/arith package) when comparing with don’t-cares.
8. Complete Examples
7-Segment Decoder (with Enable)
entity Seven_Segments is
port( ena : in STD_LOGIC;
indata : in STD_LOGIC_VECTOR(3 downto 0);
disp : out STD_LOGIC_VECTOR(6 downto 0));
end Seven_Segments;
architecture Seven_Segments_Architecture of Seven_Segments is
begin
process(indata, ena)
begin
if ena = '1' then
case indata is -- abcdefg
when "0000" => disp <= "1111110";
when "0001" => disp <= "0110000";
when "0010" => disp <= "1101101";
when "0011" => disp <= "1111001";
when "0100" => disp <= "0110011";
when "0101" => disp <= "1011011";
when "0110" => disp <= "1011111";
when "0111" => disp <= "1110000";
when "1000" => disp <= "1111111";
when "1001" => disp <= "1111011";
when others => disp <= "1110110";
end case;
else
disp <= "1111110";
end if;
end process;
end Seven_Segments_Architecture;8-Bit Adder (Two Architectures)
entity Adder_8_bits is
port( op1, op2 : in INTEGER;
c : out STD_LOGIC;
sum : out INTEGER);
end Adder_8_bits;
-- Dataflow
architecture Adder_8_bits_Arch_1 of Adder_8_bits is
begin
sum <= op1 + op2;
c <= '1' when op1 + op2 > 255 else '0';
end Adder_8_bits_Arch_1;
-- Behavioral, with a variable
architecture Adder_8_bits_Arch_2 of Adder_8_bits is
begin
process(op1, op2)
variable num : integer;
begin
num := op1 + op2;
if num > 255 then
num := num - 256;
c <= '1';
else
c <= '0';
end if;
sum <= num;
end process;
end Adder_8_bits_Arch_2;⚠️ The slide’s version uses
sum >= 255andnum - 255. For 8 bits the carry happens when the sum exceeds 255 (≥ 256), and the wrapped result isnum - 256. Arch 1 in the slide also reads the output portsuminside the architecture, which VHDL-93 doesn’t allow for modeout— compute fromop1 + op2(as above) or use an internal signal.
9. Exercises (from the Slides)
- Implement the two gate circuits shown on the slide in VHDL.
- Write a 4-input multiplexer whose inputs are 32-bit
std_logic_vectors. - For
ENTITY compare IS PORT(a, b : IN std_logic_vector(3 DOWNTO 0); eq : OUT std_logic);, write three architectures settingeq = '1'whena = b: (1)WHEN-ELSE, (2) Boolean equations, (3)IF-THEN-ELSE. - Implement the half adder and the full adder.
- Write a 4-bit Gray-to-binary converter.
Worked Example – Exercise 3 (three architectures)
ARCHITECTURE arch1 OF compare IS
BEGIN
eq <= '1' WHEN a = b ELSE '0';
END arch1;
ARCHITECTURE arch2 OF compare IS
BEGIN
eq <= NOT( (a(3) XOR b(3)) OR (a(2) XOR b(2)) OR
(a(1) XOR b(1)) OR (a(0) XOR b(0)) );
END arch2;
ARCHITECTURE arch3 OF compare IS
BEGIN
PROCESS (a, b)
BEGIN
IF a = b THEN eq <= '1';
ELSE eq <= '0';
END IF;
END PROCESS;
END arch3;(Arch 2 is the XNOR comparator of 9A-2 – Arithmetic Circuits (Subtraction and Comparators).)
Worked Example – Exercise 4 (full adder, dataflow)
ENTITY full_adder IS PORT(
x, y, z : IN std_logic;
s, c : OUT std_logic);
END full_adder;
ARCHITECTURE dataflow OF full_adder IS
BEGIN
s <= x XOR y XOR z;
c <= (x AND y) OR ((x XOR y) AND z);
END dataflow;Exercises: 1–5 listed in §9 (entity exercise solved in §3.3).