Continue to Site

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.

[SOLVED] How do I read a test bench input from a txt file?

Status
Not open for further replies.

ggiacomo

Newbie level 3
Joined
Apr 17, 2018
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
49
I have a txt file containing my input signal represented by 12 bit numbers in column. I need to write a test bench file that allows me to read the .txt and assign these values to a signal. I know the basic of reading from a file, but I dont really know how to make the signal update following the txt. I tried to write some loops but I couldnt make it work. I know it probably is an easy question for more expert designers, thanks to anyone willing to help
 

Sure. I tried to adapt my usual program to work with std_logic_vector but surely I got something wrong. I cant even read the file properly atm. Signal y is declared in the architecture.


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
--read process
 process is
    file txt_file   : text;
    variable line_v : line;
    variable slv_v  : std_logic_vector(11 downto 0);
    variable good_v : boolean;
  begin
   
    file_open(txt_file, "Input.txt", read_mode);
    readline(txt_file, line_v);
    report "line_v: " & line_v.all;
    read(line_v, slv_v, good_v);
    file_close(txt_file);
    y<=slv_v;
    wait;
  end process;

 

Sure. My program looks like this atm. I didnt include initial declaration but that shouldnt be an issue, the program is compiling and executing as expected.

Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
process
           variable v_ILINE     : line;
           variable v_OLINE     : line;
           variable v_ADD_TERM1 : std_logic_vector(c_WIDTH-1 downto 0);
           variable v_ADD_TERM2 : std_logic_vector(c_WIDTH-1 downto 0);
           variable v_SPACE     : character;
            
         begin
        
           file_open(file_VECTORS, "Input.txt",  read_mode);
        
           while not endfile(file_VECTORS) loop
             readline(file_VECTORS, v_ILINE);
             read(v_ILINE, v_ADD_TERM1);
             read(v_ILINE, v_SPACE);           -- read in the space character
             read(v_ILINE, v_ADD_TERM2);
        
             -- Pass the variable to a signal to allow the ripple-carry to use it
             y <= v_ADD_TERM1;
             
              
          
           end loop;
        
           file_close(file_VECTORS);
            
           wait;
         end process



The file looks like this, just with a lot more lines (around 2000).
Code:
110100010010 
011100011001 
010000000110 
000001111010 
001010100101 
100010101010 
111111001010 
110011111001 
111101011010 
011010100101 
111111000010 
010110001001 
111101111000 
101110001111 
111100110001 
101010010111

The y signal only appears to have the last line of my Input.txt file. Here I attach a quick waveform screen just for clarity. As you can see the input (y) is supposed to update but it is stuck on the 101010010111 value, which is exactly the last one in the file.

RQo7kgk.png


Im sure I'm missing something thats very easy to spot but Im kind of rusty on vhdl...
 

In the testbench, you will need to add a wait statement. Without a wait, it will just read through the entire file and take the last one and assign it to Y, as you have found. You probably want to do something like this:


Code VHDL - [expand]
1
2
3
4
5
6
7
8
9
10
while not endfile(file_VECTORS) loop
  readline(file_VECTORS, v_ILINE);
  read(v_ILINE, v_ADD_TERM1);
  read(v_ILINE, v_SPACE);           -- read in the space character
  read(v_ILINE, v_ADD_TERM2);
        
  -- Pass the variable to a signal to allow the ripple-carry to use it
  y <= v_ADD_TERM1;
  wait until rising_edge(clk_out1);          
end loop;

 

First try what #5 - TrickyDicky recommends.

Secondly, when dealing with reading of files you may want to inspect the different types of libraries available to you. Some will enable the reading & writing of binary, others will allow hex, dec etc.

Overall it looks like you're logic is sound
 

At one time I had to do a lot of this, and we found the best
way was to use external scripts (I started with sed -e, then
a CAD lady turned it into cleaner perl scripts for ut) to add
veriloga header, massage vectors (we had timestamp and
value, not just value - you need to assign that somehow)
and veriloga footer, stuff that to underneath a "testVectors"
symbol/veriloga pair as its verilog.va view, and badda-bing,
a pattern generator for schematic based mixed signal.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top