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.

How to read data file by VHDL

Status
Not open for further replies.
how long have you run the simulation for?
and where is your clock generated?
 

i`ve given wait for 10 ns; this is showin me some 25 - 30 values but it stored in integer so now i want to place the values in array so i`m altering it by declaring an array. when it comes to assigning integer value to array how do i alter the program

architecture Behavioral of file2 is
type integer1 is array (integer range 1 to 191500) of integer
begin
process
file test : text open read_mode is "C:\Documents and Settings\Chitra\Desktop\decimal.txt";
--file file test: text is in decimal.txt;
variable buff: line;
variable x:integer range 255 downto 0 ; --- x1 can be of any format

begin

while (not endfile(test))loop
readline (test,buff);
read (buff,x);
int<=x ;
for i in 1 to 191500 loop
integer1(i)<=int;
i++;
wait for 10 ns;
end loop;
end loop;

end process;
end Behavioral;
how to alter this properly?
 

sir i got the output

---------- Post added at 17:10 ---------- Previous post was at 17:08 ----------

but its reading only first value shd i extend the loop

some thing like this @Simulation Waveform Window ?
int=185 and the simulator
stops ............


Here there is a wait statement on clock ...and probably... you might have forgot to give clock stimulus ,
so the process executes once and suspends ...so the first value is loaded and other values are not loaded.
it's the problem with 'clk'....While loop is fine .....

so remedy is ...apply the clock 'clk'
 

now i`m able to read the values in first column but all the values are declared as integers. if i want these values in array i mean from int to some array like int1 whose range is 1 to 191500 then how will i alter this program??
 

i`ve given wait for 10 ns; this is showin me some 25 - 30 values but it stored in integer so now i want to place the values in array so i`m altering it by declaring an array. when it comes to assigning integer value to array how do i alter the program

architecture Behavioral of file2 is
type integer1 is array (integer range 1 to 191500) of integer
begin
process
file test : text open read_mode is "C:\Documents and Settings\Chitra\Desktop\decimal.txt";
--file file test: text is in decimal.txt;
variable buff: line;
variable x:integer range 255 downto 0 ; --- x1 can be of any format

begin

while (not endfile(test))loop
readline (test,buff);
read (buff,x);
int<=x ;
for i in 1 to 191500 loop
integer1(i)<=int;
wait for 10 ns;
end loop;
end loop;

end process;
end Behavioral;
how to alter this properly?

i++ c style coding .....there is no need for i++
when you have ------------
for i in 0 to 1000 loop

....here i takes value 0 to 1000 .....
as the loop works.
no need for any additional i++;

---------- Post added at 23:11 ---------- Previous post was at 23:05 ----------

type integer1 is array (integer range 1 to 191500) of integer;

Now you have to declare an array of type integer1 ....

Example
variable storage:integer1;

now you can do array assignments ...

storage(i):=int
 

sir now i`m able to read the values and assign them to array. but i`m facing one problem in the program below it can read only 1st column so wat remedy can i have pls do reply sir.

entity fil2 is
port(clk:in bit;
int:eek:ut integer:=0);
end fil2;

architecture Behavioral of fil2 is
type num is array(natural range<>) of integer;
signal s:num(0 to 166499);
begin
process(clk)
variable ch:character;
variable inbuff:line;
file test : text open read_mode is "C:\Documents and Settings\Chitra\Desktop\decimal.txt";
variable word: integer;
variable num_word: integer:=0;
begin
while (not endfile (test)) loop
readline (test,inbuff);
read (inbuff,word);
read (inbuff,ch);
s(num_word)<=word;
num_word:=num_word+1;
end loop;
end process;
end behavioral;

---------- Post added at 08:47 ---------- Previous post was at 08:47 ----------

pls do give solution for this problem sir i`m in need of it
 

the read function will read values from the same line. There is another version of the function that will tell you if a read has been done sucessfully. It will ignore whitespace, so there is no need for you to read the whitespace between values. You also dont need a temporary integer to store the read values.

Code:
architecture Behavioral of fil2 is
  type num is array(natural range<>) of integer;
  signal s:num(0 to 166499);
begin
  
  process  --no clock, because you're not using the clock
  
    variable inbuff:line;
    file test : text open read_mode is "C:\Documents and Settings\Chitra\Desktop\decimal.txt";
    
    variable num_word: integer:=0;
    variable good_read  : boolean;
  begin
    while (not endfile (test)) loop
      readline (test,inbuff);
      good_read := true;
      
      while good_read loop
        read (inbuff, s(num_word), good_read);
      
        if good_read then          
          num_word:=num_word+1;
        end if;
      end loop;
      
    end loop;
    
  end process;
  
end behavioral;
 

fine sir if i need to move to next line wat is that i need to do. i tried putting for loop for readline but this didn`t work. i don`t knw wats wrong bcos when
"while not endfile loop" is given it should read all values in text rite???
 

the readline function reads an entire line from a text file (up to the next /r or /n character)
The read function reads values off that line. If you have 100 values on a line you need to call read 100 times before you call readline again.
 

fine sir if i need to move to next line wat is that i need to do. i tried putting for loop for readline but this didn`t work. i don`t knw wats wrong bcos when
"while not endfile loop" is given it should read all values in text rite???

As TrickyDicky said readline stores the entire line .so you have go for

n 'read' ....if there are n integers per line .So i would suggest another method ....IF you can change the format of the input file to few integers per line(manageable) ..everything should work ...simple script in matlab can help you reformat the text so that it suits the VHDL style .


other complex solutions do exist like developing a new package .
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top