EmbDev.net

Forum: FPGA, VHDL & Verilog Accessing dut variables in testbench : VHDL


von Muhammad Tahir R. (Company: Self) (tahirsengine)


Rate this post
useful
not useful
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;

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Muhammad Tahir R. wrote:
> but still no success
What do you want to do? What should happen? And what happens instead?


BTW:
>    -- hold reset state for 100 ns.
If you have a comment, it should reflect what happens. Otherwise you'd 
better delete it.

von Muhammad Tahir R. (Company: Self) (tahirsengine)


Rate this post
useful
not useful
Lothar M. wrote:
> Muhammad Tahir R. wrote:
>> but still no success
> What do you want to do? What should happen? And what happens instead?
>
I want to evaluate that assert expression, and when that variable(SW) 
doesn't have the required value(as in assertion) then it should throw an 
error. At the moment, although code is not failing, but this expression 
is also not getting evaluated property, or at all.
Is this right way to check value of SW variable?

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Muhammad Tahir R. wrote:
> SW variable?
SW ist not a variable. It is a signal. There a huge difference 
between...

> Is this right way to check value of SW variable?
See it that way: a testbench is just a "normal" VHDL entity without any 
ports to somewhere. But in this VHDL module you instantiate components, 
maybe one, maybe several. Those components themself may have other 
components in their entity, and so forth.
And because a testbench is a VHDL module like any other you cannot 
access internal signals just with a '.'

The usual way is to pass signals from the component to the "upper level" 
entity is by means of the port list like the counter, reset and clk...

: Edited by Moderator
von Bernhard K. (bkom)


Rate this post
useful
not useful
Muhammad Tahir R. wrote:
> if(en = '1') then assert << signal dut.sw : std_logic >> = '1'
> report "Second Assertion

works ony with VHDL2008 setting in your simulator - for examples see:
https://www.doulos.com/knowhow/vhdl/vhdl-2008-easier-to-use/
(scroll down)

another example:
https://support.xilinx.com/s/question/0D52E00006hpXtRSAU/correct-syntax-to-reference-a-hierarchical-signal-in-a-vhdl-2008-testbench?language=en_US

: Edited by User
Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.