Professional Documents
Culture Documents
26 October - 20 November, 2009: VHDL & FPGA Architecturs Synthesis III - Advanced VHDL
26 October - 20 November, 2009: VHDL & FPGA Architecturs Synthesis III - Advanced VHDL
Nizar Abdallah
ACTEL Corp. 2061 Stierlin Court Mountain View
CA 94043-4655
U.S.A.
Lectures:
VHDL & FPGA Architectures
Outline
Introduction to FPGA & FPGA Design Flow
Synthesis I – Introduction
Synthesis II - Introduction to VHDL
Synthesis III - Advanced VHDL
Design verification & timing concepts
Programmable logic & FPGA architectures
Actel ProASIC3 FPGA architecture
process
process (SEL,
(SEL, A)
A)
begin
begin A latch Y
if
if (SEL
(SEL == ‘1’)
‘1’) then
then YY <=
<= A;
A;
end
end if
if ;; SEL
end
end process;
process;
--
-- sel,
sel, A,
A, BB are
are std_logic
std_logic SEL[1]
process
process (SEL,
(SEL, A,
A, B)
B)
begin
begin A
case
case SEL
SEL is
is latch Y
when
when “00”
“00” =>
=> YY <=
<= A;
A; B
when
when “10”
“10” =>
=> YY <=
<= B;
B;
when
when others
others =>
=> null;
null; SEL[0]
end
end case;
case;
end
end process;
process;
To avoid unwanted latches, actually define Y for the “others” condition, for example:
when others => Y <= ‘0’;
architecture
architecture BEHAVE
BEHAVE of
of DF
DF is
is
begin
begin
INFER:
INFER: process
process (CLK)
(CLK) begin
begin D Q
if
if (CLK’event
(CLK’event and
and CLK
CLK =‘1’)
=‘1’) then
then
QQ <=
<= D;
D;
end
end if
if ;;
end
end process
process INFER;
INFER; CLK
end
end BEHAVE;
BEHAVE;
D flip-flop with
asynchronous low
reset and active high
architecture
architecture FLOPFLOP of
of DFCLR
DFCLR is
is clock edge
begin
begin
INFER:
INFER: process
process (CLK,
(CLK, RST)
RST)
begin
begin
if D Q
if (RST
(RST =‘0’)
=‘0’) then
then
QQ <=
<= ‘0’;
‘0’;
elsif
elsif (CLK’event
(CLK’event and
and CLK
CLK =‘1’)
=‘1’) then
then
QQ <=
<= D;
D; CLK
end
end if
if ;; RST
end
end process
process INFER;
INFER;
end
end FLOP;
FLOP;
D flip-flop with
synchronous low reset,
architecture
architecture FLOPFLOP of
of DFSLRHE
DFSLRHE is
is active high enable and
begin
begin rising edge clock
INFER:
INFER: process
process (CLK)
(CLK)
begin
begin
if
if (CLK’event
(CLK’event and and CLK
CLK =‘1’)
=‘1’) then
then
if
if (SRST
(SRST == ‘0’)
‘0’) then
then D Q
QQ <=
<= ‘0’;
‘0’; EN
elsif
elsif (EN(EN == ‘1’)
‘1’) then
then
CLK
QQ <=
<= D;
D;
end SRST
end ifif ;;
end
end if
if ;;
end
end process
process INFER;
INFER;
end
end FLOP;
FLOP;
architecture
architecture FLOPFLOP of
of EN_FLOP
EN_FLOP is
is
begin
begin
INFER:process
INFER:process (CLK)(CLK) begin
begin
if
if (CLK’event
(CLK’event and and CLK
CLK =‘0’)
=‘0’) then
then
if
if (EN
(EN == ‘0’)
‘0’) then
then
QQ <=
<= D;D;
end
end ifif ;;
end
end ifif ;;
end
end process
process INFER;
INFER;
end
end FLOP;
FLOP;
library
library ieee;
ieee; 4-bit register
use
use ieee.std_logic_1164.all;
ieee.std_logic_1164.all; using WAIT
entity
entity DF_4
DF_4 isis statement
port
port (D:
(D: inin std_logic_vector(3
std_logic_vector(3 downto
downto 0);0);
CLK:
CLK: inin std_logic;
std_logic;
Q:
Q: out
out std_logic_vector(3
std_logic_vector(3 downto
downto 0));
0));
end
end DF_4
DF_4 ;; D[3:0] Q[3:0]
architecture
architecture FLOPFLOP of
of DF_4
DF_4 is
is
begin
begin
INFER:
INFER: process
process Where’s the sensitivity list?
begin
begin
CLK
wait
wait until
until (CLK’event
(CLK’event and
and CLK
CLK =‘1’);
=‘1’);
QQ <=
<= D;
D;
end
end process
process INFER;
INFER;
end
end FLOP;
FLOP;
CNT
8
8 2x1 8 D Q 8
MUX Q
+ 8
library
library ieee;
ieee;
use
use ieee.std_logic_1164.all;
ieee.std_logic_1164.all;
entity
entity SHIFTER
SHIFTER is
is
port(CLK,
port(CLK, DIN:
DIN: in
in std_logic;
std_logic;
Z:
Z: out
out std_logic_vector(7
std_logic_vector(7 downto
downto 0));
0)); A[6:0]
end
end SHIFTER;
SHIFTER;
architecture
architecture RTL
RTL of
of SHIFTER
SHIFTER is
is
DIN
signal
signal A:A: std_logic_vector(7
std_logic_vector(7 downto
downto 0);
0); D[7:0] Z[7:0]
begin
begin
process
process (CLK)
(CLK)
begin
begin
if
if (CLK'event
(CLK'event and
and CLK='1')
CLK='1') then
then
AA <=
<= AA (6
(6 downto
downto 0)
0) && DIN;
DIN; --
-- shift
shift left
left CLK
end
end if;
if;
end
end process;
process;
ZZ <=
<= A;
A;
end
end RTL
RTL
Definition:
State (t+1) <= F(i1,...,in,State(t))
Output <= F(i1,...,in,State(t))
VHDL & FPGA Architectures © 2005 Nizar Abdallah November, 2005 14
FSM: Two Machine Types
Moore
Moore Trans. Gen. O
Machine
Machine I
Func.
Func Func.
ck
Mealey
Mealey Trans. Gen. O
Machine
Machine I
Func.
Func Func.
ck
Current state
Asynchronous
reset
Third process
Output Outputs
Logic
(combinational)
0
E0 1
0
E1
0 0
1 0 1
E4
E2
1 E3
1
Architecture
Architecture automate
automate of
of counter
counter is
is
type
type STATE_TYPE
STATE_TYPE is
is (E0,
(E0, E1,
E1, E2,
E2, E3,
E3, E4);
E4);
signal
signal CURRENT_STATE,
CURRENT_STATE, NEXT_STATE:
NEXT_STATE: STATE_TYPE;
STATE_TYPE;
--
-- pragma
pragma CUR_STATE
CUR_STATE CURRENT_STATE;
CURRENT_STATE;
--
-- pragma
pragma NEX_STATE
NEX_STATE NEXT_STATE;
NEXT_STATE;
--
-- pragma
pragma CLOCK
CLOCK ck;
ck;
begin
begin
Process(CURRENT_STATE,
Process(CURRENT_STATE, I, I, reset)
reset)
begin
begin
if
if (reset
(reset == '1')
'1') then
then
NEXT_STATE
NEXT_STATE <=
<= E0;
E0;
OO <=
<= '0';
'0';
else
else
WHEN
WHEN E1
E1 =>
=>
if
if (I='1')
(I='1') then
then
NEXT_STATE
NEXT_STATE <=
<= E2;
E2;
else
else
NEXT_STATE
NEXT_STATE <=
<= E0;
E0;
end
end if;
if;
OO <=
<= '0';
'0';
WHEN
WHEN E3
E3 =>
=>
if
if (I='1')
(I='1') then
then
NEXT_STATE
NEXT_STATE <=
<= E4;
E4;
else
else
NEXT_STATE
NEXT_STATE <=
<= E0;
E0;
end
end if;
if;
OO <=
<= '0';
'0';
WHEN
WHEN others
others =>
=>
assert
assert ('1')
('1')
report
report "Illegal
"Illegal State";
State";
end
end case;
case;
end
end if;
if;
end
end process;
process;
CK
CK
II
O
O
Current
Current E0 E1 E2 E3 E4
Next
Next E1 E2 E3 E4 E4
Procedure
Use testbench or manually apply stimulus
Check for correct results and produce a trace file
Choices
Use vendor-specific stimulus file (non-portable)
Write generic VHDL testbench
assert
assert (Y
(Y >> 2)
2)
report
report “SETUP
“SETUP VIOLATION”
VIOLATION”
severity
severity Warning;
Warning;
Remember!
Processes with a sensitivity list cannot have a
WAIT statement
D_CLK
30 50 80 100
entity
entity TESTBENCH
TESTBENCH is
is Testbench entity does
not include ports
end
end TESTBENCH;
TESTBENCH;
architecture
architecture BEHAVE
BEHAVE of
of TESTBENCH
TESTBENCH is
is
Counter declared
component
component COUNTER
within testbench
COUNTER
port
port (CLK,CNT_EN,CLR:in
(CLK,CNT_EN,CLR:in std_logic;
std_logic;
Q:out
Q:out std_logic_vector(7
std_logic_vector(7 downto
downto 0));
0));
end
end component;
component;
signal
signal CLKIN,ENABLE,RESET:std_logic;
CLKIN,ENABLE,RESET:std_logic;
signal
signal Qout:std_logic_vector(7
Qout:std_logic_vector(7 downto
downto 0);
0);
begin
Counter instantiated
begin --
-- Instantiate
Instantiate Counter
Counter
U1:COUNTER
U1:COUNTER port
port map(CLK=>CLKIN,
map(CLK=>CLKIN, CNT_EN=>ENABLE,
CNT_EN=>ENABLE,
within testbench
CLR=>RESET,
CLR=>RESET, Q=>Qout);
Q=>Qout);
--
-- initialize
initialize inputs,
inputs, and
and toggle
toggle the
the reset
reset line
line
INIT:
INIT: process
process begin
begin
ENABLE
ENABLE <=
<= '1';
'1';
RESET
RESET <=<= '1';
'1';
wait
wait for
for 250
250 ns;
ns;
RESET
RESET <=<= '0';
'0';
wait
wait for
for 250
250 ns;
ns;
RESET
RESET <=<= '1';
'1';
wait;
wait; --
-- this
this instruction
instruction suspends
suspends the
the init
init process
process
end
end process
process INIT;
INIT;
--
-- process
process to
to cause
cause clock
clock to
to toggle
toggle (20
(20 MHz)
MHz)
CLK_TOG:
CLK_TOG: process
process begin
begin
CLKIN
CLKIN <=<= '0';
'0';
wait
wait for
for 25
25 ns;
ns;
CLKIN
CLKIN <=<= '1';
'1';
wait
wait for
for 25
25 ns;
ns;
end
end process
process CLK_TOG;
CLK_TOG;
end
end BEHAVE;
BEHAVE;
process
process (A,
(A, B,
B, SEL)
SEL)
begin
begin
if
if (SEL=‘1’)
(SEL=‘1’) then
then
OUT
OUT <=
<= A;
A;
else
else
OUT
OUT <=
<= B;
B;
end
end if;
if;
end
end process;
process;
process
process (A,
(A, B,
B, SEL)
SEL) process
process
begin
begin begin
begin
if
if (SEL=‘1’)
(SEL=‘1’) then
then OUT
OUT <=
<= A;
A; if
if (SEL=‘1’)
(SEL=‘1’) then
then
else
else OUT
OUT <=
<= B;
B; OUT
OUT <=
<= A;
A;
end
end if;
if; else
else
end
end process;
process; OUT
OUT <=
<= B;
B;
end
end if;
if;
wait
wait on
on A,
A, B,
B, SEL;
SEL;
end
end process;
process;
process
process
begin
begin
if
if (condition)
(condition)
wait
wait on
on CLK’event
CLK’event and
and CLK=1;
CLK=1;
end
end if;
if;
end
end process;
process;
process
process (A,
(A, B)
B)
begin
begin
wait
wait until
until CLK’event
CLK’event and
and CLK=1;
CLK=1;
if
if (COUNT
(COUNT >=
>= 9)
9) then
then
COUNT
COUNT <=
<= 0;
0;
else
else
COUNT
COUNT <=
<= COUNT
COUNT +1;
+1;
end
end if;
if;
end
end process;
process;
process
process Process
Process (CLK,
(CLK, RST)
RST)
begin
begin begin
begin
wait
wait until
until CLK’event
CLK’event and
and CLK=1;
CLK=1; if
if (RST=‘1’)
(RST=‘1’) then
then
if
if (RST=‘1’)
(RST=‘1’) then
then --
-- asynchronous
asynchronous reset
reset
--
-- synchronous
synchronous reset
reset elsif
elsif (CLK’event
(CLK’event and
and
else
else CLK=1)
CLK=1) then
then
--
-- combinational
combinational code
code --
-- combinational
combinational code
code
end
end if;
if; end
end if;
if;
end
end process;
process; end
end process;
process;
process(A,
process(A, B, B, C,C, SEL)
SEL) Process
Process (A,(A, B,
B, C,
C, SEL)
SEL)
begin
begin variable
variable tmp:
tmp: bit;
bit;
if
if (SEL=‘1’)
(SEL=‘1’) thenthen begin
begin
ZZ <= SEL
<= AA ++ B;
B; if
if (SEL=‘1’)
(SEL=‘1’) then
then
else
else C tmp
tmp :=
:= B;
B;
+ SEL
ZZ <=
<= AA ++ CC A else
else
end if;
end if; + tmp
tmp :=
:= C;
C; B
end
end process;
process; B end
end if;
if;
ZZ <= C
<= AA ++ tmp;
tmp; +
end
end process;
process; A