--Counter testbench
entity CounterTestBench is
end CounterTestBench;
--Content of the environment
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
architecture Bench of CounterTestBench is
constant BW : integer := 4;
signal Clk : bit := '0';
signal Rst, Ena : std_logic := '0';
signal Strt, Stp, Addr : unsigned ( BW - 1 downto 0 ) := ( others => '0' );
signal Halt : boolean := false;
--Unit Under Test (UUT)
component Counter
generic ( BIT_WIDTH : positive );
port (
CLK : in bit;
RESET, ENABLE : in std_logic;
STARTADR, STOPADR : in unsigned ( BIT_WIDTH - 1 downto 0 );
ADDRESS : out unsigned ( BIT_WIDTH - 1 downto 0 ) );
end component;
begin
--UUT
UUT: Counter generic map (BW) port map ( Clk, Rst, Ena, Strt, Stp, Addr );
--Clock generator
Clk <= not Clk after 10 ns when not Halt else unaffected;
--Test sequence
Test_sequence: process
procedure MakeSequence
( constant START_VALUE, STOP_VALUE, CYCLES_COUNT : positive ) is
begin
wait on Clk until Clk = '1';
Strt <= conv_unsigned ( START_VALUE, BW ) after 1 ns;
Stp <= conv_unsigned ( STOP_VALUE, BW ) after 1 ns;
Rst <= '1' after 1 ns;
Ena <= '0' after 1 ns;
wait on Clk until Clk = '1';
Rst <= '0' after 1 ns;
wait on Clk until Clk = '1';
Ena <= '1' after 1 ns;
for i in 0 to CYCLES_COUNT - 4 loop
wait on Clk until Clk = '1';
end loop;
Ena <= '0' after 1 ns;
wait on Clk until Clk = '1';
end MakeSequence;
begin
MakeSequence ( 2, 12, 16 ); --From 2 to 12, 16 cycles
MakeSequence ( 13, 5, 16 ); --From 13 down to 5, 16 cycles
Strt <= ( others => '0' ) after 1 ns;
Stp <= ( others => '0' ) after 1 ns;
Halt <= true after 50 ns;
wait;
end process Test_sequence;
end Bench;