Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > VHDL and signed numbers

Reply
Thread Tools

VHDL and signed numbers

 
 
salman sheikh
Guest
Posts: n/a
 
      12-17-2004
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
 
Reply With Quote
 
 
 
 
Alan Fitch
Guest
Posts: n/a
 
      12-20-2004
"salman sheikh" <(E-Mail Removed)> wrote in message
news:cpvh5j$qo$(E-Mail Removed)...
> 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:
http://www.velocityreviews.com/forums/(E-Mail Removed)
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.

 
Reply With Quote
 
 
 
 
John LeVieux
Guest
Posts: n/a
 
      12-20-2004
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" <(E-Mail Removed)> wrote in message
> news:cpvh5j$qo$(E-Mail Removed)...
> > 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:
> (E-Mail Removed)
> 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.


 
Reply With Quote
 
John LeVieux
Guest
Posts: n/a
 
      12-20-2004
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" <(E-Mail Removed)> wrote in message
> news:cpvh5j$qo$(E-Mail Removed)...
> > 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:
> (E-Mail Removed)
> 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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert a signed binary number into a signed one ? Rob1bureau VHDL 1 02-27-2010 12:13 AM
fixed point representation and signed numbers blackpadme VHDL 4 09-07-2008 03:03 PM
signed(12 downto 0) to signed (8 downto 0) kyrpa83 VHDL 1 10-17-2007 06:58 PM
VHDL-2002 vs VHDL-93 vs VHDL-87? afd VHDL 1 03-23-2007 09:33 AM
Representing signed numbers in VHDL Kingsley Oteng VHDL 0 05-04-2004 02:00 AM



Advertisments