A Compact Overview P: Recommended Books: Recommended Books
A Compact Overview P: Recommended Books: Recommended Books
A Compact Overview P: Recommended Books: Recommended Books
button
G button
Int od ction
Introduction %
RO O
Finite-State
Machine
3 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 4 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Control Box Classic Approach
11b X 00b 0b 1b 1b
Green Light
5 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 6 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
B
B Red Light u S1
Red Light
S1
u t
t t
S0
Orange Light
o
t Orange Light n
o S0 Green Light
n Clock
Green Light Button
State 00 01 10 11 00
00 0 00 1 0 0 S1 S1 Red light
00 1 01 1 S1 0 S1 S10 S1 S1 S1 Orange light
S0 1
0 1
0 Green light
01 X 10 S00 0 11 1 00 S0 0 0 0 0
time
10 X 11 0 0 1 S0 0
1 0
1 Flip flop delay Undefined state Gate delay
11 X 00 S00 1 01 0 11 S0 1 1 0 1 due to cascaded
logic gates
7 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 8 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Is This the Way to Go? Design Flow
Design engineers used this method until Hardware flow Software flow
about 1985
For simple designs this method works, but
as complexity increases new
? C++ or Java
VHDL is a very rich language and provides Simulation: It is the process of verifying the
syntactical elements for describing: proper functionality of the VHDL description of a
Synthesizable digital systems system (similar to executing a program in C++
Functional description of complex components or Java)
(processors DSPs
(processors, DSPs, etc
etc.))
Description of libraries of elementary gates with
internal delays rise and fall times,
times etc.
etc y
Synthesis: It is the p
process of translating
g the
… VHDL description of a system into simple gates
We will only use a subset,
subset namely the (similar
(s a to
o co
compiling
p g a program
p og a in C++
C or
o
description of synthesizable zero-delay digital Java)
systems
13 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 14 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
BEGIN
IF (state = green) THEN Green_Light <= ‘1’;
update_process : PROCESS(state,button)
Button ELSE Green_Light <= ‘0’; Button
END IF;
BEGIN
G G
IF (state = orange OR
IF (state = green) THEN
IF (button = ‘1’) THEN next_state <= orange;
Button state = red_orange) THEN Orange_Light <= ‘1’;
ELSE Orange_Light <= ‘0’;
Button
END IF;
ELSE next_state <= green;
END IF; RO O
IF (state = red OR
state = red_orange) THEN Red_Light <= ‘1’;
RO O
ELSIF (state = orange) THEN next_state <= red; ELSE Red_Light <= ‘0’;
ELSIF (state = red) THEN next_state
next state <= red_orange;
red orange; END IF;
ELSE next_state <= green; R END PROCESS output_process;
R
END IF;
END PROCESS update_process;
State State
Update (memory) Output Update (memory) Output
Process Process Process Process
(combinatorial (combinatorial (combinatorial (combinatorial
logic) logic) logic) logic)
15 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 16 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Traffic Light in VHDL Basic Syntactical Rules
And finally, the “memory”
memory of the state has to be modelled VHDL is a case insensitive language
Note that the new state only depends on next_state and clk
VHDL has a free formatting
B tt
Button
Each command sequence should be
G
terminated by a “;”
state_process : PROCESS (clk, next_state)
Button
BEGIN
IF (clk’event AND clk=‘1’) THEN state <= next_state;
END IF;
RO O Remarks can be placed by using “--” in front
of the remark
END PROCESS state_process;
State
Update (memory) Output
Process Process
(combinatorial (combinatorial
logic) logic)
17 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 18 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
The “black box” is The signals going into, or coming ENTITY <entity_name> IS
called ENTITY in from the ENTITY are called ports
ports, and PORT ( … );
END <entity_name>;
VHDL are described in the PORT section
ENTITY fsm IS
PORT ( B : IN std_logic; -- Button input
RL : OUT std_logic; -- Red light output
OL : OUT std_logic; -- Orange light output Each ENTITY may have Each ENTITY requires a
GL : OUT std_logic); -- Green light output a port section unique name
END fsm;
19 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 20 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Syntax of the Port Section (Signal) Types in VHDL
VHDL knows various types, like:
Each PORT requires a unique name Each PORT requires a signal type
Real
We will seldom (or never…)
Integer use standard types
PORT ( <port
<port_name>
name> : <port_type>
<port type> <signal_type>;
<signal type>;
Time
i
<port_name> : <port_type> <signal_type>;
. …
In this course we are only going to use the following VHDL types:
.
<port name> : <port_type>
<port_name> <port type> <signal type>;
<signal_type>; IMPORTANT NOTE:
<port_name> : <port_type> <signal_type> The last port in the PORT section STD_LOGIC Æ This is the type holds a one bit quantity (see it as being
is not terminated by a ;
);
one wire)
STD LOGIC VECTOR ((n-1) DOWNTO 0) Æ This type holds a set of
STD_LOGIC_VECTOR
Each
PORT requires a type, which can be: n-bits (see it as being a collection of n wires)
IN => The port is an input port (Read Only)
OUT => The pport is an output
p port
p ((Write Only)
y)
Furthermore we are going to use own defined types, which can
INOUT => The port is bidirectional (Read and Write) come in
i handy
h d ini FSMs
FSM ((as we will
ill later
l t see):
)
TYPE state_type IS (Green, Orange, Red, RedOrange)
TYPE hex_type
_ IS (1,2,3,4,5,6,7,8,9,A,B,C,D,E,F)
We will seldom (maybe
never…) use INOUT ports
21 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 22 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
23 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 24 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Functionality Architecture
ARCHITECTURE functional_level OF fsm IS state_process : PROCESS (clk, next_state)
RL
BEGIN
TYPE fsm_state_t IS (green,orange,red,red_orange); IF (clk’event AND clk=‘1’) THEN state <= next_state;
SIGNAL state : fsm_state_t; END IF; State
SIGNAL next_state : fsm_state_t; END PROCESS state_process; Update (memory) Output
Process G=00b
BEGIN END functional_level; B (combinatorial
Process
update_process : PROCESS(state,button)
logic)
O 01b
O=01 (combinatorial OL
BEGIN R=10b logic)
IF (state = green) THEN RO=11b
IF (button = ‘1’) THEN next_state <= orange;
ELSE next_state <= green;
END IF;
ELSIF (state = orange) THEN next_state <= red;
GL
ELSIF (state = red) THEN next_state <= red_orange;
ELSE next_state <= green; The functionality of the black box
END IF;
is described in VHDL in the The ports are defined in the
END PROCESS update_process;
ARCHITECTURE
C C section PORT section of the ENTITY declaration,
declaration
output_process : PROCESS (state)
BEGIN and are therefore inherently known in the
IF (state = green) THEN Green_Light <= ‘1’;
State ARCHITECTURE
ELSE Green_Light <= ‘0’; Update (memory) Output
END IF;
Process Process
P ARCHITECTURE implementation_1
implementation 1 OF fsm IS
IF (state = orange OR
state = red_orange) THEN Orange_Light <= ‘1’; (combinatorial (combinatorial …
ELSE Orange_Light <= ‘0’; logic) logic)
END IF;
BEGIN
IF (state = red OR …
state = red
red_orange)
orange) THEN Red
Red_Light
Light <= ‘1’;
1 ; END implementation_1;
implementation 1;
ELSE Red_Light <= ‘0’;
END IF;
END PROCESS output_process;
25 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 26 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
[Declaration Section]
BEGIN
ARCHITECTURE ARCHITECTURE ARCHITECTURE [Body]
implementation_2 implementation_1 implementation_3 END <implementation_name>;
29 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 30 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
following the RTL (=Register Transfer Level) principle. In this course ENTITY least one functional
description
LIBRARY ieee; (ARCHITECTURE)…
we will only design using this principle. USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
The RTL principle consists of separating the sequential processes (e.g.,
memory, flip-flops and latches) from the combinatorial processes. Finally we ENTITY <entity_name> IS
PORT ( <port_name> : <port_type> <signal_type>;
ARCHITECTURE
2
ARCHITECTURE
1
ARCHITECTURE
3
connect the different processes by wires. <port_name> : <port_type> <signal_type>;
.
How do we do this: . But each ENTITY can
Identify the combinatorial and sequential elements. <port_name> : <port_type> <signal_type>; have multiple
functional descriptions
<port_name> : <port_type> <signal_type> (ARCHITECTURE)
Write the VHDL code for all these elements. );
Control that no memory action is introduced in the combinatorial elements
END <entity
y_name>;
State BEGIN
Update (memory) Output [Body]
Process Process END <implementation_name>;
(combinatorial (combinatorial
logic) l i )
logic)
31 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 32 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
2 Remember RTL
We will divide each system (ARCHITECTURE) into:
Combinatorial elements
The body of an ARCHITECTURE Elementary sequential elements (memory, flip-flop and/or latches)
Interconnects ((wires)
i )
Each combinatorial and sequential element form a PROCESS inside
the ARCHITECTURE and all execute in parallel
p
Signals as wires
INPUTS SYSTEM OUTPUTS
Operators
State State
Statements (memory,
(memory
flip-flops combinatorial
(memory,
(memory
flip-flops
or or
logic
Events latches) latches)
Cin Cout And all SIGNAL’s are defined in the It is good practice, but not required,
declaration section of the ARCHITECTURE to prefix all signal names with “s_”
Cout = A.B+Cin.(A XOR B)
35 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 36 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Signal Properties Constant Signal Assignments
Each SIGNAL mayy and must be assigned g only
y once. Compare
p with an We can assign
g a constant value to a signal
g of type
yp std_logic
g byy using
g
electrical wire, if we connect a wire to two outputs, we create a short circuit <signal_name> <= ’<value>’;
and “blow the fuse” Examples
s_a <= ’0’;
A SIGNAL is assigned a value by s_a <= ’1’
’1’;
s_a <= ’X’;
<signal_name> <= <source>; s_a <= ’Z’;
Each SIGNAL can be used multiple times.times We can connect a wire to one
We can assign a constant value to a signal of type std_logic_vector by
or multiple loads, of course using <signal_name> <= ”<value>”;
Each SIGNAL is global to its and only its ARCHITECTURE Examples
A SIGNAL whichhi h is
i assigned
i d with
ith a constant
t t value,
l can be
b declared
d l d ini the
th s_vect
t <
<= ”0101”
”0101”; -- Assign
A i bi
binary value
l
declaration section of the ARCHITECTURE as a CONSTANT s_vect <= X”F”; -- Assign hexadecimal value
s_vect <= to_stdlogicvector(-3,4); -- Assign integer –3 in 4
CONSTANT <constant_name> : <signal
g _type>
yp := <value>; -- bit representation
We can use the macro OTHERS for signals of type std_logic_vector
Example
s_vect <= ”0000”; equals s_vect <= (OTHERS => ’0’);
It is good practice
practice, but not required
required, Some synthesizers do not allow for
to prefix all constant names with “c_” constant declaration, and thus
we will seldom use the constant
37 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 38 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
the ARCHITECTURE
B Cpropagate
PORT’s have a slightly odd behavior:
Input PORT’s can only be read, but they cannot be assigned a value Cin Cout
Output PORT’s
PORT s can only be assigned a value,
value but they cannot be
read
The SIGNALS
B Cpropagate
NO
Cin Cout As Cout is an output port, it cannot We have to introduce an explicit signal s_x8,
be read! Hence this is not a correct to make a correct implementation
implementation
The PORTS
39 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 40 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Different Implementations Operators
Extensive signal
g usage:
g “Merging”
g g of signals:
g To model the functionality of the system, VHDL provides several
s_x1
s_x2
<=
<=
A;
B; operators:
Logical:
s_x3 <= Cin;
s_x4 <= s_x1 XOR s_x2;
s_x5 <= s_x4 XOR s_x3; and or nand nor xor xnor not
SUM <= s_x5; SUM <= A XOR B XOR Cin;
Comparison:
s_x6 <= s_x1 AND s_x2; These operators we will use
s_x7 <= s_x3 AND s_x4; = /= < <= > >=
s_x8 <= s_x6 OR s_x7; s_x8 <= (A AND B) OR (Cin AND (A XOR B));
Cout <= s
s_x8;
x8; Cout <= s
s_x8;
x8; Concatenation:
s_x9 <= s_x8 AND s_x3; &
Cpropagate <= s_x9; Cpropagate <= s_x8 AND Cin;
Arithmetic: We will only use + and – of this set
+ - * / mod rem of operators
41 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 42 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
43 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 44 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Special Operations Back to the Full Adder
We can perform shifting by using concatenation LIBRARY ieee;
; LIBRARY ieee;
;
USE ieee.std_logic_1164.all; USE ieee.std_logic_1164.all;
SIGNAL s_x1 : std_logic_vector( 3 DOWNTO 0 ); USE ieee.std_logic_arith.all; USE ieee.std_logic_arith.all;
SIGNAL s_x2 : std_logic_vector( 3 DOWNTO 0 );
SIGNAL s_x3 : std_logic_vector( 3 DOWNTO 0 ); ENTITY full_adder IS ENTITY full_adder IS
PORT ( A : IN std_logic; -- A input PORT ( A : IN std_logic; -- A input
s_x1
s x1 <
<= s
s_x2(
x2( 2 DOWNTO 0 ) & ”0”; -- s
s_x1
x1 is s
s_x2
x2 << 1; hence s
s_x1
x1 = s
s_x2*2…
x2*2 B : IN std
std_logic;
logic; -- B input B : IN std
std_logic;
logic; -- B input
s_x3 <= s_x2(3) & s_x2( 3 DOWNTO 1 ); -- s_x3 is signed(s_x2) >> 1; hence s_x3 = s_x2/2… Cin : IN std_logic; -- Carry input Cin : IN std_logic; -- Carry input
SUM : OUT std_logic; -- Sum output SUM : OUT std_logic; -- Sum output
We can use concatenation to extract the carry out Cprop: OUT std_logic; -- Carry propagate Cprop: OUT std_logic; -- Carry propagate
Cout : OUT
END full_adder;
std_logic); -- Carry output
? Cout : OUT
END full_adder;
std_logic); -- Carry output
=
SIGNAL s
s_a
a : std
std_logic;
logic;
SIGNAL s_b : std_logic;
ARCHITECTURE implementation_1 OF full_adder IS ARCHITECTURE implementation_1 OF full_adder IS
SIGNAL s_add : std_logic_vector( 1 DOWNTO 0 );
SIGNAL s_sum : std_logic;
SIGNAL s_x8 : std_logic; SIGNAL s_x8 : std_logic;
SIGNAL s_cout: std_logic;
BEGIN BEGIN
s_add <= unsigned(”0” & s_a) + unsigned(”0” & s_b);
SUM <= A XOR B XOR Cin; Cprop <= s_x8 AND Cin;
s_sum <= s_add(0);
s_x8 <= (A AND B) OR (Cin AND (A XOR B)); SUM <= A XOR B XOR Cin;
s_cout <= s_add(1);
Cout <= s_x8; Cout <= s_x8;
Cprop <= s_x8 AND Cin; s_x8 <= (A AND B) OR (Cin AND (A XOR B));
Important
p note: END implementation_1; END implementation_1;
Process 2 is sensitive to A,B and Cin Process 4 is sensitive to s_x8 and Cin
Intuition:
All elements in hardware will execute A process is triggered if one or more wires, to which the process is
in parallel, hence the processes must
also
l execute t in
i parallel
ll l sensitive change its/their value
sensitive,
47 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 48 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Delta Delta
Assume that every PROCESS has an input to output delay of δ We assumed the input and output delay to be δ, but in reality δ Æ 0
If A, B, and/or Cin change(s) at time t1, this is how simulation goes Delta is defined as the number of δ steps we need to take until all
s_x9 PROCESS’es produce a stable output (no process is triggered):
Note:
A P1 P5 OSC δ does not PROCESS 1 and d 2 produce
d a stable
t bl output
t t after
ft DDelta
lt = 1
B SUM include the gate PROCESS 3 and 4 produce a stable output after Delta = 2
s_x8 delays, as we are
P2
P3
3 Cout working with a PROCESS 5 does not p produce a stable output,
p , as it is triggered
gg over
zero delay model! and over again
Cin P4 Cprop
An ARCHITECTURE which does not produce a stable output on all
its PROCESS
PROCESS’eses, after a finite number of δ steps,
steps is called instable,
instable
And this continues
The change on A triggers A and cannot be simulated.
process 1 and process 2 B infinitely
Cin We will only use stable ARCHITECTURE’s,
After one δ process 1 and
OSC h
hence Delta
D l isi finite
fi i Notes:
SUM 1. We can of course model oscillators (instable
process 2 produce a After two δ process 3 and
s_x8 architectures), by also modeling the gate delay,
stable output, and trigger 4 produce stable outputs,
Cout but process 5 is triggered
but this is outside the scope
p of this course
processes 3
3, 4 and 5
Cprop by s_x9
2. Instable architectures can be implemented in
t1
hardware, and are thus synthesizable
49 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 50 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
BEGIN
[Process description] This are so called implicit PROCESS’s
END PROCESS <process_name>;
Implicit form Implicit PROCESS’es are by definition sensitive to all
SIGNAL’s ’ listed
li t d in
i the
th <source>, andd thus
th are
<signal_name> <= <source>;
triggered by a change on these signals
Implicit PROCESS
PROCESS’es es are not embedded into a PROCESS
Or a component: container
In implicit PROCESS’es the <source> consists of
<component_reference>
<component reference> : <component_name>
<component name>
GENERIC MAP ( [generic mappings] )
signals and operators
PORT MAP ( [Port connections] ); There exists a special implicit PROCESS, the WHEN …
ELSE …; construct
51 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 52 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Implicit Constructs Summary
<sourcen>;
…
The operators define the functionality of the system
Question:
Example: What is the hardware representing this construct?
SIGNAL’s may only be assigned once
Answer:
next_state <= green WHEN state = red_orange OR <source1> 1
(state = green AND
button /= ‘1’) ELSE
<signal_name> Each element in the body of an ARCHITECTURE is a
PROCESS or a COMPONENT
<source2> 0
orange WHEN state = green AND
button = ‘1’ ELSE
red WHEN state = orange ELSE <condition>
es and COMPONENT
COMPONENT’ss execute in parallel
red_orange;
PROCESS
PROCESS’es
53 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 54 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
3 Reminder
Processes and Components
BEGIN
[Process description]
END PROCESS <process_name>;
Implicit form
Explicit processes
Latches <signal_name> <= <source>;
Flip flops and Registers
Flip-flops
Or a component:
Components
<component_reference>
<component reference> : <component_name>
<component name>
GENERIC MAP ( [generic mappings] )
PORT MAP ( [Port connections] );
55 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 56 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Explicit Process Explicit Process Syntax
A PROCESS which is not implicit is called an Each PROCESS has a Each PROCESS can have
explicit PROCESS unique name a sensitivity list
only
l combinatorial
bi t i l logic
l i [Declaration Section]
Note:
We can also just write END PROCESS;
57 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 58 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
=
ARCHITECTURE implementation
p _2 OF full_adder IS
SIGNAL s_x8 : std_logic;
BEGIN
61 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 62 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
=
s_x8 <= (A AND B) OR (Cin AND (A XOR B)); SUM <= A XOR B XOR Cin;
Using <
<= in a statement means schedule an assignment
Cout <= s_x8; Cout <= s_x8;
Cprop <= s_x8 AND Cin; s_x8 <= (A AND B) OR (Cin AND (A XOR B));
END implementation_1; END implementation_1;
The explicit process has some “strange” behavior when it comes to
What about the explicit
p PROCESS’s: signals
g The process “fixes”
fixes the values of the signals when
BEGIN BEGIN
adder : PROCESS( A , B , Cin ) adder : PROCESS( A , B , Cin ) it is triggered
?
example : PROCESS( A , B , C )
The statements within the process schedule
VARIABLE v_x8 : std_logic; VARIABLE v_x8 : std_logic;
BEGIN BEGIN BEGIN
C <= A OR B; new assignments to a signal
=
SUM <= A XOR B XOR Cin; Cprop <= v_x8 AND Cin;
v_x8 := (A AND B) OR (Cin AND (A XOR B)); SUM <= A XOR B XOR Cin; IF (A AND B) = ’1’ THEN
Cout <= v_x8; Cout <= v_x8; C <= ’0’; The process assigns the new values of the signals
when it is finished
Cprop <= v_x8 AND Cin; v_x8 := (A AND B) OR (Cin AND (A XOR B)); END IF;
END PROCESS adder; END PROCESS adder; X2 <= C;
END PROCESS example;
END implementation_2; END implementation_2;
Hence, X2 is assigned the old value of C
Th
These two
t implementations
i l t ti are nott equal!
l!
Note further that X2 and C are only assigned once a value,
Due to the fact that these are now inside the body of the process, they are namely at the end of the PROCESS
not any longer separate processes,
processes but statements.
statements And statements
execute in program order inside the body of an explicit process, and not
in parallel! We will go into more detail
63 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 64 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Statements and Variables Explicit Constructs
It
It’ss getting even more “strange”
strange , as VARIABLE’ss are Similar to the WHEN … ELSE …;
; construct,
construct we have the
assigned immediately in explicit PROCESS’es, hence := IF … END IF; construct in an explicit process:
means assign g immediately y
Thus IMPORTANT:
:= can ONLY be used with variables! IF <condition> THEN [Statement(s)]; This version should only be used
END IF; to model sequential logic
example : PROCESS( A , B , C )
(
(we will
ill see more in
i the
th nextt lecture)
l t )
VARIABLE v_x : std_logic; IF <condition> THEN [Statement(s)];
BEGIN ELSE [Statement(s)];
v_x := A OR B; END IF;
IF (A AND B) = ’1’
1 THEN The difference with Signals and Variables,
Variables is that
v_x := ’0’; v_x is now assigned immediately a value, and not IF <condition> THEN [Statement(s)]; Each of these sections should
END IF; just scheduled a new assignment! ELSIF <condition2> THEN [Statement(s)];
X2 <= v_x; contain at least one, but can
ELSE [Statement(s)]; contain multiple statements
c <= v_x;; END IF;
END PROCESS example;
65 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 66 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Cin s_x8
Cout
Operators Æ to model the functionality of the system the architecture ENTITY full_adder
full adder IS
PORT ( A : IN std_logic; -- A input
PROCESS’es Æ which execute in parallel, and can be of two B : IN
Cin : IN
std_logic;
std_logic;
--
--
B input
Carry input
forms SUM : OUT
Cprop: OUT
std_logic;
std_logic;
--
--
Sum output
Carry propagate
Implicit: These processes are not contained in a PROCESS container Cout : OUT std_logic); -- Carry output
and are in the form <signal_name> <= <source> END full_adder;
Explicit: These processes are in a PROCESS container, and the ARCHITECTURE implementation_1 OF full_adder IS We have three
The order of the process implicit processes
statements in these pprocesses execute in program
p g order (implicit and explicit) SIGNAL s
s_x8
x8 : std
std_logic;
logic;
Statements Æ help to express conditional logic (= does not matter as they BEGIN
multiplexing) execute in parallel
SUM <= A XOR B XOR Cin;
Implicit usage only: The WHEN … ELSE … construct Cout <= s_x8;
Explicit usage only: The IF … END IF; and CASE … END CASE;
C
Cprop <
<= s_x8
8 AND Ci
Cin;
69 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 70 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Latches Latches
Let
Let’ss look at the simulation behavior
latch : PROCESS ( clock , d )
latch : PROCESS ( clock , d )
BEGIN d q
IF (
(clock = ’1’)
) THEN BEGIN d q
q <= d; IF (clock = ’1’) THEN
END IF; q <= d;
clock END IF;
END PROCESS latch;
END PROCESS latch; clock
71 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 72 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Latches vs
vs. Muxes Combinatorial or Sequential?
Both latches and multiplexers
p are described through
g IF statements latch : PROCESS ( clock , d ) mux : PROCESS ( s , in0 , in1 )
BEGIN
BEGIN IF (s = ’1’) THEN
latch : PROCESS ( clock , d ) mux : PROCESS ( s , in0 , in1 ) IF (clock = ’1’) THEN out <= in1;
q <= d; ELSE
BEGIN BEGIN out <= in0;
IF (clock = ’1’)
1 ) THEN IF (s = ’1’)
1 ) THEN END IF;
END IF;
q <= d; out <= in1; END PROCESS latch; END PROCESS mux;
END IF; ELSE
END PROCESS latch; out <= in0; start start
END IF;
END PROCESS mux;
d q clock ? S ?
in0
out
in1 assign q assign out assign out
clock
s
The important difference is that in muxes there is always a new end end
value assigned to signals or variables, whereas in latches
At least one path between start and end of the All paths between start and end of the process
sometimes nothingg is assigned
g and theyy keepp their old value process contains no assignment to q contain at least one assignment to out
(Æ memory!) Î q is the output of a Î out is the output a
sequential element combinatorial element
73 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 74 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
An EVENT should always be used in combination with a test for the If there is no transition or clock equals 0, q will not be scheduled
current level,
level because
beca se the
there
eeexists
ists no hardware component any value
l because
b the
h IF statement is skipped.
k d Therefore
h f at the
h
which is triggered by both transitions end of the PROCESS, q will keep its previous value!
IF <signal
g _name>’EVENT THEN
…
END IF;
? We also described a memory element, but this time it is a flip-flop
75 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 76 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Flip-flops and Registers A Bad Idea for a Flip-Flop
Let
Let’ss look at the simulation behavior One could think of exploiting the sensitivity list…
list
?
IF (clock’EVENT AND clock = ’1’) THEN IF (clock’EVENT AND clock = ’1’) THEN
synchronous or asynchronous
Synchronous reset IF (reset = ’1’) THEN s_q1 <= ’0’; IF (reset = ‘1’) THEN s_q1 <= ’0’;
reset
=
s_q
q2 <= ’0’;
; s_q
q2 <= ’0’;
;
flipflop : PROCESS ( clock , reset , d ) q3 <= ’0’; q3 <= ’0’;
BEGIN ELSE q3 <= s_q2; ELSE s_q1 <= d;
IF (clock’EVENT and clock = ’1’) THEN 0 s_q2 <= s_q1; s_q2 <= s_q1;
IF (reset = ’1’) THEN q <= ’0’; d q s_q1 <= d; q3 <= s_q2;
ELSE q <= d; END IF; END IF;
END IF; END IF; END IF;
END IF; END PROCESS Delay_line; END PROCESS Delay_line;
END PROCESS flipflop;
YES!
The two processes are identical
Asynchronous reset reset
0 0 0
flipflop : PROCESS ( clock , reset , d )
d D Q D Q D Q q3
BEGIN q s_q1 s_q2
IF (reset = ’1’) THEN q <= ’0’; d
ELSIF (clock’EVENT and clock = ’1’) THEN
q <= d; reset
END IF;
END PROCESS flipflop;
clock
79 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 80 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Registers Variables,
Registers, Variables and Ordering Components
Delay_line : PROCESS ( clock , reset , d , Delay_line : PROCESS ( clock , reset , d ,
s_q
q1 )
VARIABLE v_q2 : std_logic;
s_q
q1 )
VARIABLE v_q2 : std_logic;
We can introduce a hierarchy by using COMPONENT
COMPONENT’ss
BEGIN BEGIN
A COMPONENT is a reference to an ENTITY
?
IF (clock’EVENT AND clock = ’1’) THEN IF (clock’EVENT AND clock = ’1’) THEN
IF (reset = ’1’) THEN s_q1 <= ’0’; IF (reset = ’1’) THEN s_q1 <= ’0’;
v q2 := ’0’;
v_q2
q3
0 ;
<= ’0’; =
v q2 := ’0’;
v_q2
q3
0 ;
<= ’0’;
The syntax of a COMPONENT is
ELSE q3 <= v_q2; ELSE s_q1 <= d;
v_q2 := s_q1; v_q2 := s_q1;
s_q1 <= d; q3 <= v_q2; Each COMPONENT requires
q a
END IF; END IF;
END IF; END IF;
COMPONENT <entity_name>
PORT ( … );
reference to the corresponding
END PROCESS Delay_line; END PROCESS Delay_line;
END COMPONENT; ENTITY
NO!
The two processes are different!
Each COMPONENT has the same
reset reset
0 0
port section as it’s corresponding ENTITY
0 0 0
D Q s_q1 D Q v_q2 D Q q3 D Q s_q1 D Q q3
clock
an ARCHITECTURE
clock
81 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 82 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Summary
Usage of Components Signals Variables,
Signals, Variables and Parallelism
LIBRARY ieee;
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
For a SIGNAL, the <
<= has a different meaning in an implicit
USE ieee.std_logic_arith.all;
ENTITY adder IS
PROCESS, and when used in a statement (explicit PROCESS)
ENTITY full_adder IS
PORT ( A : IN std_logic; -- A input
PORT ( A
B
:
:
IN
IN
std_logic_vector( 3 DOWNTO 0);
std_logic_vector( 3 DOWNTO 0);
Using <= in an implicit PROCESS means assign immediately
B : IN
Cin : IN
std
std_logic;
logic;
std_logic;
--
--
B input
Carry input
Cin :
SUM :
IN
OUT
std
std_logic;
logic;
std_logic_vector( 3 DOWNTO 0); Using <
<= in an explicit PROCESS means schedule an assignment
SUM : OUT std_logic; -- Sum output Cout : OUT std_logic);
Cout : OUT std_logic); -- Carry output END adder;
a unique identifier
PORT MAP ( A
B
=> A(n),
=> B(n), Statements are defined inside the body of an explicit PROCESS, and
And here we connect the PORT
PORT’ss of the
Cin => s_carries(n),
SUN => SUM(n), execute in program order
Cout => s_carries(n+1) );
component with the SIGNAL’s to form the new END GENERATE fas;
functionality END implementation;
83 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007 84 VHDL — A Compact Overview © Sanchez, Ienne, Kluter 2007
Summary
Sequential Components
Sequential elements can only be made by using an explicit PROCESS
Flip-flops:
p p
flipflop : PROCESS ( clock , d )
BEGIN
IF (clock’EVENT and clock = ’1’) THEN d q
q <= d;
END IF;
;
END PROCESS flipflop;