Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

VHDL testbench read stimulus from file

Status
Not open for further replies.

ustinoff

Member level 2
Joined
Mar 6, 2016
Messages
45
Helped
4
Reputation
8
Reaction score
4
Trophy points
8
Location
Russia
Activity points
315
Hello everyone. I want to use some data from external file in my testbench.

Loading data from file:

Code:
------------------------------------------
--LOADING DATA FROM FILE-----------
------------------------------------------

type signal_storage is array (integer range <>)of std_logic_vector (data_width-1 downto 0);
signal mem : signal_storage (0 to data_storage-1);
   
        procedure Load_ROM (signal data_word :inout signal_storage) is
        -- Open File in Read Mode
        file romfile   :text open read_mode is "signal_record.txt";
        variable lbuf  :line;
        variable i     :integer := 0;
        variable fdata :std_logic_vector (data_width-1 downto 0);
        begin
         while not endfile(romfile) loop
            -- read digital data from input file
             readline(romfile, lbuf);
             read(lbuf, fdata);
             data_word(i) <= fdata;
             i := i+1;
         end loop;
        end procedure;

Now i need a counter for reading data from signal mem:

Code:
address_count :process(i_clk, i_read_en)
   begin
        if rising_edge(i_clk) then
         if i_read_en = '1' then
          r_reg <= r_next;
         end if;
        end if;
end process;

r_next <= (others=>'0') when r_reg = (samples-1) else r_reg + 1;

r_reg and r_next define as unsigned and of course i can use r_reg signal as address bus.

Stimulus process:

Code:
stim_proc: process
   begin         
        wait for 100 ns;
        i_arst <='1';
        wait for 300 ns;
        i_arst <='0';
        wait for 1000 ns;
        i_read_en <='1';
        i_data <= mem(to_integer(r_reg));
        wait for 6000 ns;
        i_read_en <='0';
        wait;
        assert false report "simulation ended" severity failure;
end process;

When i simulate the testbench i see next:
1) loading data from file - OK;
2) counting process - OK

But reading from mem is stoped on index "0" (reading from address "0"). Can someone tell me why?
 

ads-ee

Super Moderator
Staff member
Joined
Sep 10, 2013
Messages
7,860
Helped
1,817
Reputation
3,644
Reaction score
1,782
Trophy points
1,393
Location
USA
Activity points
59,415
Code:
i_read_en <='1';
i_data <= mem(to_integer(r_reg));
wait for 6000 ns;

These are not concurrently running statements they are sequential (a program) so it executes i_data <= mem(to_integer(r_reg)); once then sits there at the wait for 6000 ns; statement for 6000 ns of time before executing the next statement.

If you want i_data to update every time you have a new value for r_reg you need to put the assignment outside this process or in a separate process sensitive to r_reg.
 
Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top