VHDL Cookbook 1
VHDL Cookbook 1
VHDL Cookbook 1
Introduction
1-1
1-2 The VHDL Cookbook
A A F
Y
B G
A A
Y Y Y
F B I
B
A
Y
(a) B B H
(b)
productions where they are not directly relevant to the context. For this
reason, the full syntax is included in AppendixA, and should be consulted
as a reference.
BIT_0 COUNT2
T_FLIPFLOP
CLOCK Q0
FF0
CK Q
BIT_1
INV T_FLIPFLOP
INVERTER Q1
INV_FF0 FF1
A Y CK Q
explicitly given for this value when the entity is used in a design, the default
value of 10ns will be used.
An implementation of the entity is described in an architecture body.
There may be more than one architecture body corresponding to a single
entity specification, each of which describes a different view of the entity.
For example, a behavioural description of the counter could be written as:
architecture behaviour of count2 is
begin
count_up: process (clock)
variable count_value : natural := 0;
begin
if clock = '1' then
count_value := (count_value + 1) mod 4;
q0 <= bit'val(count_value mod 2) after prop_delay;
q1 <= bit'val(count_value / 2) after prop_delay;
end if;
end process count_up;
end behaviour;
In this description of the counter, the behaviour is implemented by a
process called count_up, which is sensitive to the input clock. A process is a
body of code which is executed whenever any of the signals it is sensitive to
changes value. This process has a variable called count_value to store the
current state of the counter. The variable is initialized to zero at the start of
simulation, and retains its value between activations of the process. When
the clock input changes from '0' to '1', the state variable is incremented, and
transactions are scheduled on the two output ports based on the new value.
The assignments use the generic constant prop_delay to determine how long
after the clock change the transaction should be scheduled. When control
reaches the end of the process body, the process is suspended until another
change occurs on clock.
The two-bit counter might also be described as a circuit composed of two
T-flip-flops and an inverter, as shown in Figure1-2. This can be written in
VHDL as:
1. Introduction 1-5