reading hex file-URGENTTT !!

Joined
May 5, 2011
Messages
1
Reaction score
0
Hey, Im not familiar with vhdl code and need an immediate help.
i need to build a test bench that reads a combined victor of two bits and hex numbers, here's an example:
reading the victor: 0 0 F0A...3C 0BB...D1 FFF...0F AA0...A0
that is:

|Reset (single bit)
|
| --- |EN (single bit)
| --- |
| --- | - |Ms(128 hex digits)
| --- | - | ------------ |Hs(64 hex digits)
| --- | - | ------------ | ------------ |Ss(32 hex digits)
| --- | - | ------------ | ------------ | ----------- |Ts (16 hex digits)
0 - 0 - F0A...3C - 0BB...D1 - FFF...0F - AA0...A0

i heard about library textio but still don't know hoe to use its functions and what parameters
I will really appreciate if some one can write me a relevant code or help me with that, this is urgent for my project in the university
(sorry about my bad english level)
THANKS IN ADVANCE
 
Joined
May 6, 2011
Messages
4
Reaction score
0
Sorry, I don't have time to write code custom to your project cuz I'm struggling through my own code atm, but I have some stuff that can help you...



library IEEE;
library std;
use std.textio.all;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;

entity filereader_tb is
generic(inleft : string := "left25.hex";
inright : string := "right25.hex";
outfile : string := "output.hex");
end filereader_tb;

architecture behavioral of filereader_tb is
begin
P1 : process
variable fstatus : file_open_status := status_error;
variable l : line;
variable r : line;
file in_lft : text;
file in_rgt : text;
file out_fd : text;
variable sample : string(8 downto 1);

begin
file_open(fstatus,in_lft,inleft,read_mode);
if(fstatus /= open_ok)then
assert false;
report "Your left input can go to hell"
severity failure;
end if;

file_open(fstatus,in_rgt,inright,read_mode);
if(fstatus /= open_ok)then
assert false;
report "Your right input can go to hell"
severity failure;
end if;

file_open(fstatus,out_fd,outfile,write_mode);
if(fstatus /= open_ok)then
assert false;
report "Your output can go to hell"
severity failure;
end if;

while(not endfile(in_lft)) loop
wait for 5 ns;
readline(in_lft,l);
read(l,sample(8 downto 5));
readline(in_rgt,r);
read(r,sample(4 downto 1));
report "Value Read from file"
severity note;
write(l,sample);
writeline(output,l);
write(l,sample);
writeline(out_fd,l);
end loop;
report "Left and Right channels concatenated together, and outputted"
severity note;
file_close(out_fd);
wait;
end process P1;
end behavioral;
 

Attachments

  • filereader_tb.txt
    1.5 KB · Views: 268
  • left25.txt
    125 bytes · Views: 252
  • right25.txt
    125 bytes · Views: 234
  • output.txt
    250 bytes · Views: 226
Last edited:
Joined
May 6, 2011
Messages
4
Reaction score
0
jeez, of course the tabbed formatting gets all screwed up

not sure why my most recent comment disappeared, but change the file extension on the test bench to .vhd, and the others to .hex. this code reads in a 16-bit hex number from each right and left files (represents right and left audio), combines them using a string, and spits them out into output.hex.

note that each read/write takes 5ns, so set your clock and execution time according.
 
Last edited:
Joined
May 6, 2011
Messages
4
Reaction score
0
okay. i had to upload everything as text files because it doesn't all .vhd files. so, after you download the files, change filereader_tb to .vhd extension, and change the other three files to .hex extension.

what this code does is open up two seperate text files containing 16-bit hex values, combines them into 1 string (32 bits), and spits it out into output.hex. note that each read/write in my test bench requires 5ns, so make sure you run it for the appropriate amount of time.

http://www.cs.sfu.ca/~ggbaker/reference/std_logic/

is a website with good reference for textio and other vhdl in general
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,815
Latest member
treekmostly22

Latest Threads

Top