2d TestBench Avtar
2d TestBench Avtar
Note the use of declaration initialization for the clock signal. We need this
because the default initialization value of a std_ulogic signal is 'U'. The first time
the signal assignment executes, not 'U' is 'X' and the remaining executions
(every 5 ns) of this statement yield not 'X' is 'X' - no clock sequence at all. The
disadvantage of this approach is that the clock runs forever - and so will the
simulation!
Rather than continuous generation, what we would like to do is implement
the clock generator inside a process so that a known number of clock cycles
can be generated, courtesy of a for loop.
-- architecture declarative part
Note that a VHDL constant is used to constant num_cycles : integer := 320;
allow easy maintenance of the signal clock : std_ulogic := '1';
simulation duration. However, this piece -- architecture statement part
of code doesn't really do the trick. After process
320 cycles, the loop exits and the begin
process is re-invoked, generating sets of for i in 1 to num_cycles loop
clock <= not clock;
320 cycles continuously. In order to stop
wait for 5 ns;
the simulation from running forever due clock <= not clock;
to continuous clock cycle generation, we wait for 5 ns;
can append a wait statement to this -- clock period = 10 ns
process to suspend the process end loop;
indefinitely after one pass of 320 cycles. end process;
process
begin
for i in 1 to num_cycles loop
clock <= not clock;
wait for 5 ns;
clock <= not clock;
wait for 5 ns;
-- clock period = 10 ns
end loop;
wait; -- simulation stops here
end process;
Wait Statement
Definition:
The wait statement is a statement that causes suspension of a process or a
procedure.
Simplified Syntax
wait;
• wait on signal_list;
Example 2 Example 3
assert Status = OPEN_OK assert not (S= '1' and R= '1')
report "The call to FILE_OPEN was not report "Both values of signals S
successful" and R are equal to '1'"
severity WARNING; severity ERROR;
When the values of the signals S
Having called the procedure FILE_OPEN, if
and R are equal to '1', the message
the status is different from OPEN_OK, it is
is displayed and the simulation is
indicated by the warning message.
stopped because the severity is set
to ERROR.
•ERROR can be used when assertion violation makes continuation of
the simulation not feasible (example 3);
•FAILURE can be used when the assertion violation is a fatal error and
the simulation must be stopped at once (example 4).
Event like illegal operation code are
Example 4
severe errors and should cause
assert Operation_Code = "0000" immediate termination of the
report "Illegal Code of Operation" simulation, which is forced by the
severity FAILURE; severity level FAILURE.
•The message is displayed when the condition is NOT met, therefore the message should be
an opposite to the condition.
•Concurrent assertion statement is a passive process and as such can be specified in an
entity.
•Concurrent assertion statement monitors specified condition continuously.
•Synthesis tools generally ignore assertion statements.
TestBench
Test bench is not defined by the VHDL Language Reference
Manual and has no formal definition.
Simplified Syntax
entity testbench_ent is
end entity testbench_ent;
architecture testbench_arch of testbench_ent is
signal declarations
component declarations
begin
component instantiations
stimuli (test vectors)
end architecture testbench_arch;
• The testbench is a specification in VHDL that plays the role of a
complete simulation environment for the analyzed system (unit
under test, UUT). A testbench contains both the UUT as well as
stimuli for the simulation.
• The UUT is instantiated as a component of the testbench and
the architecture of the testbench specifies stimuli for the UUT's
ports, usually as waveforms assigned to all output and
bidirectional ports of the UUT.
• The entity of a testbench does not have any ports as this serves
as an environment for the UUT. All the simulation results are
reported using the assert and report statements.
Example
entity Test_Decoder_bcd is begin
end entity Test_Decoder_bcd; U1:
architecture Struct_1 of Test_Decoder_bcd is Decoder_bcd port map (Enable,led,bcd);
bcd <= "00" after 5 ns,
component Decoder_bcd is "01" after 15 ns,
port ( "10" after 25 ns,
enable : in BIT; "11" after 35 ns;
led : in std_ulogic_vector(3 downto 0); assert bcd = "00" and led = "0001"
or bcd = "01" and led = "0010"
bcd : out BIT_VECTOR(1 downto 0)); or bcd = "10" and led = "0100"
end component Decoder_bcd; or bcd = "11" and led = "1000"
signal bcd: BIT_VECTOR(1 downto 0) := "11"; report "There is an incorrect value
signal Enable: BIT := '1'; on the output led"
severity error;
signal led: std_ulogic_vector (3 downto 0); end architecture Struct_1;
The design entity Test_Decoder_BCD is designed to verify correctness of the
Decoder_BCD. This test bench applies stimuli to the bcd inputs and when the
value of the sled signal is other than asingle '1' on the position corresponding
to the binary value of the bcd signal, with all other bits equal to zero, the
listed error is reported.