VHDL and signed numbers

S

salman sheikh

Guest
Is there any way I can read in a file of negative and positive integers
into my VHDL testbench and convert them to hex values? Or does anybody
have a program to convert them?

Salman
 
"salman sheikh" <sheikh@pop500.gsfc.nasa.gov> wrote in message
news:cpvh5j$qo$1@skates.gsfc.nasa.gov...
Is there any way I can read in a file of negative and positive
integers
into my VHDL testbench and convert them to hex values? Or does
anybody
have a program to convert them?

Salman
You can read in integers using textio, and just reading into
an integer.

e.g.

use STD.TEXTIO.all;

....

process
variable L : LINE;
variable I : INTEGER;
variable OK : BOOLEAN;
file F : TEXT;
status : FILE_OPEN_STATUS;
begin
file_open(status, F, READ_MODE, "vectors.txt");

assert status OPEN_OK report "file open failure - Doh!";

while not ENDFILE(F) loop
READLINE(F, L);
assert L'LENGTH!=0 report "that's a short line!";
READ(L, I, OK);
assert OK report "file read error - Doh!";
report "I read the value " & INTEGER'IMAGE(I);

-- convert to hex here...
wait for 10 ns; -- or whatever
end;

wait;
end process;

Unfortunately converting to hex is not that easy.
Probably the most straightforward way is to write the values
to a line in the correct format, and then read them back.
There are procedures HREAD and HWRITE in IEEE.STD_LOGIC_TEXTIO
which you can use.

However I would first ask why you want hex and why you are starting
with integers? Can you actually put hex in the file instead?

regards
Alan

--
Alan Fitch
Consultant

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

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24
1AW, UK
Tel: +44 (0)1425 471223 mail:
alan.fitch@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.
 
An Excel spreadsheet can be used to convert integers into hex values.
Create one cell as an integer (I'll refer to the location as
"Integer_Cell_ID"). Define the cell next to it using the function
formula: =DEC2HEX("Integer_Cell_ID",3).

Note that the "3" in the formula will give a 3 digit hex value
(000-FFF).

John

Alan Fitch wrote:
"salman sheikh" <sheikh@pop500.gsfc.nasa.gov> wrote in message
news:cpvh5j$qo$1@skates.gsfc.nasa.gov...
Is there any way I can read in a file of negative and positive
integers
into my VHDL testbench and convert them to hex values? Or does
anybody
have a program to convert them?

Salman

You can read in integers using textio, and just reading into
an integer.

e.g.

use STD.TEXTIO.all;

...

process
variable L : LINE;
variable I : INTEGER;
variable OK : BOOLEAN;
file F : TEXT;
status : FILE_OPEN_STATUS;
begin
file_open(status, F, READ_MODE, "vectors.txt");

assert status OPEN_OK report "file open failure - Doh!";

while not ENDFILE(F) loop
READLINE(F, L);
assert L'LENGTH!=0 report "that's a short line!";
READ(L, I, OK);
assert OK report "file read error - Doh!";
report "I read the value " & INTEGER'IMAGE(I);

-- convert to hex here...
wait for 10 ns; -- or whatever
end;

wait;
end process;

Unfortunately converting to hex is not that easy.
Probably the most straightforward way is to write the values
to a line in the correct format, and then read them back.
There are procedures HREAD and HWRITE in IEEE.STD_LOGIC_TEXTIO
which you can use.

However I would first ask why you want hex and why you are starting
with integers? Can you actually put hex in the file instead?

regards
Alan

--
Alan Fitch
Consultant

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

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24
1AW, UK
Tel: +44 (0)1425 471223 mail:
alan.fitch@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.
 
An Excel spreadsheet can be used to convert integers into hex values.
Create one cell as an integer (I'll refer to the location as
"Integer_Cell_ID"). Define the cell next to it using the function
formula: =DEC2HEX("Integer_Cell_ID",3).

Note that the "3" in the formula will give a 3 digit hex value
(000-FFF).

John

Alan Fitch wrote:
"salman sheikh" <sheikh@pop500.gsfc.nasa.gov> wrote in message
news:cpvh5j$qo$1@skates.gsfc.nasa.gov...
Is there any way I can read in a file of negative and positive
integers
into my VHDL testbench and convert them to hex values? Or does
anybody
have a program to convert them?

Salman

You can read in integers using textio, and just reading into
an integer.

e.g.

use STD.TEXTIO.all;

...

process
variable L : LINE;
variable I : INTEGER;
variable OK : BOOLEAN;
file F : TEXT;
status : FILE_OPEN_STATUS;
begin
file_open(status, F, READ_MODE, "vectors.txt");

assert status OPEN_OK report "file open failure - Doh!";

while not ENDFILE(F) loop
READLINE(F, L);
assert L'LENGTH!=0 report "that's a short line!";
READ(L, I, OK);
assert OK report "file read error - Doh!";
report "I read the value " & INTEGER'IMAGE(I);

-- convert to hex here...
wait for 10 ns; -- or whatever
end;

wait;
end process;

Unfortunately converting to hex is not that easy.
Probably the most straightforward way is to write the values
to a line in the correct format, and then read them back.
There are procedures HREAD and HWRITE in IEEE.STD_LOGIC_TEXTIO
which you can use.

However I would first ask why you want hex and why you are starting
with integers? Can you actually put hex in the file instead?

regards
Alan

--
Alan Fitch
Consultant

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

Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, Hampshire, BH24
1AW, UK
Tel: +44 (0)1425 471223 mail:
alan.fitch@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