file io prob in vhdl

Guest
The piece of code goes like this:
process
variable m,n: integer:=0;
type integer_file is file of integer;
file intfile: integer_file open read_mode is "integers.txt";
begin
while not(endfile(intfile)) loop
read(intfile,m);
read(intfile,n);
----
----

end process;

The values in the file integers.txt are like 3,4,10,12 etc seperated by
space. But when it reads the values m & n, its getting it all wrong,
the values being very high like 805965104,221252109,168636426,... etc.
I am bugged as to what is happening.

-neo
 
Can you send me your code as I think there is no problem reading a text
file.
 
thanks jonathan, yeah I can do that with textio but was trying other
approaches.


-Neo
 
zingafriend@yahoo.com wrote:

The values in the file integers.txt are like 3,4,10,12 etc seperated by
space. But when it reads the values m & n, its getting it all wrong,
the values being very high like 805965104,221252109,168636426,... etc.
I am bugged as to what is happening.
Write the file before you read it.
Here is an example with characters.
http://groups-beta.google.com/groups?q=vhdl+char_range

-- Mike Treseler
 
yep that works, but not preferable as you pointed out.
thanks guys.

-neo
 
On 25 Jan 2005 03:27:52 -0800, zingafriend@yahoo.com wrote:

The piece of code goes like this:
[...]

The values in the file integers.txt are like 3,4,10,12 etc seperated by
space. But when it reads the values m & n, its getting it all wrong,
the values being very high like 805965104,221252109,168636426,... etc.

I am bugged as to what is happening.
In hex, these three numbers are X"300A0D30", X"0D300A0D", X"0A0D300A".

Given a table of ASCII values, it shouldn't be difficult to figure out
what's going on.

Try reading this file using std.textio.

- Brian
 
"Jonathan Bromley" <jonathan.bromley@doulos.com> wrote in message
news:5lpev0969vmhmvl1vsdhmnmtd9trvdphoi@4ax.com...
You can usually do a fairly good job of reading/writing
binary files from VHDL by treating them as "file of character",
but once again it's not guaranteed to be portable.
I've had good results reading and writing binary files using a file type
of character. It works the same on both an IBM PC (byte little-endian
architecture) and an IBM RS6000 (byte big-endian architecture). Reading
or writing one character at a time gets around the little/big-endian
confusion of integer representation.

Charles Bailey
 
On 25 Jan 2005 03:27:52 -0800, zingafriend@yahoo.com wrote:

The piece of code goes like this:
process
variable m,n: integer:=0;
type integer_file is file of integer;
file intfile: integer_file open read_mode is "integers.txt";
begin
while not(endfile(intfile)) loop
read(intfile,m);
read(intfile,n);
[..]
The values in the file integers.txt are like 3,4,10,12 etc seperated by
space. But when it reads the values m & n, its getting it all wrong,
the values being very high like 805965104,221252109,168636426,... etc.
To read from a "file of integer" using read(), you must have written
the file using VHDL write()...

unless you know the internal binary representation of integer
that's used by your simulator vendor...

so don't do that. Use std.textio instead. Plenty of examples
around about how to do that.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:jonathan.bromley@doulos.com
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 
On 25 Jan 2005 21:46:48 -0800, zingafriend@yahoo.com wrote:

thanks jonathan, yeah I can do that with textio but
was trying other approaches.
OK.

I *guess* that most simulators will treat "file of integer"
as a straight binary file, with each integer packed as 4
bytes. Try *writing* a "file of integer" from VHDL, with
a few known integer values, and look at the resulting file
with a text editor that understands how to do binary/hex
byte-by-byte editing, or with "od" in *nix.

The biggest problems (i.e. differences among simulators and
operating systems) are likely to relate to endianness
and end-of-file detection.

You can usually do a fairly good job of reading/writing
binary files from VHDL by treating them as "file of character",
but once again it's not guaranteed to be portable. Plain-text
is the right way to do it in VHDL. It's easy to write external
scripts or C programs to convert between VHDL-friendly text and
software-friendly binary representations.
--
Jonathan Bromley, Consultant

DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail:jonathan.bromley@doulos.com
Fax: +44 (0)1425 471573 Web: http://www.doulos.com

The contents of this message may contain personal views which
are not the views of Doulos Ltd., unless specifically stated.
 

Welcome to EDABoard.com

Sponsor

Back
Top