EmbDev.net

Forum: FPGA, VHDL & Verilog Need help with VHDL reading from file


von Darren S. (Company: STP) (lift)


Rate this post
useful
not useful
Hi guys,requesting some help with my vhdl code,i am writing a Data 
Encryption Standard using VHDL.I have a problem with reading from a 
file.I can write to a file if I entered the inputs manually in my 
testbench but I cant write to a file when I try to read the inputs from 
a file.Below is a portion of my code and the input/output files.Any help 
would be greatly appreciated and thanks for your time!

Input File(.txt)
_________________
785AC3A4BD0FE12D
123456789ABCDEF0
785AC3A4BD0FE12D


Output File(.txt)
_________________
1335 ns FD9CBA5D26331F38
2135 ns 17EA4A8B48C14DA0
2935 ns FD9CBA5D26331F38




Code(data_in<=input,data_out<=output)
____________________________________________
-- data_in <= x"785AC3A4BD0FE12D",
-- x"123456789ABCDEF0" after 1400 ns,
-- x"785AC3A4BD0FE12D" after 2200 ns;
1
process 
2
use std.textio.all;
3
use ieee.numeric_std.all;
4
file inputfile:text open read_mode is "input.txt";
5
6
variable ipa:std_logic_vector(63 downto 0);
7
variable inline:line;
8
9
begin
10
 while not(endfile(inputfile))loop
11
  readline(inputfile,inline);
12
  read(inline,ipa);
13
  data_in<=ipa;
14
  wait for 4000 ns;
15
 end loop;
16
 wait;
17
end process;
18
19
 function_select <= '1';
20
 --'0' after 2100 ns,
21
 --'1' after 4550 ns,
22
 --'0' after 5800 ns;
23
24
25
 tb: PROCESS
26
 BEGIN
27
  key <= x"38A84FF898B90B8F";
28
  wait for 1400 ns;
29
30
31
 end process;
32
33
 process
34
  use std.textio.all;
35
  use ieee.numeric_std.all;
36
  file resultfile:text open write_mode is "result.txt";
37
  variable outline:line;
38
 begin
39
  wait on data_out;
40
  wait for 50 ns;
41
  write(outline,now,right, 2);
42
  hwrite(outline,data_out,right, 40);
43
  writeline(resultfile,outline);
44
 end process;
45
end key;

: Edited by Moderator
von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Darren Seow wrote:
> but I cant write to a file when I try to read the inputs from a file.
Why not? What error message do you get?

von Darren S. (Company: STP) (lift)


Rate this post
useful
not useful
Hi there,sorry for the late reply,issue has been solved.I forgotten to 
add a "h"in front of read.Hence,it wasnt able to read hexadecimal 
inputs.Thanks for your time!

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.