Advanced VHDL 11.1 v1
Advanced VHDL 11.1 v1
Techniques
Design units
ENTITY
ARCHITECTURE,
CONFIGURATION
PACKAGE (LIBRARY)
Behavioral vs. structural modeling
Implicit vs. explicit processes
i.e. Concurrent signal assignment vs. PROCESS statement
Signal delay
AFTER clause
Inertial vs. transport delays
Delta delays
Simulation
Code executed in the exact way it is written
User has flexibility in writing
Initialization of logic supported
Synthesis
Code is interpreted & hardware created
Knowledge of PLD architecture is important
Synthesis tools require certain coding to generate correct logic
Subset of VHDL language supported
Coding style is important for fast & efficient logic
Initialization controlled by device
Logic implementation can be adjusted to support initialization
ACCESS
These are some of the constructs
ASSERT not supported by Quartus II
DISCONNECT synthesis
See the online help in Quartus II
FILE (or your target synthesis tool) for
GROUP a complete list
NEW
Physical delay types
PROTECTED
SHARED VARIABLE
Signal assignment delays
Sequential PROCESS d q
Sensitive to a clock and
clk
control signals
Example
aclr_n
PROCESS (clr, clk)
Sensitivity list does not include the d input,
only the clock or/and control signals
2012 Altera CorporationConfidential
15
Sensitivity Lists
Incomplete sensitivity list in combinatorial PROCESS blocks may
result in differences between RTL & gate-level simulations
Synthesis tool synthesizes as if sensitivity list complete
PROCESS
PROCESS (a, (a, b)
b) Incorrect Way the simulated behavior is not
yy <=
<= aa AND
AND b b AND
AND c;
c; that of the synthesized 3-input AND gate
PROCESS
PROCESS (a, (a, b,
b, c)
c)
yy <=
<= aa AND
AND b b AND
AND c;
c;
or Correct way for the intended AND logic !
PROCESS
PROCESS (all)
(all)
yy <=
<= aa AND
AND b b AND
AND c;
c;
Recommendations
Design with registers (RTL)
Watch out for inferred latches
Latches inferred on combinatorial outputs when results not specified for set of
input conditions
Lead to simulation/synthesis mismatches
Logical Equation
IF <cond1> THEN
IF <cond1> AND <cond2> THEN
IF <cond2> THEN
PROCESS
PROCESS (sel,
(sel, a,
a, b,
b, c)
c)
BEGIN
BEGIN
IF
IF sel
sel == 001
001 THEN
THEN
sel(0) LOGIC
output
output <=
<= a;
a; sel(1) LATCH
sel(2) output
ELSIF
ELSIF sel
sel == 010
010 THEN
THEN A
B
output
output <=
<= b;
b; C
ELSIF
ELSIF sel
sel == 100
100 THEN
THEN
output
output <=
<= c;
c;
END
END IF;
IF;
END
END PROCESS;
PROCESS;
PROCESS
PROCESS (all)
(all)
BEGIN
BEGIN
IF
IF sel
sel == 001
001 THEN
THEN
output
output <= <= a;
a; sel(0)
LOGIC
ELSIF sel(1)
ELSIF selsel == 010
010 THEN
THEN sel(2)
output
output
output <= <= b;
b; A
B
ELSIF
ELSIF selsel == 100
100 THEN
THEN C
output
output <= <= c;
c;
ELSE
ELSE
output
output <= <= (OTHERS
(OTHERS =>
=> X);
X);
END
END IF;IF;
END
END PROCESS;
PROCESS;
PROCESS
PROCESS (all)
(all)
BEGIN
BEGIN
sel(0) LOGIC LATCH
IF
IF sel
sel == 010
010 THEN
THEN sel(1) X
xx <=
<= a;a; sel(2)
A
ELSIF
ELSIF selsel == 100
100 THEN
THEN
yy <=
<= b;b;
sel(0) LOGIC LATCH
ELSIF
ELSIF selsel == 001
001 THEN
THEN sel(1) Y
zz <=
<= c;
c; sel(2)
B
ELSE
ELSE
xx <=
<= 0;
0;
sel(0) LOGIC LATCH
yy <=
<= 0;
0; sel(1) Z
zz <=
<= 0;
0; sel(2)
C
END
END IF;IF;
END
END PROCESS;
PROCESS;
PROCESS
ina inb out
PROCESS (ina,(ina, inb)
inb)
BEGIN
BEGIN 1 1 1
yy <=
<= 0;
0; 0 0 0
IF
IF ina
ina == '1'
'1' THEN
THEN 0 1 0
IF
IF inb
inb == '1'
'1' THEN
THEN 1 0 0
yy <=
<= '1';
'1';
END
END IF; IF; ina
END
END IF;IF;
inb out
END
END PROCESS;
PROCESS;
output:
output: PROCESS
PROCESS (filter)
(filter)
BEGIN
BEGIN
Undetermined output
CASE
CASE filter
filter IS
IS conditions implies
WHEN
WHEN idleidle =>
=> memory
nxt
nxt <= '0';
<= '0';
first sel
sel missing
missing Latch generated for
first <= '0';
<= '0';
WHEN
WHEN tap1tap1 =>=> ALL 3 outputs
sel
sel <=
<= "00";
"00";
first
first <=
<= '1';
'1'; nxt
nxt missing
missing
WHEN
WHEN tap2tap2 =>=>
sel <= "01";
sel <= "01";
first
first <=
<= '0';
'0'; nxt
nxt missing
missing
WHEN
WHEN tap3tap3 =>=>
sel
sel <=
<= "10";
"10"; nxt
nxt &
& first
first missing
missing
WHEN
WHEN tap4tap4 =>=>
sel <= "11";
sel <= "11";
nxt
nxt <=<= '1';
'1'; first
first missing
missing
END
END CASE;
CASE;
END
END PROCESS
PROCESS output;
output;
output:
output: PROCESS(filter)
PROCESS(filter)
BEGIN
BEGIN To remove latches & ensure
first
first <=
<= 0;
0; outputs are never undetermined
nxt
nxt <=<= 0;
0; Signals
Signals Initialized
Initialized
sel
sel <=
<= 00;
00;
CASE
CASE filter
filter ISIS
Use signal initialization at
WHEN
WHEN idle idle =>
=> beginning of case statement
WHEN
WHEN tap1 tap1 =>=> (case statement only deals with
first
first <=
<= '1';
'1'; changes)
WHEN
WHEN tap2 tap2 =>=>
sel
sel <=
<= "01";
"01"; Use dont cares (-) for WHEN
WHEN
WHEN tap3 =>
tap3 => OTHERS clause, if design
sel <= "10";
sel <= "10"; allows (for better logic
WHEN
WHEN tap4 tap4 =>=>
sel
sel <=
<= "11";
"11";
optimization)
nxt
nxt <=
<= '1';
'1'; Manually set output in each
END CASE;
END CASE; case
END
END PROCESS output;
PROCESS output;
PROCESS
PROCESS (clk)
(clk)
BEGIN
BEGIN
IF
IF rising_edge
rising_edge (clk)
(clk) THEN
THEN
clrn
clrn <=
<= (ctrl1
(ctrl1 XOR
XOR ctrl2)
ctrl2) AND
AND q;
q;
END
END IF;IF;
clrn END
END PROCESS;
PROCESS;
Recommendations:
Use clock enables for clock gating functionality
Use dedicated device resources (e.g. clock control blocks) to gate clocks
synchronously and reduce power
If you must build your own gating logic
Use a synchronous gating structure
Ensure global clock routing is used for clock signal
Gate the clock at the source
Toolbar
Latches
Registers
Counters
Tri-states
Memory
ENTITY latch IS
PORT (
data : IN std_logic;
gate : IN std_logic;
q : OUT std_logic); Latch in Technology
END ENTITY latch; Viewer
APEX II Device
Logic
ena1
ena2 out_sig
in_sig1
in_sig2
bidir
bidir as
as an
an input
input
SUBTYPE byte IS std_logic_vector (7 DOWNTO 0); Using subtype for vector width
BEGIN
SIGNAL mem: mem_type := init_ram; Loop used to assign each memory address
BEGIN
Default initial value for memory
BEGIN
Memory content cannot be
PROCESS (clock, reset) cleared with reset
BEGIN Synthesizes to general logic
IF reset = 1 THEN resources
mem(conv_integer(address)) <=
Recommendations
(OTHERS => 0);
ELSIF rising_edge(clock) THEN 1. Avoid reset checking in
IF (we = '1') THEN RAM read or write
mem(conv_integer(address)) <= data; processes
END IF; 2. Be wary of other control
END IF;
END PROCESS;
signals (i.e. clock enable)
until validated with target
q <= mem(conv_integer(address)); architecture
END ARCHITECTURE logic;
BEGIN
Automatically converted to
BEGIN
ROM
PROCESS(clock)
PROCESS(clock) Tools generate ROM
BEGIN
BEGIN using embedded RAM &
IF
IF rising_edge(clock)
rising_edge(clock) THEN
THEN initialization file
CASE
CASE address
address IS
IS
WHEN
WHEN "0000" =>
"0000" => qq <=
<= "0111111";
"0111111";
Requires constant explicitly
WHEN
WHEN "0001"
"0001" =>
=> qq <=
<= "0011000";
"0011000"; defined for each choice in
WHEN
WHEN "0010"
"0010" =>
=> qq <=
<= "1101101";
"1101101"; CASE statement
WHEN
WHEN "0011"
"0011" =>
=> qq <=
<= "1111100";
"1111100"; May use romstyle
WHEN
WHEN "0100"
"0100" =>
=> qq <=
<= "1011010";
"1011010";
synthesis attribute to control
WHEN
WHEN "1101"
"1101" =>
=> qq <=
<= "1111001";
"1111001"; implementation
WHEN
WHEN "1110"
"1110" =>
=> qq <=
<= "1100111";
"1100111"; Like RAMs, address or
WHEN
WHEN "1111"
"1111" =>
=> qq <=
<= "1000111";
"1000111"; output must be registered to
WHEN
WHEN OTHERS
OTHERS => => qq <=
<= "XXXXXXX";
"XXXXXXX";
END
implement in Altera
END CASE;
CASE;
END
END IF;IF; embedded RAM
END
END process;
process;
TYPE
TYPE state_type
state_type IS
IS (idle,
(idle, fill,
fill, heat_w,
heat_w, wash,
wash, drain);
drain);
SIGNAL
SIGNAL current_state,
current_state, next_state
next_state :: state_type;
state_type;
Tools Menu
State Flow Diagram Use Drop-Down to
State Machine Viewer Select State Machine
Full = 1
END ENTITY wm; Heat_demand = 1
WASH HEAT_W
ARCHITECTURE behave OF wm IS Done = 1
Water = 0 Water = 0
TYPE state_type IS Spin = 1
Heat = 0
Spin = 1
Heat = 1
(idle, fill, heat_w, wash, drain); Pump = 0 Pump = 0
Water = 0 Water = 0
END PROCESS; Spin = 1 Spin = 1
Heat = 0 Heat = 1
Pump = 0 Pump = 0
Water = 0 Water = 1
heat <= 0; Spin = 1 Spin = 0
Heat = 0 Heat = 0
pump <= 0; Pump = 1 Pump = 0
CASE current_state IS Heat_demand = 1
Full = 1
Options:
Apply Assignment to One-Hot
State Variable Gray
Minimal Bits
Sequential
User-Encoded
Johnson
WHEN
WHEN heat_w
heat_w => =>
Heat_demand = 0
IF
IF heat_demand
heat_demand == 0 0 THEN
THEN next_state
next_state <=<= wash;
wash;
END
END IF;IF;
WHEN
WHEN wash
wash => =>
IF
IF heat_demand == 1
heat_demand 1 THEN
THEN next_state
next_state <=<= heat_w;
heat_w; This code does not consider
ELSIF done = 1 THEN next_state
ELSIF done = 1 THEN next_state <= drain; <= drain; undefined states
END
END IF;IF;
WHEN drain =>
WHEN drain =>
The when others statement
IF
IF empty
empty == 1 1 THEN
THEN next_state
next_state <=<= idle;
idle; only considers other
END
END IF;IF; enumerated states
WHEN
WHEN others
others => =>
next_state
next_state <= <= idle;
idle;
The states 101, 110 &
END CASE;
END CASE; 111 are not considered
END
END PROCESS;
PROCESS;
Current State
Next State
Outputs
Next
Inputs State Output Output
State
Registers Logic Registers
Logic
Current State
Next State
Next
State
Inputs State
Registers
Logic
Next
State Output Outputs
Output Registers
Logic
pump
pump <= <= 0;
0; Heat_demand = 1
Full = 1
CASE
CASE next_state
next_state IS IS
WHEN
WHEN idle idle =>
=> Done = 1
WASH HEAT_W
WHEN fill
WHEN fill => => Water = 0
Spin = 1
Water = 0
Spin = 1
water
water <= <= 1;
1; Heat = 0
Pump = 0
Heat = 1
Pump = 0
WHEN
WHEN heat_wheat_w => =>
spin
spin <= <= 1;
1; Heat_demand = 0
heat
heat <= <= 1;
1;
WHEN
WHEN wash wash =>=> Base output logic case statement
spin <= 1;
spin <= 1;
WHEN on next state variable (instead of
WHEN drain drain =>=>
spin
spin <= <= 1;
1; current state variable)
pump
pump <= <= 1;
1; Wrap output logic with a clocked
END
END CASE;
CASE; process
END IF;
END IF;
END PROCESS;
END PROCESS;
Water
Pump
State
Spin
Heat
output logic Encoding
Drain 0 1 0 1 0101
END
END wm;
wm; Water = 0 Water = 1
Spin = 1 Spin = 0
Heat = 0 Heat = 0
Pump = 1 Pump = 0
ARCHITECTURE
ARCHITECTURE behave
behave OF OF wm wm IS
IS Full = 1
Heat_demand = 1
TYPE
TYPE state_type
state_type IS
IS (idle,
(idle, fill,
fill, heat_w,
heat_w, wash,
wash, drain);
drain);
ATTRIBUTE
ATTRIBUTE syn_encoding
syn_encoding :: STRING;
STRING; WASH HEAT_W
Done = 1
ATTRIBUTE
ATTRIBUTE syn_encoding
syn_encoding OF OF state_type
state_type :: TYPE
TYPE IS
IS Water = 0
Spin = 1
Water = 0
Spin = 1
"0000
"0000 1000
1000 0110
0110 01000100 0101;
0101; Heat = 0
Pump = 0
Heat = 1
Pump = 0
SIGNAL
SIGNAL current_state, next_state : state_type;
current_state, next_state : state_type;
BEGIN
BEGIN Heat_demand = 0
Balancing operators
Resource sharing
Logic duplication
Pipelining
Synthesis tools
break down code 1 Comparator
into logic blocks <
They then assemble,
optimize & map to
hardware
IF
IF (sel
(sel << 10)
10) THEN
THEN 2 Adders
yy <=
<= aa ++ b;
b;
ELSE
ELSE
yy <=
<= aa ++ 10;
10; + +
END
END IF;IF;
1 Mulitplexer
Unbalanced Balanced
z <= a * b * c * d z <= (a * b) * (c * d)
a a
X X
b
X b
c X z c
X z
d X
d
a, b, c, d: 4-bit vectors
Unbalanced Balanced
z <= a * b * c * d z <= (a * b) * (c * d)
a 4x4 a 4x4
X 8x4
X 8x8
b
X 12 x 4 b
c X z c 4x4
X z
16-bit
d 16-bit
X
d
Delay through 3
stages of multiply Delay through 2
stages of multiply
Up/down counter
process(rst, clk) 2 adders are mutually
variable tmp_q : std_logic_vector(7 DOWNTO 0); exclusive & can be shared
begin
(typically IF-THEN-ELSE
if rst = '0' then
with same operator in both
choices)
tmp_q := (OTHERS => 0);
elsif rising_edge(clk) then
if updn = '1' then clk rst
tmp_q := tmp_q + 1;
else +1
end if;
tmp_q := tmp_q - 1;
+
end if; q
q <= tmp_q; Registers
-1
end process;
+
process(rst, clk)
variable tmp_q : std_logic_vector(7 DOWNTO 0); Up/down counter
variable dir : integer range -1 to 1; Only one adder required
begin
if rst = '0' then
tmp_q := (OTHERS => 0);
elsif rising_edge(clk) then
if updn = '1' then clk rst
dir := 1;
else
dir := -1;
end if; +1
-1
end if;
tmp_q := tmp_q + dir;
+ Registers
q
q <= tmp_q;
end process;
y <= a * b * c
z <= b * c * d
y <= a * b * c
z <= b * c * d
a
X
b
X y
c
4 Multipliers!
X
X z
d
y <= a * (b * c)
z <= (b * c) * d
y <= a * (b * c)
z <= (b * c) * d
b 3 Multipliers!
X
c
X y This is called sharing
a common subexpressions
Some synthesis tools do this
automatically, but some
dont!
Parentheses guide synthesis
tools
X z
If (b*c) is used repeatedly,
d assign to temporary signal
25 MHz System
Counter, Decode
Decode
State Value
Value Logic
Logic
Machine xx
40 ns
50 MHz System
Counter, Decode
Decode
State Value
Value Logic
Logic
Machine x-1
x-1
20 ns 20 ns
a
X
b
X z
c
X
d
Introduction to Testbenches
Purpose of testbench
Three classes of traditional testbenches
General testbench methods
Self verification methods
Arrays for stimulus & results
TEXTIO for stimulus & results
-- clk initialized to 0
SIGNAL clk : std_logic := 0;
(uses IEEE.numeric_std.all)
clk_assignment mycode.vhd
clk
wavegen_process compare_process
in1
in2 out1
in3
out2
reset_assignment clk
stim: PROCESS
VARIABLE error : BOOLEAN; Code repeated for each test case
BEGIN Result checked
WAIT UNTIL falling_edge(clk);
a <= (OTHERS => 0);
b <= (OTHERS => 0);
WAIT FOR 40 ns;
IF (sum /= 0) THEN
Simple self verifying test bench
error := TRUE; Each sub-block within process
END IF;
assigns values to a,b and waits
WAIT UNTIL falling_edge(clk); to compare sum to its
a <= 0010;
b <= 0011;
predetermined result
WAIT FOR 40 ns; Code not very efficient
IF (sum /= 5) THEN
error := TRUE;
Each test case may require a
END IF; lot of repeated code
-- repeat above varying values of a and b
Improve this code by introducing
a procedure
WAIT;
END PROCESS stim;
VARIABLE
VARIABLE vector
vector :: test_record_type;
test_record_type;
vector
vector :=
:= (a
(a =>
=> 0010,
0010, b
b =>
=> 0011,
0011, sum
sum =>
=> 0101);
0101);
Report (optional)
Displays text in simulator window
Must be type string
Enclose character strings in
Other data types must be converted (discussed later)
Severity (optional)
Expression choices: NOTE, WARNING, ERROR, FAILURE
ERROR is the default
Results of severity depend on simulator
e.g. By default, ModelSim tool ends simulation on failure only
Syntax
REPORT
REPORT <text_string>
<text_string>
SEVERITY
SEVERITY <expression>;
<expression>;
Severity (optional)
Same options as ASSERT except NOTE is the default
<data_type>IMAGE(obj)
Type attribute that converts obj of type <data_type> to its string
equivalent with no leading or trailing whitespace
Examples
INTEGERIMAGE(integer_variable)
TIMEIMAGE(time_variable)
std_logicIMAGE(1_bit_std_logic_variable)
Conversion utilities
Cannot use IMAGE for vectors
<data_type> must be a scalar type or subtype
Simple web search can provide most (if not all) required conversion
utilities
Testbench passes
ModelSim Transcript Window
**
** Failure:
Failure: ---VECTORS
---VECTORS PASSED---
PASSED---
Time:
Time: 288
288 ns
ns Iteration:
Iteration: 00 Process:
Process: /record_add_tb/test
/record_add_tb/test File:
File:
Break
Break inin Process
Process test
test at
at record_tb.vhd
record_tb.vhd line
line 59
59
ENTITY file_tb IS
END ENTITY file_tb;
COMPONENT adder
PORT (clk : IN std_logic;
a, b: IN std_logic_vector(3 DOWNTO 0);
sum: OUT std_logic_vector(3 DOWNTO 0));
END COMPONENT;
-- create file handles to access text files, one for reading vectors and
-- another to write output messages
FILE vectorfile: TEXT OPEN READ_MODE IS vectors.txt;
FILE results: TEXT OPEN WRITE_MODE IS results.txt;
240
240 ns
ns Calc=
Calc= 0100,
0100, Exp=
Exp= 1001
1001
Parameterized Code
ENTITY
ENTITY reg_bank
reg_bank IS IS
GENERIC
GENERIC ((
tplh
tplh ,, tphl
tphl :: time
time :=
:= 55 ns;
ns;
tphz,
tphz, tplz
tplz :: time
time :=
:= 33 ns;
ns;
size
size :: integer
integer :=:= 1;
1;
);
);
PORT
PORT ((
clk
clk :: IN
IN std_logic;
std_logic;
dd :: IN
IN std_logic_vector
std_logic_vector (size (size -- 11 DOWNTO
DOWNTO 0);
0);
qq :: OUT
OUT std_logic_vector
std_logic_vector (size (size -- 11 DOWNTO
DOWNTO 0)
0)
);
);
END
END ENTITY
ENTITY shift_reg;
shift_reg;
u1
u1 :: counter
counter
GENERIC
GENERIC MAP
MAP (width
(width =>
=> 16)
16)
PORT
PORT MAP
MAP (clk
(clk =>
=> tclk,
tclk, clr
clr =>
=> tclr,
tclr, sload
sload =>
=> tsload,
tsload,
cnt_en
cnt_en =>=> tcnt_en,
tcnt_en, data
data =>
=> tdata,
tdata, qq =>
=> tq);
tq);
top_counter
16
counter
clk sload
tclk tsload
clr data
tclr data
cnt_en q
cnt_en tq
ENTITY
ENTITY top_counter
top_counter IS IS
PORT
PORT ((
tclk,
tclk, tclr,
tclr, tsload,
tsload, tcnt_en
tcnt_en :: IN
IN std_logic;
std_logic;
tdata
tdata :: IN
IN std_logic_vector
std_logic_vector (15 (15 DOWNTO
DOWNTO 0);0);
tq : OUT std_logic_vector (15
tq : OUT std_logic_vector (15 DOWNTO 0)DOWNTO 0)
););
END
END ENTITY
ENTITY top_counter;
top_counter;
ARCHITECTURE
ARCHITECTURE logic logic OF
OF top_counter
top_counter ISIS
COMPONENT
COMPONENT pcounter
pcounter
GENERIC
GENERIC (width
(width :: INTEGER);
INTEGER);
PORT
PORT ((
clk,
clk, clr,
clr, sload,
sload, cnt_en
cnt_en :: IN
IN std_logic;
std_logic;
data
data :: IN
IN std_logic_vector
std_logic_vector (width
(width -- 11 DOWNTO
DOWNTO 0);
0);
qq :: OUT std_logic_vector (width - 1
OUT std_logic_vector (width - 1 DOWNTO 0)DOWNTO 0)
););
END
END COMPONENT;
COMPONENT;
BEGIN
BEGIN
u1
u1 :: pcounter
pcounter
GENERIC
GENERIC MAP
MAP (width
(width =>
=> 16)
16)
PORT
PORT MAP (clk => tclk, clr =>
MAP (clk => tclk, clr => tclr,
tclr, sload
sload =>
=> tsload,
tsload,
cnt_en
cnt_en =>=> tcnt_en,
tcnt_en, data
data =>
=> tdata,
tdata, qq =>
=> tq);
tq);
END
END ARCHITECTURE
ARCHITECTURE logic;
logic;
u1
u1 :: counter
counter
GENERIC
GENERIC MAP
MAP (width
(width =>
=> 16)
16)
PORT
PORT MAP
MAP (clk
(clk =>
=> tclk,
tclk, clr
clr =>
=> tclr,
tclr, ,,
cnt_en
cnt_en =>=> tcnt_en,
tcnt_en, ,, qq =>
=> tq);
tq);
ENTITY counter IS
GENERIC (width : INTEGER := 8); Initialized
Initialized to
to 88
PORT (
clk, clr, cnt_en : IN std_logic;
sload : IN std_logic := 0;
data : IN std_logic_vector (width - 1 DOWNTO 0) := (OTHERS => 0); Initialized
Initialized to
to Zeros
Zeros
q : OUT std_logic_vector (width - 1 DOWNTO 0)
);
END ENTITY counter;
ARCHITECTURE logic OF counter IS
BEGIN
VARIABLE cnt : INTEGER RANGE 0 TO (2**width)-1;
u1
u1 :: counter
counter
GENERIC
GENERIC MAP
MAP (width
(width =>
=> 16)
16)
PORT
PORT MAP
MAP (clk
(clk =>
=> tclk,
tclk, clr
clr =>
=> tclr,
tclr,
cnt_en
cnt_en =>=> tcnt_en,
tcnt_en, qq =>
=> tq);
tq);
top_counter
16 No error messages (warnings
counter
possible) since sload & data are
clk
8
sload
initialized
tclk 0 May map to OPEN for clarity
clr data
tclr 0 Setting width to 16 overrides
cnt_en cnt_en q
tq default setting of 8
Syntax
label
label :: FOR
FOR <identifier>
<identifier> IN
IN <range>
<range> GENERATE
GENERATE
--concurrent
--concurrent statements
statements
END
END GENERATE
GENERATE label;label;
BEGIN
RAM_GEN : FOR i IN 7 DOWNTO 0 GENERATE
u : ram
GENERIC MAP (width_ad => taddress'high+1)
PORT MAP (clk => tclk, we => twe, data => tdata(i), 88 RAMs
RAMs Generated
Generated
address => taddress, q => tq(i));
END GENERATE;
clk
tdata1
X1 RAM q1
tdata2
X1 RAM q2
tdata3
X1 RAM q3
tdata4
X1 RAM q4
tdata5
X1 RAM q5
tdata6
X1 RAM q6
tdata7
X1 RAM q7
BEGIN
RAM_GEN : FOR i IN tdataRANGE GENERATE
u : ram
GENERIC MAP (width_ad => taddressHIGH+1)
PORT MAP (clk => tclk, we => twe, data => tdata(i), RANGE
RANGE attribute
attribute used
used
address => taddress, q => tq(i));
END GENERATE; for
for increased
increased flexibility
flexibility
END ARCHITECTURE logic;
Syntax
label
label :: IF
IF <expression>
<expression> GENERATE
GENERATE
//// generated
generated structure
structure
ELSE
ELSE GENERATE
GENERATE
//// alternate
alternate generate
generate structure
structure
END
END GENERATE
GENERATE label;label;
U:
U: LPM_ADD_SUB_UNSIGNED
LPM_ADD_SUB_UNSIGNED
generic
generic map
map (LPM_WIDTH
(LPM_WIDTH =>
=> LPM_WIDTH,
LPM_WIDTH, LPM_DIRECTION
LPM_DIRECTION =>=> LPM_DIRECTION,
LPM_DIRECTION,
LPM_PIPELINE
LPM_PIPELINE =>
=> LPM_PIPELINE,
LPM_PIPELINE, LPM_TYPE
LPM_TYPE =>
=> LPM_TYPE,
LPM_TYPE,
LPM_HINT => LPM_HINT)
LPM_HINT => LPM_HINT)
port
port map
map (DATAA
(DATAA =>=> DATAA,
DATAA, DATAB
DATAB =>
=> DATAB,
DATAB, ACLR
ACLR =>
=> ACLR,
ACLR, CLOCK
CLOCK =>
=> CLOCK,
CLOCK,
CIN
CIN => CIN, ADD_SUB => ADD_SUB, RESULT =>
=> CIN, ADD_SUB => ADD_SUB, RESULT => RESULT,
RESULT, COUT
COUT =>
=> COUT,
COUT,
OVERFLOW => OVERFLOW, CLKEN => CLKEN);
OVERFLOW => OVERFLOW, CLKEN => CLKEN);
end
end generate;
generate;
V:
V: LPM_ADD_SUB_SIGNED
LPM_ADD_SUB_SIGNED
generic
generic map
map (LPM_WIDTH
(LPM_WIDTH =>
=> LPM_WIDTH,
LPM_WIDTH, LPM_DIRECTION
LPM_DIRECTION =>=> LPM_DIRECTION,
LPM_DIRECTION,
LPM_PIPELINE
LPM_PIPELINE =>
=> LPM_PIPELINE,
LPM_PIPELINE, LPM_TYPE
LPM_TYPE =>
=> LPM_TYPE,
LPM_TYPE,
LPM_HINT => LPM_HINT)
LPM_HINT => LPM_HINT)
port
port map
map (DATAA
(DATAA =>=> DATAA,
DATAA, DATAB
DATAB =>
=> DATAB,
DATAB, ACLR
ACLR =>
=> ACLR,
ACLR, CLOCK
CLOCK =>
=> CLOCK,
CLOCK,
CIN
CIN => CIN, ADD_SUB => ADD_SUB, RESULT =>
=> CIN, ADD_SUB => ADD_SUB, RESULT => RESULT,
RESULT, COUT
COUT =>
=> COUT,
COUT,
OVERFLOW => OVERFLOW, CLKEN => CLKEN);
OVERFLOW => OVERFLOW, CLKEN => CLKEN);
end
end generate;
generate;
end
end LPM_SYN;
LPM_SYN;
Syntax
label:
label: case <expression> GENERATE
case <expression> GENERATE
when
when <condition1>
<condition1> =>
=> //// generated
generated structure
structure
when
when <condition2>
<condition2> =>
=> //// generated
generated structure
structure
when
when <conditionN>
<conditionN> =>
=> //// generated
generated structure
structure
END
END GENERATE
GENERATE label;
label;
Summary
Instructor-Led Online
Training Training
http://www.altera.com/training
View training class schedule and register for a class
2012 Altera CorporationConfidential
174
Altera Technical Support
Appendix
ENTITY
Used to define external view of a model. i.e. symbol
ARCHITECTURE
Used to define the function of the model. i.e. schematic
CONFIGURATION
Used to associate an architecture with an entity
PACKAGE
Collection of information that can be referenced by VHDL models.
i.e. LIBRARY
Consists of two parts: PACKAGE declaration and PACKAGE
body
ENTITY cmpl_sig IS
PORT ( a, b, sel : IN std_logic;
x, y : OUT std_logic);
END ENTITY cmpl_sig;
Behavioral modeling
A component is described by its input/output response
Structural modeling
A component is described by interconnecting lower-level
components/ primitives
Higher-level component
input1 output1
Lower-level
Component1
Lower-level
Component0
inputn outputn
Explicit Process
Implied Processes proc1: PROCESS(a, b)
c <= a and b; BEGIN
y <= c; c <= a AND b;
END PROCESS proc1;
Sequential statements
IF-THEN statement
CASE statement
Looping statements
WAIT statements
Note: Simple signal assignment is considered both a sequential statement and a concurrent statement
Architecture scope
Local Scope
Scope (communicate between
(inside processes)
processes within architecture)
Updated at end of
current delta cycle
Behavior (new value not immediately
Updated immediately
available)