EmbDev.net

Forum: FPGA, VHDL & Verilog Reading a text file


Author: sam boulos (Company: tcs) (sameh)
Posted on:

Rate this post
0 useful
not useful
Hi to all,

I am trying to read a text file has some values in character type as 
follow:
26
30
34
30
20
8
11
11
12
12
but what I am getting wrong values as follow:
50
49
10
51
48
10
51

based in the following code:

library ieee;
USE ieee.std_logic_1164.all;
USE ieee.numeric_bit.ALL;
USE std.textio.all;

Entity feeder Is
port ( start: in std_logic;
pixel_value: out bit_vector(7 downto 0)
);
END feeder;

Architecture Behavior OF feeder Is

TYPE frame_txt IS FILE OF character;
TYPE frame_array IS ARRAY (natural RANGE <>) OF bit_vector(7 DOWNTO 0);


SIGNAL read_frame_array : frame_array(0 to 25343);


begin
read_file: PROCESS (start) IS
FILE file_in : frame_txt OPEN read_mode IS " 
/afs/cad/u/s/m/smb34/vlsi2/frame1.txt"; -- open the frame file for 
reading
VARIABLE char_buffer : character;
BEGIN
IF start'EVENT AND start = '1' THEN
FOR i IN read_frame_array'RANGE LOOP
read(file_in, char_buffer);
read_frame_array(i) <= 
bit_vector(to_unsigned(character'POS(char_buffer), 8));
pixel_value <= read_frame_array(i);
--frame_array_byte(i) <= 
CONV_STD_LOGIC_VECTOR(character'pos(char_buffer), 8);
END LOOP; -- i
file_close(file_in);
END IF;
END PROCESS read_file;


End Behavior;

please, let me know what i have done wrong, so i can read the right 
values out of the file?!

Author: tux (Guest)
Posted on:

Rate this post
1 useful
not useful
that's the ascii code of the character
50 -> '2'
49 -> '1'
10 -> linebreak
51 -> '3'
48 -> '0'
10 -> linebreak
51 -> '3'
...

Author: lehmi (Guest)
Posted on:

Rate this post
1 useful
not useful
the textio package has some functions/procedures reading text files. 
Here are some examples using textio:

http://paws.kettering.edu/~mcdonald/class/ce422/qh...

Author: sam boulos (Company: tcs) (sameh)
Posted on:

Rate this post
0 useful
not useful
thanks so much , my problem solved.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.