26 October - 20 November, 2009: FPGA Architectures & VHDL Introduction To Synthesis
26 October - 20 November, 2009: FPGA Architectures & VHDL Introduction To Synthesis
26 October - 20 November, 2009: FPGA Architectures & VHDL Introduction To Synthesis
Nizar Abdallah
ACTEL Corp.2061 Stierlin Court Mountain View
CA 94043-4655
U.S.A.
FPGA Architectures & VHDL
Nizar Abdallah
nizar@ieee.org
October 2009
FPGA Architectures & VHDL
Introduction to FPGAs & FPGA design flows
Introduction to Synthesis
The VHDL hardware description language
Design verification, validation, and testing
Behavior
Dataflow Timing
Structure
RTL
Layout
CONTROLFLOW ≠ DATAFLOW
CONTROLFLOW ≠ DATAFLOW
9 YES 8 NO
--
-- component
component declaration
declaration Structural
component
component DFFDFF
port
port (( D,
D, CLR,
CLR, CLK
CLK :: in
in std_logic;
std_logic;
QQ :: out
out std_logic);
std_logic);
end
end component;
component;
--
-- component
component instantiation
instantiation
U1:
U1: DFF
DFF
port
port map
map (D
(D =>=> DATA,
DATA, CLR
CLR =>
=> RESET,
RESET, CLK
CLK =>
=> CLK,
CLK, QQ =>
=> OUT);
OUT);
Entity
Architecture
Configuration
Package
Library
MUX2
AIN
YOUT
BIN
SIN
entity MUX2 is
port (AIN, BIN, SIN : in std_logic;
YOUT : out std_logic);
end MUX2;
Port Port
mode type
Cin A B
entity FULL_ADDER is
port (A, B, Cin : in BIT
BIT;; FULL
S, Cout : out BIT );
BIT); ADDER
end FULL_ADDER;
Port
mode Port
type S Cout
Entity
Architecture
Configuration
Package
Library
architecture
architecture TWOTWO of
of MUX2
MUX2 is
is Structural
Structural
component
component MX2
MX2 --
-- aa macro
macro from
from aa library
library
port
port (A,
(A, B,
B, S:in
S:in std_logic;
std_logic; Declarative
YY :out
:out std_logic);
std_logic); part
end
end component;
component;
begin
begin
--
-- instantiate
instantiate MX2
MX2
U1:
U1: MX2
MX2 Descriptive
port
port map(A=>AIN,
map(A=>AIN, B=>BIN,
B=>BIN, S=>SIN, Y=>YOUT); part
S=>SIN, Y=>YOUT);
end
end TWO;
TWO;
entity-architecture
entity-architecture
Structural
Behavioral
CIN A B
FULL
ADDER
XX <=
<= AA xor
xor B;
B;
SS <=
<= XX xor
xor CIN;
CIN;
COUT
COUT <=
<= (A(A and
and B)
B) or
or
(X
(X and
and CIN);
CIN);
S COUT
Entity
Architecture
Configuration
Package
Library
library ieee;
use ieee.std_logic_1164.all;
IEEE Library
std_logic_1164
Requires LIBRARY and
USE statements
std_logic_arith
std_logic_unsigned
A STD
N
IEEE SIMULATOR
A
VHDL L PROJECT_LIB
files Y WORK
Z SYNTHESIZER
E
R
library library_name ;
use library_name.package_name.all;
library ieee;
use ieee.std_logic_1164.all; Declare the library
use ieee.std_logic_unsigned.all; and packages
entity
entity MULT
MULT is
is
port(A:
port(A: in
in std_logic_vector(3
std_logic_vector(3 downto
downto 0);
0); Now we can use
B:
B: in
in std_logic_vector(3
std_logic_vector(3 downto
downto 0);
0); std_logic_vector
Y:
Y: out
out std_logic_vector(7
std_logic_vector(7 downto
downto 0));
0)); types and unsigned
end
end MULT;
MULT;
arithmetic
architecture
architecture TESTTEST of
of MULT
MULT is
is
begin
begin
YY <=
<= AA ** B;
B;
end
end TEST;
TEST;
Type
.. .. ..
architecture
architecture TEST
TEST of
of EXAMPLE
EXAMPLE is
is
signal
signal SIG1:
SIG1: std_logic
std_logic ;; Declaration
begin
begin
SIG1
SIG1 <=<= AA and
and B;
B; Notice: A, B, C, and OUT1
OUT1
OUT1 <=<= SIG1
SIG1 xor
xor C;
C; are not Signals; They are
end
end TEST;
TEST; Ports declared in the Entity.
S2
S2 is
is aa 3-bit
3-bit vector
vector
……
architecture
architecture BEHAVE
BEHAVE of
of COUNTER
COUNTER is
is
signal
signal S1:
S1: std_logic_vector(7
std_logic_vector(7 downto
downto 0);
0);
signal
signal S2:
S2: std_logic_vector(2
std_logic_vector(2 downto
downto 0);
0);
signal
signal S3:
S3: std_logic;
std_logic;
port
port (P:
(P: inin std_logic_vector(0
std_logic_vector(0 to
to 3);
3);
R:
R: out
out std_logic_vector(8
std_logic_vector(8 downto
downto 0);
0);
……
Declaration Direction and
architecture
architecture BEHAVE
BEHAVE of
of EXAMPLE
EXAMPLE is
is
Slice Direction must be the
……
same. (P is up; R is down)
R(5
R(5 downto
downto 3)
3) <=
<= P(0
P(0 to
to 2);
2);
R(5) P(0)
R(4) P(1)
Size of slices must match R(3) P(2)
architecture
architecture BEHAVE
BEHAVE of
of COUNTER
COUNTER is
is
begin
begin
process(clk)
process(clk)
variable
variable cntr:
cntr: integer
integer range
range 00 to
to 63
63 :=
:= 0;
0;
begin
begin
architecture
architecture BEHAVE
BEHAVE of
of MUX
MUX is
is
constant
constant LOW:
LOW: bit_vector(1
bit_vector(1 downto
downto 0)
0) :=
:= “00”;
“00”;
begin
begin
architecture
architecture MACHINE
MACHINE of
of TRAFFIC_LIGHT
TRAFFIC_LIGHT is
is
type
type STATE
STATE is
is (RED,
(RED, YELLOW,
YELLOW, GREEN);
GREEN);
signal
signal CURRENT_STATE,
CURRENT_STATE, NEXT_STATE:
NEXT_STATE: STATE;
STATE;
begin
begin
PRECEDENCE ORDER
library
library ieee;
ieee;
use
use ieee.std_logic_1164.all;
ieee.std_logic_1164.all;
entity
entity LOGIC
LOGIC isis
port
port (A,
(A, B,
B, C:
C: inin std_logic;
std_logic;
Y,
Y, ZZ :: out
out std_logic);
std_logic);
end
end LOGIC;
LOGIC;
architecture
architecture BEHAVE
BEHAVE of
of LOGIC
LOGIC is
is
begin
begin
ZZ <=
<= AA and
and B;
B;
YY <=
<= (A
(A and
and B)
B) or
or not
not C;
C; A
B
end
end BEHAVE;
BEHAVE; C Y
entity
entity MULT
MULT is
is
A
port(A:
port(A: in
in std_logic_vector(3
std_logic_vector(3 downto
downto 0);
0);
* B:
B: in
in std_logic_vector(3
std_logic_vector(3 downto
downto 0);
0);
B Y:
Y: out
out std_logic_vector(7
std_logic_vector(7 downto
downto 0));
0));
end
end MULT;
MULT;
architecture
architecture BEHAVE
BEHAVE of
of MULT
MULT is
is
begin
begin
YY <=
<= AA ** B;
B;
end
end BEHAVE;
BEHAVE;
entity
entity ADDER
ADDER is
is
A port(
port(
A,
A, BB :: in
in std_logic_vector(7
std_logic_vector(7 downto
downto 0);
0);
+ SS :: out
out std_logic_vector(8
std_logic_vector(8 downto
downto 0)
0)
B );
);
end
end adder;
adder;
architecture
architecture BEHAVIORAL
BEHAVIORAL of
of ADDER
ADDER is
is
begin
begin
SS <=
<= (A(7)
(A(7) && A)
A) ++ (B(7)
(B(7) && B);
B);
end
end BEHAVIORAL;
BEHAVIORAL;
Y <= A; -- in process1
and, Y <= B; -- in process2
Concept of a Resolution Function; attached to a signal or a
type, and is called every time the value of signal needs to be
determined -- that is every time a driver changes value
YY <=
<= IN1
IN1 when
when SS == ‘0’
‘0’ else
else
“else” clause is required
IN2
IN2 when
when SS == ‘1’
‘1’ else
else
‘0’;
‘0’;
YY <=
<= “00”
“00” when
when COUNT
COUNT >=
>= 88 else
else
“11”;
“11”;
Example:
with
with DATAIN
DATAIN select
select --
-- selected
selected signal
signal assignment
assignment
YY <=
<= IN0
IN0 when
when “00”,
“00”,
Note that
commas are
IN1
IN1 when
when “01”,
“01”,
IN2
IN2 when
when “10”,
“10”, used here.
IN3
IN3 when
when others;
others;
library
library ieee;
ieee;
use
use ieee.std_logic_1164.all;
ieee.std_logic_1164.all;
entity
entity MY_TRI
MY_TRI is
is A(0) Y(0)
port(A:
port(A: in
in std_logic_vector(3
std_logic_vector(3 downto
downto 0);
0);
EN
EN:
EN: in
in std_logic;
std_logic;
Y:
Y: out
out std_logic_vector(3
std_logic_vector(3 downto
downto 0));
0)); A(1) Y(1)
end
end MY_TRI;
MY_TRI; EN
A(2) Y(2)
architecture
architecture BEHAVE
BEHAVE of
of MY_TRI
MY_TRI is
is
begin
begin EN
YY <=
<= AA when
when EN
EN == ‘1’
‘1’ else
else
A(3) Y(3)
(others
(others =>
=> ‘Z’)
‘Z’) ;;
end
end BEHAVE;
BEHAVE; EN
library
library ieee;
ieee;
use
use ieee.std_logic_1164.all;
ieee.std_logic_1164.all;
A B C Y
entity
entity TRUTH_TABLE
TRUTH_TABLE is is
port(A,
port(A, B,B, C:
C: inin std_logic;
std_logic;
0 0 0 1
Y:
Y: out
out std_logic)
std_logic) ;;
0 0 1 0
end
end TRUTH_TABLE;
TRUTH_TABLE;
0 1 0 1
architecture
architecture BEHAVE
BEHAVE of
of TRUTH_TABLE
TRUTH_TABLE is
is
0 1 1 0
signal
signal S1:
S1: std_logic_vector(2
std_logic_vector(2 downto
downto 0);
0);
1 0 0 1
begin
begin
1 0 1 0
S1
S1 <=
<= AA && BB && C;
C; --
-- concatenate
concatenate A,
A, B,
B, CC
1 1 0 - with
with S1
S1 select
select
1 1 1 - YY <=
<= ‘1’
‘1’ when
when “000”
“000” || “010”
“010” || “100”
“100” ,,
‘0’
‘0’ when
when “001”
“001” || “011”
“011” || “101”,
“101”,
‘-’ means don’t care ‘-’
‘-’ when
when others;
others;
end
end BEHAVE;
BEHAVE;
“|” means OR only when
used in “with” or “case”
latch
latch :: block
block (( CLK
CLK == '1'
'1' ))
begin
begin
QQ <=
<= GUARDED
GUARDED DD ;;
end
end block
block latch
latch ;;
D Q
LATCH
CLK
Syntax:
assert
assert condition
condition
[[ report
report error_message
error_message ]]
[[ severity
severity severity_level
severity_level ]] ;;
Syntax:
[[ label
label :: ]] process
process [[ (( sensitivity_list
sensitivity_list )) ]]
{{ process_declarative_part
process_declarative_part }}
begin
begin
{{ sequential_statements
sequential_statements }}
end
end process
process [[ label
label ]] ;;
process
begin
sequential_statement_1 ;
sequential_statement_2 ;
-----------
sequential_statement_n ;
end process;
Process label
(recommended) Sensitivity list
PQR:process (A, B, C)
begin
X <= A and B;
if (B = ‘1’) then
Statements
Y <= A xor C;
executed
else
sequentially
Y <= A xnor C;
end if;
end process PQR;
Syntax:
target_variable
target_variable :=
:= expression
expression ;;
Syntax:
target_signal
target_signal <=
<= [[ transport
transport ]] expression
expression [[ after
after time
time ]] ;;
signal S
signal S :: BIT
BIT :=
:= '0'
'0' ;; signal S
signal S :: BIT
BIT :=
:= '0'
'0' ;;
process
process process
process
SS <=
<= '1'
'1' after
after 55 ns
ns ;; SS <=
<= '0'
'0' after
after 10
10 ns
ns ;;
SS <=
<= '0'
'0' after
after 10
10 ns
ns ;; SS <=
<= '1'
'1' after
after 55 ns
ns ;;
end ;
end ; end ;
end ;
signal S
signal S :: BIT
BIT :=
:= '0'
'0' ;; signal S
signal S :: BIT
BIT :=
:= '0'
'0' ;;
process
process process
process
SS <=
<= '1'
'1' after
after 55 ns
ns ;; SS <=
<= '0'
'0' after
after 10
10 ns
ns ;;
SS <=
<= '0'
'0' after
after 10
10 ns
ns ;; SS <=
<= '1'
'1' after
after 55 ns
ns ;;
end ;
end ; end ;
end ;
5 10 time 5 10 time
if
if CONDITION
CONDITION then
then
--sequential
--sequential statements
statements
end
end if;
if;
if
if CONDITION
CONDITION then
then
--sequential
--sequential statements
statements
else
else
--sequential
--sequential statements
statements
end
end if;
if;
if
if CONDITION
CONDITION then
then
--sequential
--sequential statements
statements
More than one elsif allowed elsif
elsif CONDITION
CONDITION then
then
“elsif” is one word --sequential
--sequential statements
statements
elsif
elsif CONDITION
CONDITION then
then
--sequential
--sequential statements
statements
Only one else allowed else
else
--
-- sequential
sequential statements
statements
“end if” is two words end
end if;
if;
case
case (SELECTOR)
(SELECTOR) is
is
when
when value
value =>
=>
--sequential
--sequential statements
statements
when
when value1
value1 || value2
value2 || value3
value3 =>
=>
--sequential
--sequential statements
statements
when
when value1
value1 to
to value2
value2 =>
=>
--sequential
--sequential statements
statements
when
when others
others =>
=>
--sequential
--sequential statements
statements
end
end case;
case;
‘when SELECTOR falls within the range from value1 to value2, then ...’’
library
library ieee;
ieee;
use
use ieee.std_logic_1164.all;
ieee.std_logic_1164.all;
entity
entity CASE_MUX
CASE_MUX is is
port
port (C,
(C, D,D, E,
E, F:
F: in
in std_logic;
std_logic; 4:1 Multiplexer
SS :: in
in std_logic_vector(1
std_logic_vector(1 downto
downto 0);
0);
MUX_OUT
MUX_OUT :: out
out std_logic
std_logic );
);
end
end CASE_MUX;
CASE_MUX;
architecture
architecture BEHAVE
BEHAVE of
of CASE_MUX
CASE_MUX is
is C
begin
begin D MUX_OUT
mux1:
mux1: process
process (S,
(S, C,
C, D,
D, E,
E, F)
F) E
begin
begin F
case
case SS is
is
when
when “00”
“00” =>
=> MUX_OUT
MUX_OUT <=
<= C;
C;
when
when “01”
“01” =>
=> MUX_OUT
MUX_OUT <=
<= D;
D; S(1:0)
when
when “10”
“10” =>
=> MUX_OUT
MUX_OUT <=
<= E;
E;
when
when others
others =>
=> MUX_OUT
MUX_OUT <=
<= F;
F;
end
end case;
case;
end
end process
process mux1;
mux1;
end
end BEHAVE;
BEHAVE;
library
library ieee;
ieee;
use
use ieee.std_logic_1164.all;
ieee.std_logic_1164.all;
entity
entity BIBUF
BIBUF isis
port
port (A,
(A, E:E: in
in std_logic;
std_logic;
YY :: inout
inout std_logic;
std_logic;
BB :: out
out std_logic
std_logic ););
end
end BIBUF
BIBUF ;; E
architecture
architecture BEHAVE
BEHAVE ofof BIBUF
BIBUF is
is
begin
begin A Y
ONE:process
ONE:process (A,E)
(A,E)
begin
begin B
case
case EE isis
when
when ‘1’
‘1’ =>
=> YY <=
<= A;
A;
when
when ‘0’
‘0’ =>
=> YY <=
<= ‘Z’;
‘Z’;
when
when others
others =>=> YY <=
<= ‘X’;
‘X’;
end
end case;
case;
end
end process
process ONE;
ONE;
BB <=
<= Y;
Y;
end
end BEHAVE;
BEHAVE;