character to std_logic_vector


P

Pedro Claro

Greetings,

I recently tried to open some files for reading and I managed to read
characters and then putting them in hexadecimal format. ( I used HREAD
form ieee.std_textio ). My question is the following: is there anyway
for reading characters ( from 0-255 in ascii ) and then converting them
do a std_logic_vector or an integer.
For example if I have a "K" on the file the output would be "4B" since
its the hexadecimal code of the character "K".

Thanks in advance,

Pedro Claro
 
Ad

Advertisements

F

Francisco Camarero

This works for me:

...
use ieee.std_logic_arith.all;
...
MyStdLogicVector <= CONV_STD_LOGIC_VECTOR(character'pos(MyChar),8);
...

HTH

Francisco Camarero
 
J

Jonathan Bromley

Francisco Camarero said:
This works for me:
MyStdLogicVector <= CONV_STD_LOGIC_VECTOR(character'pos(MyChar),8);

Fine for simulation. It doesn't work correctly in most synthesis tools,
sadly.
--

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, Hampshire, BH24 1AW, UK
Tel: +44 (0)1425 471223 mail: (e-mail address 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.
 
F

Francisco Camarero

Jonathan said:
Fine for simulation. It doesn't work correctly in most synthesis tools,
sadly.


I know.

I could assume from Pedro's message that,
if he was opening some files for reading,
he was not trying to synthesize that code.

Fran.
 
Ad

Advertisements

F

Francisco Camarero

Amontec said:
For synthesis, you have to write a big mux (using case) including all
conversion (has a rom description).

I wrote this conversion table before.

Excuse me if I don't understand the issue here.

Why would someone want to synthesize a 'character to std_logic_vector' function?

File handling is not synthesizable, and I don't think any synthesis could can
handle character types, can they?

Fran.
 
Joined
Oct 21, 2009
Messages
1
Reaction score
0
Use of character to std_logic_vector conversion does make sense for synthesis

Hi,

I also use character to std_logic_vector conversion, by means of a charToByte(charIn) function:
Code:
to_unsigned(character'pos(charIn),8);

During simulation I use this to insert characters from files, but I also need it for synthesis, since I have an entity that parses serial data that is in ASCII. For readability in my code it is nicer to do a compare like:
Code:
... if serialByteIn = charToByte('{') then ...

Instead of:
Code:
... if serialByteIn = X"7B" then ...

So I do find it useful for synthesis as well.
 
Ad

Advertisements


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

Top