Salta al contenuto
Note per Studenti VHDL - Entity, Architecture, Types and Description Levels Report

VHDL - Entity, Architecture, Types and Description Levels

In questa pagina 6

Circuits with billions of transistors are not drawn by hand: they are described with a hardware description language (HDL) and simulated and synthesised with CAD tools. The two most common HDLs, both IEEE standards, are VHDL and Verilog. VHDL (Very high speed integrated circuits Hardware Description Language) dates from 1987.

Not a programming language

In Python or C, statements are translated into a sequence executed one after the other by a processor. An HDL is instead translated into a digital circuit: statements are concurrent, i.e. active all at the same instant, as the gates of a circuit work in parallel. A VHDL statement defines a block of hardware, not an execution step; changing the order of concurrent statements does not change the circuit.

Uses of VHDL:

  • documenting a design;
  • simulating behaviour: apply input signals and observe the outputs over time;
  • synthesising: going from a behavioural description to a set of gates and flip-flops (netlist). Only a synthesisable subset of the language can be used; a description meant for simulation only (a testbench) can use the whole language.

Synthesis flow: HDL description + constraints (area, speed, power) + technology libraries →\to intermediate RTL form (Register Transfer Level: generic gates and registers) →\to optimisation →\to technology mapping onto the blocks actually available →\to netlist, used to produce the layout of an IC or the configuration of an FPGA (Programmable Logic Devices - ROM, PLA, PAL and FPGAProgrammable logic devices (PLD) have logic structures configurable by the manufacturer or the user, which is hardware configuration and not software programming. ROM: 2^k words of n bits, a decoder followed by programmable ORs, so a physical truth table; PLA: programmable AND and OR arrays with product terms shared between outputs; PAL: programmable ANDs and fixed ORs, no sharing; FPGA: programmable logic blocks with look-up tables and flip-flops, programmable routing and I/O, with a volatile or non-volatile configuration memory. Programming is irreversible (fuse, anti-fuse, mask) or reconfigurable (SRAM, floating gate).Programmable Logic Devices - ROM, PLA, PAL and FPGA →). The process is iterative.

General features

  • Strongly typed: data of different types cannot be assigned to each other without a conversion function.
  • Case insensitive: Entity and ENTITY are the same; spaces, tabs and newlines are ignored; comments start with --.
  • Every statement ends with ;.
  • Always keep in mind the hardware being described.

Entity and architecture

A VHDL block has two mandatory parts.

Definition (entity). The "nameplate" of the block: it gives its name and defines the interface with the outside (ports, direction, type). It does not say what is inside, like the symbol of a circuit in a schematic. A block must have one entity.

vhdl
entity entity_name is
  port ( input1, input2 : in  std_logic;
         output         : out std_logic );   -- no ';' after the last port
end entity_name;

Mode (direction) of ports: in (the value can be read but not assigned by the block: the driver is outside), out (the value can be assigned but not read: the driver is inside). inout and buffer also exist. Assignment is written X <= Y;: "Y is assigned to X", the arrow goes right to left; whenever YY changes, XX changes. The statement X <= Y is the driver of signal XX.

Definition (architecture). A particular description of the content of an entity: how it behaves and works internally. An entity can have several architectures in the same project (for example a structural and a dataflow one).

Example. architecture beh of and2 is begin y <= a and b; end beh; describes entity and2: with a='1' and b='1', y='1'.

vhdl
architecture arch_name of entity_name is
  -- declarations: component, signal, constant, type
begin
  -- body: concurrent statements
end arch_name;

Libraries and packages. Declared before every entity:

vhdl
library IEEE;
use IEEE.std_logic_1164.all;     -- types std_logic and std_logic_vector

Libraries are collections of packages containing reusable code (types, components, constants). .all means "everything the package defines". For arithmetic on vectors there are IEEE packages (numeric_std) and Synopsys packages (std_logic_unsigned, std_logic_signed) that change how a std_logic_vector is treated (unsigned or signed).

Data types

type what it is example value
std_logic a "logic" bit with 9 values '0', '1', 'X', 'Z', '-'
std_logic_vector vector of std_logic "010", x"1F"
bit only '0' and '1' '1'
boolean TRUE / FALSE true
integer 32-bit integer 100

std_logic values: '0' and '1' logic; 'X' unknown or conflicting; 'U' uninitialised (seen in simulation); 'Z' high impedance; '-' don't care (the synthesiser may optimise); 'L', 'H', 'W' weak values. A std_logic goes in single quotes ('1'), a vector in double quotes ("010").

Definition (std_logic_vector). std_logic_vector(n-1 downto 0) has the most significant bit on the left, index n−1n-1; std_logic_vector(0 to n-1) has index 00 on the left (the MSB). A bit is extracted with x(2), a slice with x(3 downto 1); concatenation is &: "10" & "01" is "1001". Hexadecimal literals are written x"1F". integer is used for parameters (vector length, loop indices), in decimal without quotes.

Example. With x : std_logic_vector(3 downto 0) := "1010";: x(3)='1', x(0)='0', x(3 downto 2)="10" and x & "01" is "101001".

Signal and constant. Ports communicate with the outside and are defined in the entity; internal signals (signal) are declared in the architecture before begin and connect internal nodes or blocks: signal n1, n2 : std_logic;. Constants (constant N : integer := 8;) name fixed values for readability and easy modification.

Three description levels: the 2-bit comparator

Specification: inputs A=A1A0A=A_1A_0, B=B1B0B=B_1B_0 (subscript 11 is the MSB), output AgtB =1=1 if A>BA>B. From the Karnaugh map the minimal SOP is

Formula (2-bit A>BA>B). A>B=A1B1‾+A0B1‾ B0‾+A1A0B0‾.A>B=A_1\overline{B_1}+A_0\overline{B_1}\,\overline{B_0}+A_1A_0\overline{B_0}.

Example. A=10A=10, B=01B=01: A1B1‾=1⋅1=1A_1\overline{B_1}=1\cdot1=1, so A>B=1A>B=1 (indeed 2>12>1).

Same entity for all levels:

vhdl
library IEEE;
use IEEE.std_logic_1164.all;

entity comp2 is
  port ( A, B : in  std_logic_vector(1 downto 0);
         AgtB : out std_logic );
end comp2;

Dataflow

Describes the flow of signals with Boolean equations as concurrent assignments, without detailing the structure:

vhdl
architecture dataflow of comp2 is
begin
  AgtB <= (A(1) and not B(1)) or
          (A(0) and not B(1) and not B(0)) or
          (A(1) and A(0) and not B(0));
end dataflow;

Behavioral

Describes only the behaviour, leaving the choice of circuit to the synthesiser, here with the truth table (the six combinations with A>BA>B, written A1A0B1B0A_1A_0B_1B_0):

vhdl
architecture behav of comp2 is
  signal AB : std_logic_vector(3 downto 0);
begin
  AB <= A & B;
  with AB select
    AgtB <= '1' when "0100" | "1000" | "1001" | "1100" | "1101" | "1110",
            '0' when others;
end behav;

with ... select and when ... else are explained in VHDL - Concurrent Statements, Processes and TestbenchesConcurrent VHDL statements are the plain signal assignment, when-else (priority logic, conditions evaluated in order) and with-select (parallel logic, every case covered once, others required). A process is a concurrent statement with a sequential body (if, case, loop) that wakes up when a signal in its sensitivity list changes; for combinational logic the list holds all inputs; signals are updated when the process suspends and the last assignment wins. An if without else or an uncovered case creates unwanted memory. A testbench has an empty entity, the instantiated DUT and a stimulus process with wait statements.VHDL - Concurrent Statements, Processes and Testbenches →.

Structural

Describes the circuit as interconnected components, equivalent to a gate-level schematic (lowest abstraction level). Gates are needed as VHDL blocks:

vhdl
-- inverter
library IEEE; use IEEE.std_logic_1164.all;
entity inv is port (x : in std_logic; y : out std_logic); end inv;
architecture impl of inv is begin y <= not x; end impl;

-- 2-input AND
library IEEE; use IEEE.std_logic_1164.all;
entity and2 is port (a, b : in std_logic; y : out std_logic); end and2;
architecture impl of and2 is begin y <= a and b; end impl;

-- 3-input AND
library IEEE; use IEEE.std_logic_1164.all;
entity and3 is port (a, b, c : in std_logic; y : out std_logic); end and3;
architecture impl of and3 is begin y <= a and b and c; end impl;

-- 3-input OR
library IEEE; use IEEE.std_logic_1164.all;
entity or3 is port (a, b, c : in std_logic; y : out std_logic); end or3;
architecture impl of or3 is begin y <= a or b or c; end impl;

architecture struct of comp2 is
  signal nb1, nb0, p1, p2, p3 : std_logic;    -- internal nodes
begin
  I1 : entity work.inv(impl)  port map (B(1), nb1);
  I0 : entity work.inv(impl)  port map (B(0), nb0);
  G1 : entity work.and2(impl) port map (A(1), nb1, p1);
  G2 : entity work.and3(impl) port map (A(0), nb1, nb0, p2);
  G3 : entity work.and3(impl) port map (A(1), A(0), nb0, p3);
  G4 : entity work.or3(impl)  port map (p1, p2, p3, AgtB);
end struct;

In instantiation an instance of an already defined block is created and its ports are connected to the desired signals with the port map. Mapping may be positional (entity order, as above) or by name (port map (a => A(1), b => nb1, y => p1)).

Three ways to instantiate a component:

  1. By component: declare a component in the architecture declarations (before begin), repeating the entity ports, then instantiate: INV1 : inv port map (input, output);
  2. Direct: write entity and architecture, entity work.inv(impl), without declaring the component (more compact; used above).
  3. With a package: components are declared in a package that is imported with use work.MyPackage.all;.

Instantiation always lives in the architecture, never in the entity.

Abstraction level

style describes level when
structural interconnected components low (schematic) hierarchies, direct control of structure
dataflow Boolean equations intermediate compact logic functions
behavioral behaviour high complex circuits, state machines

A structural description does not automatically synthesise better than a behavioural one (or vice versa): the synthesiser optimises. The three styles can be combined in one project. The most common architecture for sequential circuits is behavioral (VHDL - Finite State Machines and Sequential TestbenchesA finite state machine is described in behavioral VHDL with an enumerated type for the states and three processes: the state register (reset and state <= next_state on the clock edge), the next state as a combinational function of state and input (case state, with default next_state <= state), and the output as a combinational function of the state alone (Moore) or of state and input (Mealy). The testbench has a clock process and an input process (initial reset, then a test sequence that visits all states).VHDL - Finite State Machines and Sequential Testbenches →).

Versione ripasso

  • HDL, not programming: statements are concurrent (all active together) and describe hardware. Uses: document, simulate, synthesise (only a subset is synthesisable; testbenches are not). Flow: HDL, RTL, optimisation, technology mapping, netlist (IC layout or FPGA configuration).
  • Features: strongly typed, case insensitive, -- comments, ; ends statements.
  • Entity: name and ports (in readable, out assignable); no ; after the last port; one entity per block. Architecture: content; several per entity; declarations (component, signal, constant, type) before begin. library IEEE; use IEEE.std_logic_1164.all; before every entity. X <= Y; is a driver.
  • Types: std_logic ('0' '1' 'X' 'Z' 'U' '-', single quotes), std_logic_vector (double quotes, (n-1 downto 0) MSB left, & concatenation, x"1F"), bit, boolean, integer.
  • 2-bit comparator: A>B=A1B1‾+A0B1‾ B0‾+A1A0B0‾A>B=A_1\overline{B_1}+A_0\overline{B_1}\,\overline{B_0}+A_1A_0\overline{B_0} in three styles: dataflow (equation), behavioral (with AB select ... when others), structural (inv, and2, and3, or3 with port map).
  • Instantiation: port map positional or by name; by component, direct (entity work.inv(impl)), or via package; always inside the architecture.
  • Levels: structural low, dataflow intermediate, behavioral high; can be combined; sequential circuits usually behavioral.
  • Mistakes: thinking VHDL is sequential; ; after the last port; signals after begin; assigning an in port or reading an out port; forgetting library/use; mixing '1' and "1".

Teoria collegata