Professional Documents
Culture Documents
[VHDL]
Charoen Vongchumyen
Computer engineering
King Mongkut’s Institute of Technology Ladkrabang, Thailand
Jan 2010
2 VHDL : Tong+ Jan 2010
VHDL
What is VHDL?
“The VHDL is
“Th i a software
ft programmingi language
l usedd to
t
model the intended operation of a piece of hardware, similar
t Verilog-HDL.”
to V il HDL ”
U off th
Use the VHDL LLanguage
1. Documentation Language: To provide human and machine
readable
d bl documentation
d i
2. Design Language: To provide a structure reflecting
hardware design and hierarchy and provide methods to
handle complexity by partitioning the design.
S
System D
Design
i S Specification
ifi i
Hardware/Software
Co Design
Co-Design
Hardware Design
g Software Design
Specification Specification
ASIC
FPGA
Boards and
PLD Systems
Std Parts
The top-level
top level system is modeled for
uP ROM RAM
ASIC1 ASIC2 FPGA functionality and performance using a high-
A B
level behavioral description.
p
RTL code RTL code
C
RTL code
ASIC
RTL
synthesis
RTL
synthesis
RTL
synthesis Each major component is modeled at the
behavioral level and the design is simulated
again for functionality and performance.
ASIC
Test synthesis
Faster
simulation/entry
i l ti / t Less detailed
Behavioral
RTL
Logic
Layout
L t
Slower More detailed
simulation/entry
D
Design
i att a higher
hi h llevell
¾Find problems earlier
Implementation
I l t ti independent
i d d t
¾Last minute changes
¾D l implementation
¾Delay i l i decisions
d ii
Flexibility
¾Re-use
¾Choice of tools, vendors
Language based
¾Faster design capture
¾Easier to manage
16 VHDL : Tong+ Jan 2010
VHDL Organizations
g
VHDL International
¾ Promoting use of VHDL
¾ Quarterly publication, “Resource Book”
¾ “Simulator
Simulator Certification Test Suite
Suite”
IEEE Committees
¾ VASG : defining the language : various others too (VASG :
VHDL Analysis and Standardization Group)
Europe
¾ European
E chapter
h off VASG
¾ VHDL Forum for CAD in Europe
¾ VHDL Newsletter, published by Esprit project
¾ Regional user groups : VHDL-UK, etc . . .
Newsgroups
¾ comp.lang.vhdl
17 VHDL : Tong+ Jan 2010
Digital
i i design
i
with
FPGA & CPLD
Standard IC
Xilinx
XC9536XL
800 Gates
Xilinx
Spartan-II XC2S15
15 00 Gates
15,00
System On a Chip(SOC)
www.ailogictechnology.com
Entity declaration
¾ Interface definition
¾ Input
p and output
p signal
g ((Ports))
Architecture
¾ Architecture bodyy
¾ Relation of input and output
¾ Circuit behavior
Package
¾ Library : Constants, Procedures, Data types, Components
Configuration
¾ Match entity declaration and architecture
32 VHDL : Tong+ Jan 2010
VHDL Basic : Example
p
Example of 2 to 4 decoder
VHDL 87 code
VHDL 93 code
Concurrent statement
Case insensitive
¾ A_Bus = a_bus
¾ Address_aBC = aDDRESS_Abc
Each statement end with “;”
¾ A_Variable := B_Variable;;
¾ C := X; D := Y;
¾ Data_0 <= Data_5;; Data_1 <= Data_2;;
Comment with “- “-”
¾ Data_0
Data 0 <= Data_5;
Data 5; -- Signal Data_5
Data 5 to signal Data_0
Data 0
VHDL 87 identifiers
Use only
¾ Letter
¾ Number
¾ Underscore “_”
Rules
¾ Start with letter
¾ No space
¾ No repetitive underscore
¾ Not end with underscore
¾ No reserved word
43 VHDL : Tong+ Jan 2010
Reserved words
'U'
U = Uninitialized
'X' = Unknown
'0' = Low (Logic‘0’)
g (Logic‘1’)
'1' = High g
'Z' = High impedance
'W' = Weak
W k unknown
k
'L' = Weak low
'H' = Weak high
' - ' = Don
Don'tt care
47 VHDL : Tong+ Jan 2010
std_ulogic
g VS std_logic
g
constant CONSTANT
CONSTANT_NAME
NAME : TYPE [ :=
: VALUE ];
MUX 2:1
Like signal,
signal But use only in sequential statement
Use “:=” (variable assignment) to assign value
Have to be the same data type
Local, can use only in its process, procedure of function
Update its value immediately
Can not exchange data outside sequential statement
((have to assign
g to signal
g or p
port to exchange
g data))
Temporary storage in process
type
yp BOOLEAN is ((FALSE,, TRUE)) ;
type BIT is (‘0
(‘0’, ‘1
‘1’) ;
type COLOR is (BLUE
(BLUE, GREEN
GREEN, YELLOW
YELLOW, RED);
type LOGIC_LEVEL is (‘0
(‘0’, ‘1
‘1’, ‘Z’); - - Base type
subtype BIT_LOGIC is LOGIC_LEVEL range ‘0
‘0’ to ‘1
‘1’ ; - - Subtype
range 0 to 2,147
147,,483
483,,647
“Positive”
Positive is a predefined subtype of integer (base type)
range 1 to 2,147
147,,483
483,,647
type
yp INTEGER is range
g -2147483647 to 2147483647;
2147483647;
subtype
b POSITIVE iis iinteger range 1 to 2147483647
2147483647;;
subtype HIGH_BIT_LOW
HIGH BIT LOW is BYTE_LENGTH
BYTE LENGTH range 0 to 127
127;;
type
yp DURATION is range
g -2147483647 to 2147483647
units
fs; - - femtosecond
ps = 1000 fs; - - picosecond
ns = 1000 ps; - - nanosecond
us = 1000 ns; - - microsecond
ms = 1000 us; - - millisecond
sec = 1000 ms; - - second
min = 60 sec; - - minute
end units ;
Note : Xilinx synthesis tool is ignore.
68 VHDL : Tong+ Jan 2010
Floatingg Point Type
yp ((Real))
10
10..2
- 15
15..264
12
15
15..3 ns
12
12..7 E-6
- 2.35 E10
N
Note: Whi
Which
h one iis wrong
69 VHDL : Tong+ Jan 2010
Composite
p Type
yp
Multi
Multi--value of the same type
¾ “string”
g is one dimensional arrayy of character
- - Unconstrained array
- - Unconstrained array
- - Constrained array
- - Constrained array
y
1 X 1 Dimensional
type
y DATA_ROM
_ is array
y (4095
(4095 downto 0) of
BIT_VECTOR (7
(7 downto 0);
type
t DATA_ROM
DATA ROM iis array (4095
(4095 downto
d t 0) off BYTE;
BYTE
Multi
Multi--value of the “DIFFERENCE” type
R_W : bit;
DATA_BUS
_ : bit_vector
_ (7 downto 0);
(7
CE : bit;
bit
end record;
Later explain.
In practical “0
“0”, “1
“1” and “Z”
Z ( high impedance ) are enough
std_logic
g & std_logic
g _vector are “Resolved” type
yp
‘0’, - - Forcing 0
‘1’, - - Forcing 1
‘W’ - - Weak
‘W’, W kU Unknown
k
‘L’, - - Weak 0
‘H’, - - Weak 1
‘ - ’ - - Don’t care
);
77 VHDL : Tong+ Jan 2010
std_logic
g and std_ulogic
g
subtype
yp STD_LOGIC is resolved STD_ULOGIC;;
subtype X
X01
01 is resolved STD_ULOGIC range ‘X’ to ‘1
‘1’;
- - (‘X’,
(‘X’ ‘0
‘0’,
’ ‘1
‘1’)
subtype X01
X01ZZ is resolved STD_ULOGIC range ‘X’ to ‘Z’;
- - (‘X’, ‘‘00’, ‘1
‘1’, ‘Z’)
subtype UX01
UX01 is resolved STD
STD_ULOGIC
ULOGIC range ‘U’
U to ‘1
‘1’;;
- - (‘U’, ‘X’, ‘0
‘0’, ‘1
‘1’)
subtype UX
UX01
01Z
Z is resolved STD_ULOGIC range ‘U’ to ‘Z’;
type STD
STD_ULOGIC_VECTOR
ULOGIC VECTOR is array (natural range <>) of STD_ULOGIC;
STD ULOGIC;
- - Unconstrained array
t pe STD_LOGIC_VECTOR
type STD LOGIC VECTOR is array
arra (natural
(nat ral range <>) of STD_LOGIC;
STD LOGIC;
- - Unconstrained array
1 X 1 dimensional array
Or
type DATA
DATA_ROM
ROM is array (4095
(4095 downto 0) of BYTE;
2 dimensionals array
type DATA_
DATA_22D is array ((15
15 downto 0, 7 downto 0) of std_logic
3 dimensionals array
type DATA_
DATA_33D is array (0
(0 to 255,
255, 15 downto 0, 7 downto 0) of std_logic
¾ falling_edge (CLK
CLK)) is CLK’event and CLK = ‘0’
- - Unconstrained array
- - Unconstrained array
unsigned
i d 1 x 1 dimensional
di i l constrained
t i d array
90 VHDL : Tong+ Jan 2010
7 Segments
g Decoder
unsigned
i d 1 x 1 dimensional
di i l unconstrained
t i d array
91 VHDL : Tong+ Jan 2010
VHDL
#3
VHDL Operator
p
No ( ) needed
95 VHDL : Tong+ Jan 2010
Relational Operators
p
=, //=, >
>=, >,
> <<=, <
Equal priority
IEEE Std 1076 : Scalar and Discrete
IEEE Std 1076.
1076.3 : Signed and Unsigned
IEEE Std 1164 : Not supported
But Xilinx Synthesis Tool (XST) supported
std_logic
std logic (std_ulogic),
(std ulogic) std
std_logic_vector
logic vector (std
(std_ulogic_vector)
ulogic vector)
Left alignment with unequal array
01111 (Compare ?)
1110
&
Concatenate two of 1 dimensional arrays
IEEE Std 1076
1076,, 1076
1076..3 supported
IEEE Std 1164 : Not supported
But Xilinx Synthesis Tool (XST) supported
<= “01
A <= 01”” & “1101
“1101
1101”;
”;; Equal to <= “011101
A <= 011101”;
”;;
<= ‘0’ & ““111
B <= 111”” & ““0011
0011”;
”; Equal to <== “01110011
B< 01110011”;
”;
<= A & B;
C <= Equal to <= “01110101110011
C <= 01110101110011””
+,
+ - , *, /,
/ **, MOD,
MOD REM,
REM ABS
IEEE Std 1076
+ -, ABS
+, : numeric (Integer
(Integer, Floating point
point, Physical)
*, /, ** : Integer, Floating point
MOD, REM : Integer
g
None for bit and bit_vector
IEEE Std 1164
None for std_logic (std_ulogic), std_logic_vector (std_ulogic_vector)
Have to use packages : std_logic_signed or std_logic_unsigned (IEEE; Synopsis)
IEEE Std 1076.
1076.3
unsigned, signed
Have to use packages : Numeric_std
i
99 VHDL : Tong+ Jan 2010
Type
yp conversion
1) Integer
g or floatingg p
point
Same type but difference range
Integer
g to Floatingg p
point or vice versa
type
yp X is range
g 0 to 100 ; - - defined data
type Y is range 0 to 1000
1000;;
g
signal Q
QT : X;; - - defined signal
g
signal Q : Y ;
2) Array
y
Same type of member and dimensional
2) Array
y
Same type of member and dimensional
Q(0
Q( 0) <= QT(
QT(0
0) ; - - same result
Q(1
Q( 1) <= QT(1
QT(1) ;
Q(2
Q( 2) <= QT(
QT(2
2) ;
Q(3
Q( 3) <= QT(3
QT(3) ;
Package
P k : std_logic_unsiged
d l i i d
P k
Package : Numeric_std;
N i d IIn/Out
/O std_logic_vector
d l i
Package
g : Numeric_std;
_ In/Out unsigned
g
Note : Top
Top--level port declaration must be
std_logic or std_logic_vector
106 VHDL : Tong+ Jan 2010
Shift Operators
p
IEEE Std 1076
sll
ll : Shift Left
L ft Logical
L i l
srl : Shift Right Logical
sla
l : Shift Left
L ft Arithmetic
A ith ti
sra : Shift Right Aritgmetic
roll : Rotate
R t t LLeft
ft
ror : Rotate Right
1) A(
A(55 downto 0) is “Slices of array” A =
A(55)&A(
A( )&A(44)&A(
)&A(33)&A(
)&A(22)&A(
)&A(11)&A(
)&A(00)
2) A(
A(77 downto 2) is “Slices of array” A =
A(7
A( 7)&A(
)&A(66)&A(
)&A(55)&A(
)&A(44)&A(
)&A(33)&A(
)&A(22)
108 VHDL : Tong+ Jan 2010
Shift Operators
p : IEEE Std 1164
signal A : bit
bit_vector
vector (7
(7 downto 0) := “01110001
“01110001
01110001”;
”;; - - Assume
U & iinstead
Use d off ““sll”
ll” iin IEEE Std
S d 1164
U ““sll”
Use ll” iin IEEE Std
S d 1076
1076..3
2 to 4 Decoder
library LIBRARY_NAME;
use LIBRARY_NAME.PACKAGE_NAME.PACKAGE_PARTS;
Library
Lib : IEEE
Package : std_logic_1164
std_logic_1164
library IEEE;
use IEEE.std_logic_1164
IEEE.std_logic_1164.all;
.all;
entity ENTITY_NAME is
[ generic
i ( GENERIC DECLARATIONS) ; ]
[ port ( PORT DECLARATIONS) ; ]
end
d [[entity]
tit ] [ENTITY
[ENTITY_NAME]
NAME] ;
architecture ARCHITECTURE_NAME
ARCHITECTURE NAME of ENTITY
ENTITY_NAME
NAME is
{ DECLARATIVE_ITEM }
b i
begin
{ CONCURRENT_STATEMENT }
end [architecture] [ARCHITECTURE_NAME] ;
X ’ attribute_name
attribute_name = Name of attribute
X = Name of objects
“ ’” = Tick
Ti k
Note : (not “,”)
LENGTH
LOW
RANGE
Have 2 classes
¾ Predefined attributes
¾ User defined attributes
Kinds of attribute depend on its return value
¾ Value
¾ Type
¾ Range
¾ Function
¾ Signal
g
¾ T
T’left
left = T
T’low
low ¾ T
T’left
left = T
T’high
high
¾ T’rightof(X)
g ( ) = T’succ(X)
( ) ¾ T’rightof(X)
g ( ) = T’pred(X)
p ( )
VHDL : Tong+
Arrayy Attribute
Jan 2010
Predefined Attributes
3) Signal attribute
Use with signal.
signal
C’event
C event and C = ‘1
‘1’ : rising_edge(
rising edge( C )
C’event and C = ‘0
‘0’ : falling_edge( C )
Rising
g_edge
g and Fallingg_edge
g are p
predefined in IEEE Std 1164
Later
L t explain
l i
Concurrent
C t statement
t t t
¾ All lines work in parallel.
Sequential statement
C <= A and B ;
X <= “00000000
“00000000”” ;
X <= (others => ‘0
‘0’) equal to X <= “00000000
“00000000””
X <= (others => ‘1
‘1’) equal to X <= “11111111
“11111111””
Assign
A i EXPRESSION to
t TARGET
when CONDITION is “true”.
Truth table
Truth table
Hi
Hierarchical
hi l model
d l or Structural
St t l model.
d l
Component declaration.
¾ Declare the component before use.
Component instantiation statement.
¾ Create the declared component.
p
component COMPONENT_NAME
[ generic (GENERIC_DECLARATIONS)
(GENERIC DECLARATIONS) ]
[ port (PORT_DECLARATIONS) ]
end component ;
Concurrent statement.
statement
Create declared component as circuit.
INSTANCE_NAME : COMPONENT_NAME
[ generic map ( GENERIC_NAME => VALUE { , GENERIC_NAME => VALUE } ) ]
port map ( [PORT_NAME =>] SIGNAL_NAME { , [PORT_NAME =>] SIGNAL_NAME } );
[ PORT_NAME
PORT NAME =>
> ] iis th
the name off iinput/out
t/ t off th
the
component.
Positional association
¾ No PORT_NAME.
PORT NAME.
¾ SIGNAL_NAME must place in exactly order.
Named
N d association
i ti
¾ Must have PORT_NAME.
¾ Order in not necessary.
For/Generate
¾ Suitable for repeatable statement.
¾ Suitable for duplication
p circuit.
If/Generate
¾ Operate only condition is TRUE.
Truth table
1) BLOCK_DECLARATIVE_PART
• use clause
• Subprogram declaration and Subprogram body
• Type declaration and/or Subtype declaration
• Constant declaration
• Signal declaration
• Component declaration
2) CONCURRENT STATEMENT
CONCURRENT_STATEMENT
1) PROCESS_DECLARATIVE_PART
• use clause
• Subprogram declaration and Subprogram body
• Type declaration and/or Subtype declaration
• Constant declaration
• Variable declaration
2) SENSITIVITY LIST; Every input that direct effect to the process
3) SEQUENTIAL STATEMENT
SEQUENTIAL_STATEMENT
Call
C ll subprogram
b iinside
id architecture
hit t or block
bl k
Later explain
TARGET := EXPRESSION ;
case EXPRESSION is
when CHOICES => {SEQUENTIAL_STATEMENT}
{ when CHOICES => {{SEQUENTIAL
Q _STATEMENT}} }
end case;
With concatenation
Without concatenation
wait [ on SENSITIVITY_LIST ] ;
[ until CONDITION ] ;
[ for TIME¬_EXPRESSION ] ;
wait [ on SENSITIVITY_LIST ] ;
[ until CONDITION ] ;
[ for TIME¬_EXPRESSION ] ;
M t be
Must b first
fi t statement
t t t in
i the
th process.
[ loop_label : ] loop
{SEQUENTIAL_STATEMENT}
end loop [ loop_label
loop label ] ;
Package Library
Package, Library, Subprogram
ROM,, RAM
VHDL
#6
VHDL
Wait : Stop
p the p
process.
Wait for : Stop the process for the time “wait for 100 ns;”
Assert
A t :W
Working
ki when
h condition
diti iis “FALSE”
working with “Report” and “Severity”
assert CONDITION_EXPRESSION
report TEXT_STRING
severity SEVERITY
SEVERITY_LEVEL;
LEVEL;
Clock <= not Clock after 100 ns; - - Clock generation : Period =
(100+
100+100)
100) ns, F = 5 MHz
Process
constant Period : TIME := 200 ns;
- - Declare a clock period constant
begin
Clock <= ‘1
‘1’;;
wait for (Period / 2);
Clock <
<= ‘0
‘0’;
wait for (Period / 2);
end process;
Stimulus1
Stimulus 1 : process
begin
Reset <= ‘1
‘1’;
wait for 100 ns;
CE <= ‘‘1
1’;
Reset <= ‘0
‘0’;
’
wait for 800 ns;
CE <= ‘0
‘0’;
wait for 100 ns;
wait ;
end process Stimulus
Stimulus11;
S <= "00
00",
",
"01
01"" after 30 ns,
"11
11"" after 120 ns,
ns
"01
01"" after 150 ns;
type FILE_TYPE_NAME
A iis file
fi off TYPE_NAME;
A
readline (INPUT_OBJECT_FILE,
(INPUT OBJECT FILE INPUT_LINE)
INPUT LINE) - - Reads new line from temp file
END,
END EPISODE I