Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronic 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.

Register Log in

to store series of integers into an array using vhdl

Status
Not open for further replies.

chitra ranganath

Member level 2
Joined
May 15, 2011
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,568
i want to know how to store all the values read from the text file which contains integers, into an array
 

TrickyDicky

Advanced Member level 5
Joined
Jun 7, 2010
Messages
7,035
Helped
2,063
Reputation
4,143
Reaction score
2,013
Trophy points
1,393
Activity points
38,686
Ill assume each value is stored on a seperate line:

Code:
type some_array_t is array(integer range <>) of integer;
signal ar : some_array_t(0 to 99); --could be a varaible

--inside a process
file f : text open read_mode is "my_file.txt";
variable inline : line;

for i in ar'range loop
  readline(f, inline);
  read(f, ar(i));
end loop;
Simple as that.
 

chitra ranganath

Member level 2
Joined
May 15, 2011
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,568
ERROR:HDLParsers:3326 - "F:/Xilinx/check/check1.vhd" Line 49. Formal parameter VALUE of procedure read must be associated with an actual value.
ERROR:HDLParsers:3326 - "F:/Xilinx/check/check1.vhd" Line 49. Formal parameter VALUE of procedure read must be associated with an actual value.
ERROR:HDLParsers:164 - "F:/Xilinx/check/check1.vhd" Line 50. parse error, unexpected LOOP, expecting SEMICOLON
i got these errors i actually tried this before bit don`t know what to do

---------- Post added at 17:10 ---------- Previous post was at 16:47 ----------

i`m working on the text file which i`d put as attachment in last few threads
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,652
Helped
14,075
Reputation
28,407
Reaction score
12,742
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,859
Does Xilinx XST support VHDL textio library for synthesized code? Most likely not.

P.S.: If it's for a simulation test bench, the sequence would be
Code:
for i in ar'range loop
  readline(f, inline);
  read(inline, ar(i));
end loop;
 
Last edited:

kalyanasv

Full Member level 4
Joined
May 17, 2011
Messages
192
Helped
48
Reputation
96
Reaction score
46
Trophy points
1,308
Location
NY
Activity points
2,455
I concur on that it will have to be test bench simulation. In case you want to load some values then you better use the memory macros and use a initialization file to load them with a particular value.

The below code is not too different just offers a few more modifiable parameters to play with: for an active low reset, 16bit precision, falling edge input of data.
Just ensure your file has enough data...You can also loop this infinitely you loop back after end of file

Code:

declare before begin
Code:
constant prec:integer:=16;
Code:
 process
    file infile : TEXT; 
    variable fstatus : file_open_status;       
    variable buf_in : line;
    variable temp: integer:=16;
    begin
        data_bus<=(others=>'0');
        wait for 1 ns;
        while reset = '1' loop
            file_open(fstatus, infile, "myfile.txt",READ_MODE);
            while (not endfile (infile)) loop
                  wait until clk'event and clk = '0';
                    readline (infile, buf_in);   
                    read (buf_in ,temp);   
                    data_bus<=CONV_STD_LOGIC_VECTOR(temp,prec);
            end loop;
            file_close (infile);
        end loop;
    end process;
 

chitra ranganath

Member level 2
Joined
May 15, 2011
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,568
sir problem is by using readline and read commands i`m able to read the values in file but everytime the parameter in read ie value is getting overwritten. here for me the parameter value is integer, which can display or store only one value at a time and read cannot output result in array. the content of my text file are all integers. so i think i should write a package of textio which can store the result in an array. i mean type array of integers.

or else i need a function which takes this integer as input n store it in an array whenever read updates it. pls help me in this view.

the reason y i want to store in array is i need to give these integer values as input to another program which converts it into binary value n use them for further use
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,652
Helped
14,075
Reputation
28,407
Reaction score
12,742
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,859
Both methods mentioned in your post can work. As in the recent example posted by kalyanasav, read can directly take an integer argument, also an array element, if you prefer.

Referring to your previous post, you experienced VHDL syntax errors, not particularly related to textio operations, I think. But you didn't show the actual code, so nobody can help with the VHDL errors.
 

chitra ranganath

Member level 2
Joined
May 15, 2011
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,568
process
variable L1:line ;
variable x1:integer ; --- x1 can be of any format
file f_open1 : text open read_mode is "C:\Documents and Settings\Chitra\Desktop\abc1.txt";
begin
while (not endfile(f_open1)) loop

readline(f_open1,L1);
read(L1,x1);
int<=x1 ;
wait until clk='1';
end loop;
end process;
this was the program i was using before.

as per my knowledgeREAD can output only bit, bit_vector,boolean, character, integer, real, string. n all these gets overwritten inside loop. in program above i want to store int into array arr(i). how can i do????

the program above can display only one value
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,652
Helped
14,075
Reputation
28,407
Reaction score
12,742
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,859
Using suitable types, the below code should work. I remove the wait statement from your previous code, because there's no need for a timed statement in this place. It's assumed, that the input file size doesn't exceed the array size, otherwise you have to handle this case. But it should be sufficient to get a simulator exception, if the condition is ignored.
Code:
i:=0;
while (not endfile(f_open1)) loop
readline(f_open1,L1);
read(L1,ar(i));
i:=i+1;
end loop;
 

kalyanasv

Full Member level 4
Joined
May 17, 2011
Messages
192
Helped
48
Reputation
96
Reaction score
46
Trophy points
1,308
Location
NY
Activity points
2,455
i`m able to read the values in file but everytime the parameter in read ie value is getting overwritten.
I assume your using a synchronous circuit. Every clk'event you need to use the data or do something with it or it will get overwritten.

"here for me the parameter value is integer, which can display or store only one value at a time and read cannot output result in array.
the content of my text file are all integers. so i think i should write a package of textio which can store the result in an array. i mean type array of integers."

-->Use FvM Code. I presume your just generating data like a C++ program.

"the reason y i want to store in array is i need to give these integer values as input to another program which converts it into binary value n use them for further use"

The code that I pasted above just that. CONV_STD_LOGIC_VECTOR converts from integer to binary.
 

chitra ranganath

Member level 2
Joined
May 15, 2011
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,568
no sir its not possible to read that way. array s r not supported that way i think i shd write a package which includes this array concept and add it to library textio.
one more thing wen i altered program this way
while (not endfile(f_open1)) loop
readline(f_open1,L1);
read(L1,x1);
int1<=x1 ;
read(L1,x2);
int2<=x2 ;
read(L1,x3);
int3<=x3 ;
read(L1,x4);
int4<=x4 ;
read(L1,x5);
int5<=x5 ;
it read the values but all 1st row elements r not read properly. like till 4th value it was in order later for 5th value instead of 15 it read 8. i don`t know wat is happening
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,652
Helped
14,075
Reputation
28,407
Reaction score
12,742
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,859
its not possible to read that way. array s r not supported that way i think
What's exactly the problem or error in this case? If there's actually a problem to use array elements in read() function with your simulator tool (I don't know why), then you can read the data to an auxilary integer variable.
Code:
read(inline, temp);
ar(i):=temp;
it read the values but all 1st row elements r not read properly.
Like others, I was under the assumption, that the values are supplied in the file line by line. Please clarify.
 

chitra ranganath

Member level 2
Joined
May 15, 2011
Messages
50
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,568
how do i declare this temp as. integer ?? or wat??? sorry bit confused so asking

---------- Post added at 17:04 ---------- Previous post was at 16:58 ----------

i get this error
ERROR:HDLParsers:3312 - "F:/Xilinx/read2/read21.vhd" Line 53. Undefined symbol 'i'.
ERROR:HDLParsers:1209 - "F:/Xilinx/read2/read21.vhd" Line 53. i: Undefined symbol (last report in this block)
i`ve given for loop before read

---------- Post added at 17:07 ---------- Previous post was at 17:04 ----------

readline reads one line in file and READ reads a value in that line

---------- Post added at 17:16 ---------- Previous post was at 17:07 ----------

wat is data_bus here i mean declaration
 

FvM

Super Moderator
Staff member
Joined
Jan 22, 2008
Messages
47,652
Helped
14,075
Reputation
28,407
Reaction score
12,742
Trophy points
1,393
Location
Bochum, Germany
Activity points
276,859
Yes, the variable i has to be defined as integer, it's not a loop variable in my example.
 

Status
Not open for further replies.
Toggle Sidebar

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top