Professional Documents
Culture Documents
EG - VHDL - Altera
EG - VHDL - Altera
Model Development
HDL model using
HDL or Schematic capture
Behavioral
Simulation
Netlist Synthesis
(Equations) Functional
Simulation
Implementation
Map File Translate, Place and route (Fitting)
Post place
and route
Programming Simulation
(verification)
HDL Editor
Schematic Editor
MAX+PLUS® II
All FLEX, ACEX, & MAX Devices
Hardware
Description
Language
Higher-level Component
input1 output1
Lower-level
Component1
Lower-level
Component1
inputn outputn
Analogy : Symbol
<Entity_name> Can Be Any Alpha/Numerical Name
Note: MAX+PLUS II Requires That the <Entity_name> and
<File_name> Be the Same; Not Necessary in Quartus II
Generic Declarations
Used to Pass Information Into a Model
Quartus II & MAX+PLUS II Place Some Restriction on the Use of
Generics
Port Declarations
Used to Describe the Inputs and Outputs i.e. Pins
Copyright © 2005 Altera Corporation
26
Entity : Generic Declaration
ENTITY <entity_name> IS
Generic ( constant tplh , tphl : time := 5 ns;
-- Note constant is assumed and is not required
tphz, tplz : time := 3 ns;
default_value : integer := 1;
cnt_dir : string := “up”
);
Port Declarations
END <entity_name>; (1076-1987 version)
END ENTITY <entity_name> ; ( 1076-1993 version)
Entity
Symbol
inputn outputn
Architecture
a Schematic
b D Q
mux_out
c
d clk
ENA
sel CLRN
2
clr
Type STD_ULOGIC
Same 9 Value System As STD_LOGIC
Unresolved Type: Does Not Support Multiple Signal Drives;
Error Will Occur
process process
signals Functional Functional
Block:
signals Block:
signals
MUX REGISTERS
signals (signals) (signals)
END logic;
Signal Declaration
Inside Architecture
Copyright © 2005 Altera Corporation
48
Signal Assignments
Signal Assignments Are Represented By: <=
Signal Assignments Have an Implied Process
(Function) That Synthesizes to Hardware
Signal D Q
ENA
CLRN
Example: qa <= r or t ;
Implied Processes
qb <= (qa and not(g xor h));
r qa
Parenthesis ( ) Give the
t Order of Operation
g qb
Signing + -
LIBRARY IEEE;
Include These Statements
USE IEEE.std_logic_1164.all; At the Beginning of a
USE IEEE.std_logic_unsigned.all; Design File
ENTITY overload IS
PORT ( a : IN STD_LOGIC_VECTOR (4 downto 0);
b : IN STD_LOGIC_VECTOR (4 downto 0);
sum : OUT STD_LOGIC_VECTOR (5 downto 0));
END overload;
Example:
q <= a WHEN sela = ‘1’ ELSE c
b WHEN selb = ‘1’ ELSE b q
c; a
selb
sela
Implied Process
Example:
a
WITH sel SELECT
b q
q <= a WHEN “00”,
c
b WHEN “01”,
c WHEN “10”, d
d WHEN OTHERS; sel
2
ENTITY cmpl_sig IS
PORT ( a, b, sel : IN STD_LOGIC; sel Has a STD_LOGIC Data Type
z : OUT STD_LOGIC);
END cmpl_sig;
• What are the Values for a
ARCHITECTURE logic OF cmpl_sig IS
BEGIN
STD_LOGIC Data Type
-- selected signal assignment • Answer: {‘0’,’1’,’X’,’Z’}
WITH sel SELECT
z <= a WHEN '0', • Therefore, is the WHEN OTHERS
b WHEN '1', Clause Necessary?
'0' WHEN OTHERS; • Answer: YES
END logic;
Delta Processes
Process Execution Phase
Signal Update Phase
Advance Time
When Does a Simulation Cycle
End and a New One Begin?
Simulation
When: Execute Delta Cycle
– All Processes Execute sensitive
– Signals Are Updated Processes
Signals Get Updated at the End
of the Process Update Signals
LIBRARY IEEE;
USE IEEE.std_logic_1164.all; a = 1, b = 1 a,b changes a,b changes
ENTITY simp_prc IS a = 0, b = 1 a = 1, b = 1
PORT(a, b : IN STD_LOGIC;
y: OUT STD_LOGIC);
END simp_prc; c and y c and y c and y
ARCHITECTURE logic OF simp_prc IS executed executed executed
SIGNAL c: STD_LOGIC;
BEGIN 1 1
PROCESS(a, b) simulation cycle1 simulation cycle2
BEGIN
c <= a and b; (visible delay) (visible delay)
y <= c;
END PROCESS;
• y Does Not Get the Newest Value of c Until a
END logic; Simulation Cycle Later
1 2 1 2 1 1
simulation cycle1 simulation cycle2
simulation cycle1 simulation cycle2
(visible delay) (visible delay)
(visible delay) (visible delay)
• y Does Not Get the Newest Value of c Until a
• c and y Gets Executed and Updated Within the Simulation Cycle Later
Same Simulation Cycle
Copyright © 2005 Altera Corporation
71
Variable Assignment - No Delay
• Delta Cycle has 2 Phases: a = 1, b = 1 y updated y updated
– Process Execution (y=1) (y=0)
– Signal Update
c
a,b changes a,b changes
executed
a = 0, b = 1 a = 1, b = 1
LIBRARY IEEE; and
USE IEEE.std_logic_1164.all; updated
ENTITY var IS (c=1) c executed and c executed and
PORT (a, b : IN STD_LOGIC; updated (c=0) updated (c=1)
y : OUT STD_LOGIC);
END var;
y y y
ARCHITECTURE logic OF var IS
BEGIN
executed executed executed
PROCESS (a, b)
VARIABLE c : STD_LOGIC;; 1 1
BEGIN simulation cycle1 simulation cycle2
c := a AND b; (visible delay)
(visible delay)
y <= c;
• c and y Gets Executed and Updated Within the
END PROCESS;
Same Simulation Cycle (at the End of the Process)
END logic;
No Delay
Copyright © 2005 Altera Corporation
73
Assigning Values to Variables
VARIABLE temp : STD_LOGIC_VECTOR (7 downto 0);
All Bits:
Temp := “10101010”;
Temp := X”aa” ; (1076-1993)
Single Bit:
Temp(7) := ‘1’;
Bit-slicing:
Temp (7 downto 4) := “1010”;
Single-bit: Single-quote (‘)
Multi-bit: Double-quote (“)
ENTITY var IS
PORT (a, b : IN STD_LOGIC;
y : OUT STD_LOGIC);
END var;
PROCESS (a, b)
VARIABLE c : STD_LOGIC; Variable Declaration
BEGIN
c := a AND b; Variable Assignment
y <= c;
Variable is Assigned to a
Signal to Synthesize to a
END PROCESS;
Piece of Hardware
END logic;
WHEN 1 =>
q <= i1;
END CASE;
END PROCESS;
END logic;
Copyright © 2005 Altera Corporation
76
Signal and Variable Scope
ARCHITECTURE
Declared Outside of the
{SIGNAL Declarations} Process Statements
(Globally Visible to All
label1: PROCESS Process Statements)
{VARIABLE Declarations}
• Sequential Process d D Q q
– Sensitive to a Clock or/and
Control Signals clk
ENA
• Example CLRN
ENTITY latch1 IS
PORT ( data : IN std_logic;
gate : IN std_logic;
q : OUT std_logic data Transparent
); q
END latch1;
Latch
gate
ARCHITECTURE behavior OF latch1 IS
BEGIN
D Q a D Q
b D Q q
d
clk clk clk
ENA ENA ENA
CLRN CLRN CLRN
d D Q q
clk
ENA
CLRN
Mealy Machines
A finite state machine in which the outputs can
change asynchronously i.e., an input can
cause an output to change immediately
Two processes
A synchronous process for updating the state
register
A combinational process for conditionally deriving
the next machine state and updating the outputs
REQ
tco
Copyright © 2005 Altera Corporation
113
Example: Solution 1 Present state
Combinatorial outputs
Outputs
Logic State Output
Inputs Registers Logic
END archmoore1;
Present State
State (Outputs)
Logic
Inputs Registers
END archmoore3;
Present State
State
Registers
Logic Outputs
Inputs
REQ / 0
IDLE RETRY ENABLE / 1
REQ / 0
PWAIT / 0
Higher-Level Component
input1 output1
Lower-Level
Component1
Lower-Level
Component1
inputn outputn
mid_a.vhd mid_b.vhd
entity-architecture “mid_a” entity-architecture “mid_b”
component “bottom_a” component “bottom_a”
component “bottom_b”
bottom_a.vhd bottom_b.vhd
entity-architecture “bottom_a” entity-architecture “bottom_b”
s1 muxcomp Without
2
COMPONENT!
a1 2
MUX LIBRARY ieee;
2 USE ieee.std_logic_1164.ALL;
b1 out1
ENTITY muxcomp IS PORT (
a1,b1,a2,b2: IN std_logic_vector(1 DOWNTO 0);
y
= s1,s2: IN std_logic;
s2 y: OUT std_logic);
2
END muxcomp;
a2
2 out2 ARCHITECTURE archmuxcomp OF muxcomp IS
MUX
2 SIGNAL out1,out2: std_logic_vector(1 DOWNTO 0);
b2
BEGIN
out1 <= a1 WHEN s1 = '1' ELSE b1;
out2 <= a2 WHEN s2 = '1' ELSE b2;
y <= '1' WHEN out1 = out2 ELSE '0';
END archmuxcomp;
?
b1 ENTITY muxcomp IS PORT (
MUX a1,b1,a2,b2: IN std_logic_vector(1 DOWNTO 0);
y s1,s2: IN std_logic;
y: OUT std_logic);
s2 END muxcomp;
2 ...
a2
COMP
b2
2
The Top-Level Entity
Has the highest rank in the
hierarchy
Blocks Contains and connects all the sub-
Library blocks
User-defined Furnishes the path towards pins
Copyright © 2005 Altera Corporation
133
COMPONENT: example - definition
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY mux2to1 IS PORT (
s a,b: IN std_logic_vector(1 DOWNTO 0);
s: IN std_logic; s
2 2
mux2to1 2
a y: OUT std_logic_vector(1 DOWNTO 0)); a
2 y
END mux2to1;
2
MUX y b2
b
ARCHITECTURE archmux2to1 OF mux2to1 IS
BEGIN
y <= a WHEN s = '1' ELSE b;
END archmux2to1;
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY comp IS PORT (
a 2 a,b: IN std_logic_vector(1 DOWNTO 0);
2
y: OUT std_logic); a comp
= y END comp; 2
y
2 b
b
ARCHITECTURE archcomp OF comp IS
BEGIN
y <= '1' WHEN a = b ELSE '0';
END archcomp;
Copyright © 2005 Altera Corporation
134
COMPONENT: example - declaration
A COMPONENT must be declared before it can be used
in an architecture (as function prototypes in C…)
...
s1
muxcomp 2
mux2to1
2
2
a1
2 mux1
2
mux2to1 2
comp
2 2
b1 2 2
y
comp
s2 2 mux1: mux2to1 PORT MAP (...);
comp
2 mux2 mux2: mux2to1 PORT MAP (...);
2
a2
mux2to1 comp: comp PORT MAP (...);
2 2
2
b2 2
univocal identifiers
Copyright © 2005 Altera Corporation
136
COMPONENT: example - PORT MAP
Components must be connected by means of PORT MAP
muxcomp ...
s1
mux1 SIGNAL out1,out2: std_logic_vector(1 DOWNTO 0);
2
a1 s mux2to1 2
2
a y BEGIN
2 2 mux1: mux2to1 PORT MAP (a1,b1,s1,out1);
b1 b out1
comp mux2: mux2to1 PORT MAP (a2,b2,s2,out2);
2 comp comp: comp PORT MAP (out1,out2,y);
a y END archmuxcomp;
2
y
s2 b
2
mux2
a2 s mux2to1 2 out2
2
2 2
a y Pay attention to ports positions
b2 b within the PORT MAP
muxcomp
mux1
s1 s mux2to1 2
a1 2 2 2 out1
a y
2 2
b1 b
muxcomp
mux1
s1 s mux2to1 2
a1 2 2
y 2 out1
a
2 2
b1 b
Ports and Signals belonging
to "muxcomp"
s LIBRARY ieee;
N USE ieee.std_logic_1164.ALL;
a
MUX
N
y
ENTITY mux2to1 IS
GENERIC (N: integer:=8);
Default
N
b PORT ( value
a,b: IN std_logic_vector(N-1 DOWNTO 0);
s: IN std_logic;
y: OUT std_logic_vector(N-1 DOWNTO 0));
Parameter END mux2to1;
Parametrize
ARCHITECTURE archmux2to1 OF mux2to1 IS d Vector
Parameter BEGIN
y <= a WHEN s = '1' ELSE b;
Type END archmux2to1;