character to std_logic_vector

Discussion in 'VHDL' started by Pedro Claro, Jul 30, 2003.

  1. Pedro Claro

    Pedro Claro Guest

    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
    Pedro Claro, Jul 30, 2003
    #1
    1. Advertising

  2. Ralf Hildebrandt, Jul 30, 2003
    #2
    1. Advertising

  3. This works for me:

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

    HTH

    Francisco Camarero



    Pedro Claro wrote:
    >
    > 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
    Francisco Camarero, Jul 31, 2003
    #3
  4. "Francisco Camarero" <> wrote in message
    news:...
    > 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:
    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.
    Jonathan Bromley, Jul 31, 2003
    #4
  5. Pedro Claro

    Pedro Claro Guest

    I tried that. And it worked. :)
    Thanks for the replies.

    Pedro Claro


    Francisco Camarero <> wrote in message news:<>...
    > This works for me:
    >
    > ..
    > use ieee.std_logic_arith.all;
    > ..
    > MyStdLogicVector <= CONV_STD_LOGIC_VECTOR(character'pos(MyChar),8);
    > ..
    >
    > HTH
    >
    > Francisco Camarero
    >
    >
    >
    > Pedro Claro wrote:
    > >
    > > 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
    Pedro Claro, Aug 1, 2003
    #5
  6. Jonathan Bromley wrote:
    >
    > "Francisco Camarero" <> wrote in message
    > news:...
    > > 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.



    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.



    Pedro Claro wrote:
    >
    > 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 ).
    Francisco Camarero, Aug 4, 2003
    #6
  7. Amontec Team wrote:
    >
    > Pedro Claro wrote:
    > > 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

    > 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.
    Francisco Camarero, Aug 4, 2003
    #7
  8. Pedro Claro

    Ruudiculus

    Joined:
    Oct 21, 2009
    Messages:
    1
    Location:
    Groningen, NL
    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.
    Ruudiculus, Oct 21, 2009
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Velvet
    Replies:
    9
    Views:
    14,814
    Joerg Jooss
    Jan 19, 2006
  2. raavi
    Replies:
    2
    Views:
    909
    raavi
    Mar 2, 2006
  3. cgbusch
    Replies:
    6
    Views:
    7,494
    Mike Brown
    Sep 2, 2003
  4. mimmo
    Replies:
    4
    Views:
    27,955
  5. Thomas Rouam
    Replies:
    6
    Views:
    1,128
Loading...

Share This Page