Beruflich Dokumente
Kultur Dokumente
11 - 22 November 2013
Cristian SISTERNA
National University of San Juan
San Juan
Argentina
Introduction to VHDL for
Implementing Digital Designs
into FPGAs
HDL
(VHDL/Verilog)
FPGA ASIC
¾ Easy to debug
¾ Parameterized designs
¾ Re-uso
¾ IP Cores (free) available
VHDL
VHDL
Synthesizable
Used to implement
the design into
hardware (for
instance in FPGA)
Cristian Sisterna ICTP2013 6
VHDL - Synthesis
with tmp select
j <= w when “1000”,
x when “0100”,
VHDL y when “0010”,
z when “0001”,
Code '0‘when others;
Design
Constraints FPGA list of
NET CLOCK PERIOD = 50 ns; Components and
NET LOAD LOC = P
Synthesis Connections
Design Tool
Attributes
attribute syn_encoding of my_fsm:
type is “one-hot”;
FPGA Library
of Components
Virtex 4
Spartan 6
Cristian Sisterna ICTP2013 7
VHDL ‘Description’ Examples
x if(sel=‘1’) then
0 z <= y;
z
else
y 1 z <= x;
sel end if;
if(clk )then
d q q <= d;
else
clk
q <= q;
end if;
if(clk )then
q <= d;
end if;
if(rising_edge(clk))then
q <= d;
end if;
Cristian Sisterna ICTP2013 9
VHDL – Module Structure
ff.vhd
entity
I/O
d q
clk architecture
Functionality
architecture test of ff is
begin
process(clk)
d q begin
if(rising_edge(clk)) then
q <= d;
clk end if;
end test;
Cristian Sisterna ICTP2013 11
VHDL Code – Is it really Works? ?
Test Bench
Stimulus Tested
Signals Unit Under Test Signals
Synthesis &
Optimization
Compilation
Timing
Functional Verification
Verification
Front-end Tools
PROCESS PROCESS
Signals Functional Functional
Signals Signals
Block Block
Signals
Signal Declarations:
A signal is declared in the declarative part of an architecture,
and it has two parts:
Signal Type
Signal Name
Port Mode boolean
std_logic/std_ulogic
in std_(u)logic_vector
out unsigned
inout signed
buffer integer
Cristian Sisterna ICTP2013 24
Port Modes
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL; r qa
ENTITY simp IS
t
PORT (
r, t, g, h : IN STD_LOGIC; g qb
qb : OUT STD_LOGIC
); h
END ENTITY simp;
qa <= r OR t;
• r, t, g, h, and qb are signals (by default)
qb <= (qa AND NOT (g XOR h));
• qa is a buried signal and needs to be
END ARCHITECTURE logic; declared
Examples
All bits
temp <= “10101010”;
temp <= x”aa” ; -- Hexadecimal
VHDL also supports ‘o’ for octal and ‘b’ for binary
Bit-slicing
temp (7 DOWNTO 4) <= “1010”;
Single bit
temp(7) <= ‘1’;
- Different values at different times
rst <= x”00”, x”AA” after 50 ns, x”FF” after 100 ns; -- just for simulation
counter := 5;
ASK := TRUE;
SIGNALS VARIABLES
<= :=
Assign utility Represent circuit Represent local storage
interconnection
Constant declaration:
-- case 1
architecture ej_constant of ej1 is
constant tpo_delay: time := 10 ns;
begin
....
end architecture ej_constant;
-- case 2
proc_ejemplo: process(A, B)
constant t_hold: time:= 5 ns;
begin
....
end process;
-- case 3
package my_package is
constant mi_contador: integer:= 5;
constant max_cuenta: std_logic_vector(3 downto 0):= "1111";
end package;
-- case 4
entity CPU is
generic (Add_width:integer:= 15);-- implicit constant
port(Input_CPU: in bit_vector(Add_width-1 downto 0);
Output_CPU: out bit_vector(31 downto 0));
end CPU;
Based:
2#100100001# = 145 16#FFCC# = 65484
ENTITY <entity_name> IS
Generic declarations
Port Declarations
END ENTITY <entity_name> ; (1076-1993 version)
Cristian
48 Sisterna ICTP2013
ENTITY : Generic Declaration
ENTITY <entity_name> IS
GENERIC (
CONSTANT tmax_cnt : integer = 324;
-- Note CONSTANT is assumed and is not required
default_value : INTEGER := 1;
cnt_dir : STRING := “up”
);
PORT declarations
END ENTITY <entity_name> ; --( 1076-1993 version)
Cristian
51 Sisterna ICTP2013
VHDL - Basic Modeling Structure
ENTITY entity_name IS
generics
port declarations
END ENTITY entity_name;
ENTITY cmpl_sig IS
PORT ( ENTITY
a, b, sel : IN BIT;
ARCHITECTURE
x, y, z : OUT BIT
);
END ENTITY cmpl_sig; a a
x x
ARCHITECTURE logic OF cmpl_sig IS b
BEGIN sel
-- simple signal assignment
x <= (a AND NOT sel) OR (b AND sel); a
-- conditional signal assignment
y
b y
y <= a WHEN sel='0' ELSE b
b; sel
-- selected signal assignment a
WITH sel SELECT z z
z <= a WHEN '0', b
b WHEN '1', sel sel
'0' WHEN OTHERS;
END ARCHITECTURE logic;
Type BIT
2 logic value system (‘0’, ‘1’)
SIGNAL a_temp : BIT;
Bit_vector array of bits
SIGNAL temp : BIT_VECTOR (3 DOWNTO 0);
SIGNAL temp : BIT_VECTOR (0 TO 3);
Type BOOLEAN
(False, true)
Type INTEGER
Positive and negative values in decimal
SIGNAL int_tmp : INTEGER; -- 32-bit number
SIGNAL int_tmp1 : INTEGER RANGE 0 TO 255; --8 bit number
Type NATURAL
Integer with range 0 to 232
Type POSITIVE
Integer with range 1 to 232
Type CHARACTER
ASCII characters
Type STRING
Array of characters
Type TIME
Value includes units of time (e.g. ps, us, ns, ms, sec, min, hr)
Type REAL
Double-precision floating point numbers
Type STD_LOGIC
9 logic value system (‘U’, ‘X’, ‘0’, ‘1’, ‘Z’, ‘W’, ‘L’, ‘H’, ‘-’)
z ‘1’: Logic high z ‘U’: Undefined
z ‘0’: Logic low z ‘H’: Weak logic high
z ‘X: Unknown z ‘L’: Weak logic low
z ‘Z’: (not ‘z’) Tri-state z ‘W’: Weak unknown
z ‘-’: Don’t Care
Resolved type: supports signals with multiple drivers
z Driving multiple values onto same signal results in known value
Type STD_ULOGIC
Same 9 value system as STD_LOGIC
Unresolved type: Does not support multiple signal drivers
z Driving multiple values onto same signal results in error
Subtype
Enumerated Data Type
Array
A constrained type
Synthesizable if base type is synthesizable
Use to make code more readable and flexible
Place in package to use throughout design
BEGIN
BEGIN
…
mem_64x8_a(12) <= x“AF”;
mem_64x8_b(50) <= “11110000”;
…
END ARCHITECTURE logic;
Three types
Simple signal assignment
Conditional signal assignment
Selected signal assignment
r
Ö Parenthesis ( ) give the
t order of operation
g qb
h
Expressions use VHDL operators to describe behavior
Example:
Example:
ENTITY cmpl_sig IS
PORT (
a, b, sel : IN STD_LOGIC; sel is of STD_LOGIC data type
z : OUT STD_LOGIC
); • What are the values for a
END ENTITY cmpl_sig;
STD_LOGIC data type
ARCHITECTURE logic OF cmpl_sig IS • Answer: {‘0’,’1’,’X’,’Z’ … }
BEGIN
-- Selected signal assignment
WITH sel SELECT
• Therefore, is the WHEN OTHERS
z <= a WHEN '0',
b WHEN '1', clause necessary?
'0' WHEN OTHERS; • Answer: YES
END ARCHITECTURE logic;
execution
Until a
condition is wait
satisfied
Once the process has been executed, it will wait for the
next satisfied condition
Cristian Sisterna ICTP2013 74
process - Syntax
1
process sensitivity_list
[declarations;]
begin
sequential_statements;
end process;
2
process
[declarations;]
begin
sequential_statements;
wait on sensitivity_list;
end process;
sensitivity_list
List of all the signals that are able to trigger the process
Simulation tools monitor events on these signals
Any event on any signal in the sensitivity list will cause to
execute the process at least once
declarations
Declarative part. Types, functions, procedures and
variables can be declared in this part
Each declaration is local to the process
sequential_statements
All the sequential statements that will be executed each
time that the process is activated
entity ff_example is
port(
d : in std_logic;
clk : in std_logic;
q : out std_logic);
end entity;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity counter_ud is
generic(cnt_w: natural:= 4)
port (
-- clock & reset inputs
clk : in std_logic;
rst : in std_logic;
-- control input signals
up_dw : in std_logic;
-- ouptuts
count : out std_logic_vector(cnt_w-1 downto 0));
end counter_ud;
begin
count_proc: process(clk, rst)
begin
if(rst='0') then
count_i <= (others => '0');
elsif(rising_edge(clk)) then
if(up_dw = '1') then -- up
count_i <= count_i + 1;
else -- down
count_i <= count_i - 1;
end if;
end if;
end process count_proc;
Syntax
if <boolean_expression> then
<sequential_statement(s)>
[elsif <boolean_expression> then
<sequential_statement(s)>]
. . .
[else
<sequential_statement(s)>]
end if;
library ieee;
use ieee.std_logic_1163.all;
entity if_example_9 is
port(
sel1,a1,b1: in std_logic;
sel2,a2,b2: in std_logic;
sel3,a3,b3: in std_logic;
y1,y2,y3 : out std_logic);
end entity;
Latch !
Cristian Sisterna ICTP2013 102
if-then-elsif-else-end if
example 4_4
Synthesis result
Conclusions
The inadequate use of the if statement can generate
unwanted logic
Using nested if-then it is possible:
z Introduce priority
z Use more logic
z Generate latches
entity mux4 is
port ( sel : in std_ulogic_vector(1 downto 0);
d0, d1, d2, d3 : in std_ulogic;
z : out std_ulogic );
end entity mux4;
architecture demo of mux4 is
begin
out_select : process (sel, d0, d1, d2, d3) is
begin
case sel is
when “00” => z <= d0;
when “01” => z <= d1;
when “10” => z <= d2;
when others => z <= d3;
end case;
end process out_select;
end architecture demo;
. . .
case opcode is
when load | add | substract =>
operand <= memory_operand;
when store | jump |jumpsub | branch =>
operand <= address_operand;
when others =>
operand <= ‘0’;
end case;
. . .
case opcode is
when add to load =>
operand <= memory_operand;
when branch downto store =>
operand <= address_operand;
when others =>
operand <= ‘0’;
end case;
• Use of case
– Flat: do not induce unwanted prioritization
– Device logic utilization is more predictable
– Compiler force you to cover all cases
– Easier to read
– “truth-table-like”
[loop_label]:<iteration_scheme> loop
<sequential_statements>
end loop [loop_label];
<identifier>
• The identifier is called loop parameter, and for each
iteration of the loop, it takes on successive values of the
discrete range, starting from the left element
• It is not necessary to declare the identifier
• By default the type is integer
• Only exists when the loop is executing
--=====================================================--
-- Identifier declared in the loop is local to the loop
--======================================================--
process
variable a, b: int;
begin
a:=10;
for a in 0 to 7 loop
b:=a;
end loop;
-- a = ?; b = ?
end process;
-- process (a, b)
-- begin
-- matches(7) <= not (a(7) xor b(7));
-- matches(6) <= not (a(6) xor b(6));
-- ..
-- matches(0) <= not (a(0) xor b(0));
-- end process;
Example
for_loop_1.vhd:
match_bit
entity count_ones is
port(vec: in std_logic_vector(15 downto 0);
count: out std_logic_vector(3 downto 0))
end count_ones;
architecture behavior of count_ones is
begin
cnt_ones_proc: process(vec)
variable result: unsigned(3 downto 0);
begin
result:= (others =>'0');
for i in vec’range loop
if vec(i)='1' then
result := result + 1;
end if;
end loop;
count <= std_logic_vector(result);
end process cnt_ones_proc;
end behavior;
library ieee;
use ieee.std_logic_1164.all;
entity generic_??? is
generic(width: positive := 3);
port (
sel : in std_logic_vector(width-1 downto 0);
en : in std_logic;
y_n : out std_logic_vector((2**width)-1 downto 0)
);
end generic_???;
--======================================
-- exit syntax
--======================================
exit [loop_label] [when <condition>]
--========================================
-- next syntax
--========================================
entity count_ones is
port(vec : in std_logic_vector(15 downto 0);
count : out std_logic_vector(3 downto 0));
end count_ones;
library ieee;
use ieee.std_logic_1164.all;
entity signal_variable_loop is
port(
clk, data: in std_logic;
ya, yb : out std_logic_vector(3 downto 0));
end signal_variable_loop ;
library ieee;
use ieee.std_logic_1164.all;
entity signal_variable_loop is
port(
clk, data: in std_logic;
ya, yb : out std_logic_vector(3 downto 0));
end signal_variable_loop ;
var_loop: process(clk)
begin
if(rising_edge(clk)) then
pipe_a(0) := data;
for i in 1 to 3 loop
pipe_a(i) := pipe_a(i-1);
end loop;
ya <= pipe_a;
end if;
end process var_loop;
end beh;
pipe_a(0) := data;
pipe_a(1) := pipe_a(0);
pipe_a(2) := Pipe_a(1);
pipe_a(3) := pipe_a(2);
sig_loop: process(clk)
begin
if(rising_edge(clk)) then
pipe_b(0) <= data;
for i in 1 to 3 loop
pipe_b(i) <= pipe_b(i-1);
end loop;
yb <= pipe_b;
end if;
end process sig_loop;
end beh;
It is not synthesizable
assert <boolean_expression>
[report <string_expression>
[severity <severity_level>];
-- report syntax --
[report <string_expression>
[severity <severity_level>];
assert (packet_length /= 0)
report “empty network packet received”
severity warning;
process (clk)
begin
assert (now < 90 ns)
report “-- Stopping simulator --”
severity FAILURE;
end process;
RS-232
High-Speed
DDR ADC
Top
Counter
Inputs Nand2 Outputs
BRAM D_FF
component_label: component_name
[generic map (generic_assocation_list)]
port map (port_association_list);
-- component instantiation
U1: NAND2 port map (S1, S2, S3);
-- S1 associated with a
-- S2 associated with b actuals
-- S3 associated with z
-- component declaration
component NAND2
port (a, b: in std_logic;
z: out std_logic);
end component;
-- component instantiation
U1: NAND2 port map (a=>S1, z=>S3, b=>S2);
-- S1 associated with a,S2 with b and S3 with z
begin
U1: ex4 port map(a=>’0’, b=>b, q1=>dout, q2=>open);
end rtl;
BEGIN
FF8: dff GENERIC MAP(width_8)
PORT MAP (rst, clk, d8, q8);
FF16: dff GENERIC MAP(width_16)
PORT MAP (rst, clk, d16, q16);
FF32: dff GENERIC MAP(width_32)
PORT MAP (rst=>rst,clk=>clk,d=>d32, q=>q32);
END ejemplo;
GK: block
constant K: INTEGER := 2;
begin
FA: FULL_ADDER port map (CAR(K), A(K), B(K), CAR(K+1), SUM(K));
end block GK;
. . . .
GK: block
constant K: INTEGER := 0;
begin
FA: FULL_ADDER port map (CAR(K), A(K), B(K), CAR(K+1), SUM(K));
end block GK
Example 1
FPGA
x8 IBUFDS
.
High-Speed
.
ADC
(Max104) .
x8 IBUFDS
DDR Clock
component IBUFDS
generic map ( IOSTANDARD => "LVDS_25")
port map (
O => O, -- buffer output
I => I, -- Diff_p clock buffer input
IB => IB -- Diff_n clock buffer input);
end component;
. . . .
end package VCOMPONENTS;
port map(
O => p_bus(i),
I => p_bus_p(i),
IB=> p_bus_n(i)
);
end generate pbus_diff_sstl2;
Example 2
Typical examples:
Logic added just for debugging purposes
Additional processes or component instances used
only during simulation
entity my_system is
generic ( debug: boolean := true)
port (
. . .
);
end entity my_system;
Inputs
Current Outputs
Next Output
State
State Next Logic
Logic Current
Logic State
State
CLK
RST
Inputs Current
Next Current State
Outputs
O
Output Sync
State State
Next Logic Output
Logic Logic
State FFs
CLK
RST
Sync Outputs
Output
FFs
Inputs
Next Current
State State
Logic Next Logic Current
State State
CLK
RST
Sync
Output Output A
FFs
Inputs Current
Next Current State ....
State State
Next Logic
Logic Sync
State
Output Output Z
FFs
CLK
RST
Specification
Declare the signals for the next state and current state of the
state machine as signal of the enumerated data type already
defined for the state machine:
S0 S1
X=0 Z=0 Z=1 X=0
X=1
Mealy FSM
X=1
Z=1
X=0 S0 S1 X=0
Z=0 Z=1
X=1
Z=0
Cristian Sisterna ICTP2013 222
Style A - Moore State Machine
Clock
Reset
Moore
Mealy
Clock
Reset
Cristian Sisterna ICTP2013 226
Style B - Mealy State Machine
State, Next State and Output Logic
process(clk, rst)
begin
if(rst = ‘1’) then
state <= S0;
Z <= ‘0’;
elsif (rising_edge(clk)) then
case state is
when S0 =>
if (X=’0’) then
state <= .... ;
Z <= ... ;
Is elsif (X=’1’) then
Os
state <= .... ;
Z <= ... ;
end if;
when S1 =>
if (X = ‘0’) then
...
end if;
end case;
end if;
end process;
Clock
Reset
Moore
Mealy
Clock
Reset
Clock
Reset
Moore
Mealy
process (state, X)
Present State Logic
begin
next_state <= state; process (clk, rst)
case state is begin
when S0 => if(rst = ‘1’) then
if(X =’1’) then state <= S0;
Is next_state <=S1; elsif (rising_edge(clk)) then
end if; state <= next_state;
Z <=‘0’; end if;
when S1 => end process;
if( X = ‘1’) then
next_state <=S0;
end if;
Z <=‘1’;
end case;
end process;
Clock
Reset
process (state, X)
begin Present State Logic
next_state <= state;
Z <= ... ; process (clk, rst)
case state is begin
when S0 => if(rst = ‘1’) then
if(X =’1’) then state <= S0;
Is next_state <= ... ; elsif (rising_edge(clk)) then
Z <= ... ; state <= next_state;
end if; end if;
when S1 => end process;
if( X = ‘1’) then
next_state <= ... ;
Z <= ... ;
end if;
end case;
end process;
Clock
Reset
Moore
Mealy
Clock
Reset
Specify as follows:
syn_encoding in SCOPE
State
Table
==============================================
* Advanced HDL Synthesis *
==============================================
Analyzing FSM <FSM_0> for best encoding.
Optimizing FSM <rs232_tx/tx_current_state/FSM> on signal
<tx_current_state[1:3]> with sequential encoding.
-----------------------------
State | Encoding
-----------------------------
idle | 000
start | 001
shift | 010
parity | 011
stop_1bit | 100
-----------------------------
1 bit de start
8 bits de datos
Paridad programable: paridad/no paridad, par/impar
1 bit de stop
Frecuencia de transmisión por defecto es de 9600
Bauds, pero el código debe permitir también otras
frecuencias como: 4800, 38400, 115200 Bauds.
RS-232 Tx format
Parity 00
Dato(7:0) DatoSerie
01
E1
SysClock Reg
E0 Desplaza 10
miento
DatoSent
FSM Done
StartTx
RS232 Tx Controller
StartStopBit
SysReset
Sel1, Sel0
Function
- Return only one value
- Executed in zero simulation time
- Can be invoked from an expression
Procedure
- Return zero or several values
- Can or can not be executed in zero simulation
time (wait statement)
Behavioral part
Variables Constants
<parameters_list>
- mode in only
- signals only
<sequential_statements>
- sequential instructions only
- always has to end with a return statement
package my_pack is
function max(a,b: in std_logic_vector)
return std_logic_vector;
end package;
Declarative part
Behavioral part
<parameter_list>
in mode: to receive values
out mode: to return values
inout mode: to receive/return values
Parameters can be signals, variables and constants.
By default in = constant, out = variable
Can return as many values as are needed using the
out parameters
Cristian Sisterna ICTP2013 265
Procedure Calls
Can be used in sequential or concurrent
statements areas
Concurrent calls are activated by changes in
any signal associated with a parameter of
mode IN or INOUT
Sequential calls is executed whenever the
procedure is encounter during the execution
of the sequential code
Passing parameter list:
Association by name
Association by position
-- package body
package body my_package is
function int_to_bit_vector (int_vector: integer)
return bit_vector is
Function begin
Body ...
...
end int_to_bit_vector;
end my_package;
entity package_test_2 is
port(d1,d2,d3: in std_logic_vector(width-1 downto 0);
z: out std_logic_vector(width-1 downto 0);
q: out std_logic_vector(width-1 downto 0));
end;
process(d2,d3)
begin
z <= max(d3, d2); -- sequential call of the function
end process;
end;
Cristian Sisterna ICTP2013 281
Package Common Usage
package my_pack is
-- constants declarations
constant bus_width : natural:=2;
-- component declaration
component bcd_7segm is
port( led_outs : out std_logic_vector(6 downto 0);
bcd_inps : in std_logic_vector(3 downto 0)
);
end component;
component mux is
port( inf_inputs: in std_logic_vector(3 downto 0);
sel : in std_logic_vector(1 downto 0);
output : out std_logic);
end component;
end package my_pack;
entity bcd_7seg_top is
port ( . . .
. . . );
end;
U1: bcd_7segm
port map ( . . . );
U2: mux
port map ( . . . );
. . .
end beh;
entity bcd_7seg_top is
port ( . . .
. . . );
end;
U1: bcd_7segm
port map ( . . . );
U2: mux
port map ( . . . );
. . .
end beh;
Synthesis &
Optimization
Post_Synthesis
Verification
Functional Timing
Verification Verification
y Post-synthesis Verification:
y Not necessary unless several synthesis attributes
were used and it’s necessary to verify the behavior
after synthesis
Test bench
Test Bench
TB entity:
Empty declaration
TB architecture:
Component declaration
Local signal declaration
Component instantiation
Stimulus statements
Check values statements
Clock
Generation
Reset
Generation
Data
Verification
ch of test_my_desi
architecture testbench test_my_design is
component my_design is
port (a,b : in std_logic; Component declaration of the
x,y : out std_logic); device to test
end component;
begin
uut : my_design port map
(a=>as, b=>bs, x=>xs, y=>ys); Instantiated UUT in test
bench
as <= not(as) after 50 ns;
process begin
bs <= '1'; wait for 75 ns; Define the stimulus of the test
bs <= '0'; wait for 25 ns;
end process;
end testbench;
Cristian Sisterna ICTP2013 296
Test Bench – VHDL Template
library ieee;
use ieee.std_logic_1164.all;
-- architecture declaration
architecture tb of testbench is
-- component declaration: component to test
component device_under_test
port(list_of_ports);
end component;
generate_input_waveforms;
monitor_output_statements;
end tb;
Basic Usages:
wait for time;
wait on signal_list;
wait;
process
. . .
J <= ‘1’;
wait for 50 ns;-- process is suspended for 50 ns after J is
. . . -- assigned to ‘1’
end process;
process
. . .
wait until CLK = ‘1’;-- sync with CLK rising edge before
-- continuing of simulation
. . .
end process;
process
rst <= ‘1’;
wait for 444 ns;
rst <= ‘0’;
wait; -- used without any condition,
-- the process will be suspended
-- forever
end process;
Cristian Sisterna ICTP2013 301
Test Bench – Clock Generation 1
architecture testbench of test_my_design is
signal clk_50 : std_logic := ‘1’;
signal clk_75 : std_logic := ‘0’;
constant clk_period : time := 100 ns;
constant h_clk_period: time := 50 ns;
begin
begin
diff_duty_clk_cycle: process
begin
clk <= ‘0’;
wait for period * 0.60;
clk <= ‘1’;
wait for period * 0.40; -- 60% duty cycle
. . .
end architecture testbench;
begin
clk_cycle: process
begin
clk <= ‘0’;
wait for half_period; -- the clock will toggle
clk <= ‘1’;
wait for half_period; -- as long as the simulation
-- is running
end process clk_cycle;
. . .
begin
patt_gen_proc: process 00000101 00000000
begin 00000000 10101010 00000101
Add_Bus <= “00000000”;
wait for 10 ns;
begin
A_BUS <= “00000000”,
“00000101” after 10 ns,
“00001010” after 20 ns;
-- etc.
. . . 00000000 00001010
end absolute_timing; 00000101
10 20 30
test0
test1
begin
process
begin
for i in 0 to 4 loop
Add_BUS <= DATA(i);
for k in 1 to 7 loop
wait until rising_edge(clk);
end loop;
wait until falling_edge(clk);
end loop;
end process;
. . .
end array_usage;
entity dcd_2_4 is
port (in1 : in std_logic_vector (1 downto 0);
out1 : out std_logic_vector (3 downto 0));
end dcd_2_4;
--
architecture dataflow of dcd_2_4 is
begin
with in1 select
out1 <= "0001" when "00",
"0010" when "01",
"0100" when "10",
"1000" when "11",
"0000" when others;
end dataflow;
component decode
port (
in1 : in std_logic_vector(1 downto 0);
out1: out std_logic_vector(3 downto 0));
end component;
Cristian Sisterna ICTP2013 315
Test Bench Simple – Ex. Decoder 2:4
begin
decode_1: decode port map( Component
Instantiation
in1 => in1,
Inputs
out1 => out1); Stimulus and
Outputs port
apply_inputs: process map
begin
for j in input_vectors‘range loop
Data
in1 <= input_vectors(j); generation
wait for 50 ns;
end loop;
end process apply_inputs;
Data verification:
Input
stimulus
test_outputs: process
begin
wait until (in1 = "01");
Wait on
wait for 25 ns;
certain time
assert (out1 = "0110")
report"Output not equal to 0110"
severity ERROR;
… -- check the other outputs Check the
end process test_outputs; output
entity dcd_2_4 is
port (in1 : in std_logic_vector(1 downto 0);
clk : in std_logic ;
out1 : out std_logic_vector(3 downto 0));
end dcd_2_4;
architecture dataflow of dcd_2_4 is
signal out1_i: std_logic_vector (3 downto 0);
begin
with in1 select
out1_i <= "0001" when "00",
"0010" when "01",
"0100" when "10",
"1000" when "11",
"0000" when others;
reg_proc: process(clk)
begin
if(rising_edge(clk)) then
out1 <= out1_i;
end if;
end process reg_proc;
end dataflow;
Cristian Sisterna ICTP2013 321
Test Bench – Example 74LS194
library ieee;
use ieee.std_logic_1164.all;
entity ls194 is
port(
clk,mr_n,s0,s1,dsr,dsl_ser: in std_logic;
p : in std_logic_vector(3 downto 0);
q : out std_logic_vector(3 downto 0)
);
end ls194;
entity test_bench is
end test_bench;
architecture tb of test_bench is
component ls194 is
port(
clk,mr_n,s0,s1,dsr,ds: in std_logic;
p : in std_logic_vector(3 downto 0);
q : out std_logic_vector(3 downto 0));
end component;
-- internal signals
signal clk_tb: std_logic:= ‘1’;
signal s0_tb, s1_tb, mr_tb_n, dsr_tb, dsl_tb: std_logic:=
'0';
signal p_tb, q_tb : std_logic_vector (3 downto 0);
begin
-- component instantiation
U1: ls194 port map(
clk => clk_tb,
mr_n => mr_tb_n,
s0 => s0_tb,
s1 => s1_tb,
dsr => dsr_tb,
dsl => dsl_tb,
p => p_tb,
q => q_tb);
-- clock generation
clk_tb <= not clk_tb after clk_period/2;
Cristian Sisterna ICTP2013 327
Test Bench – Example 74LS194 (5)
main_proc: process
begin
-- check_init_proc
wait for 10 ns;
assert q_tb = "0000"
report " Initialization Error "
severity ERROR;
wait;
end process;
end tb;
Pre-defined User-defined/Synthesis
Attributes Attributes
<data_object/type/block>’attribute_identifier;
then:
and:
Attributes of Signals
True if there is an event on S in the current
S’event
simulation cycle, false otherwise
True if there is an transaction S in the current
S’active
simulation cycle, false otherwise
S’ last_event The time interval since the last event on S
S’last_active The time interval since the last transaction on S
S’last_value The value of S just before the last event on S
process
constant setup_time: time :=1.2 ns;
begin
wait until clk = ‘0’;
assert (data'stable(setup_time))
report “Setup Violation"
severity warning;
end process;
Ejemplos
attribute syn_preserve: boolean;
attribute syn_preserve of ff_data: signal is true;
Synthesis Attribute