EmbDev.net

Forum: FPGA, VHDL & Verilog Reading a text file


von sam b. (Company: tcs) (sameh)


Rate this post
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?!

von tux (Guest)


Rate this post
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'
...

von lehmi (Guest)


Rate this post
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/qhdl/8_TxtIO.pdf

von sam b. (Company: tcs) (sameh)


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

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.