Hey gals and guys,
So all I want is to access the "sw" from testbench and check it for a
certain value. I do it regularly in Verilog, but this VHDL is a little
harsh on me. Just see the "assert_test" process below. There in second
assert expression I tried to do that, but still no success. Any
soloutions to this situations?
-------------------------------------------------------------
Entity
-------------------------------------------------------------
1 | library IEEE;
|
2 | use IEEE.STD_LOGIC_1164.ALL;
|
3 | use IEEE.STD_LOGIC_UNSIGNED.ALL;
|
4 | -- FPGA projects using Verilog code VHDL code
|
5 | -- fpga4student.com: FPGA projects, Verilog projects, VHDL projects
|
6 | -- VHDL project: VHDL code for counters with testbench
|
7 | -- VHDL project: VHDL code for up counter
|
8 | entity UP_COUNTER is
|
9 | Port ( clk: in std_logic; -- clock input
|
10 | reset: in std_logic; -- reset input
|
11 | counter: out std_logic_vector(3 downto 0) -- output 4-bit counter
|
12 | );
|
13 | end UP_COUNTER;
|
14 |
|
15 | architecture Behavioral of UP_COUNTER is
|
16 | signal counter_up: std_logic_vector(3 downto 0);
|
17 | signal sw: std_logic;
|
18 | begin
|
19 | -- up counter
|
20 | process(clk)
|
21 | begin
|
22 | if(rising_edge(clk)) then
|
23 | if(reset='1') then
|
24 | counter_up <= x"0";
|
25 | sw <= '0';
|
26 | else
|
27 | counter_up <= counter_up + x"1";
|
28 | sw <= '1';
|
29 | end if;
|
30 | end if;
|
31 | end process;
|
32 | counter <= counter_up;
|
33 |
|
34 | end Behavioral;
|
-----------------------------------------------------------
Testbench
-----------------------------------------------------------
1 | -- Code your testbench here
|
2 | -- or browse Examples
|
3 | library IEEE;
|
4 | use IEEE.STD_LOGIC_1164.ALL;
|
5 | -- FPGA projects using Verilog code VHDL code
|
6 | -- fpga4student.com: FPGA projects, Verilog projects, VHDL projects
|
7 | -- VHDL project: VHDL code for counters with testbench
|
8 | -- VHDL project: Testbench VHDL code for up counter
|
9 | entity tb_counters is
|
10 | end tb_counters;
|
11 |
|
12 | architecture Behavioral of tb_counters is
|
13 |
|
14 | component UP_COUNTER
|
15 | Port ( clk: in std_logic; -- clock input
|
16 | reset: in std_logic; -- reset input
|
17 | counter: out std_logic_vector(3 downto 0) -- output 4-bit counter
|
18 | );
|
19 | end component;
|
20 | signal reset,clk, en: std_logic;
|
21 | signal counter:std_logic_vector(3 downto 0);
|
22 | begin
|
23 | dut: UP_COUNTER port map (clk => clk, reset=>reset, counter => counter);
|
24 | -- Clock process definitions
|
25 | clock_process :process
|
26 | begin
|
27 | clk <= '0';
|
28 | en <= '0';
|
29 | wait for 10 ns;
|
30 | clk <= '1';
|
31 | en <= '1';
|
32 | wait for 10 ns;
|
33 | end process;
|
34 |
|
35 |
|
36 | -- Stimulus process
|
37 | stim_proc: process
|
38 | begin
|
39 | -- hold reset state for 100 ns.
|
40 | reset <= '1';
|
41 | wait for 20 ns;
|
42 | reset <= '0';
|
43 | wait;
|
44 | end process;
|
45 |
|
46 | -- assertion test
|
47 | assert_test: process
|
48 | begin
|
49 | wait for 21 ns;
|
50 | if(en = '1') then assert reset /= '1' report "Assertion violation." severity error;end if;
|
51 | if(en = '1') then assert << signal dut.sw : std_logic >> = '1' report "Second Assertion violation." severity error;end if;
|
52 | wait;
|
53 | end process;
|
54 |
|
55 |
|
56 | end Behavioral;
|