Reading hex data from file

Discussion in 'VHDL' started by magik, Jun 23, 2005.

  1. magik

    magik Guest

    Hi!

    I have got text file with data wrote in this manner:

    .........
    01 04 A2 FC 10 D0 E4 C2
    0A C3 FF 9A D2 E1 00 00
    .........


    each 2-sign value is a hex value of std_logic_vector(7 downto 0), and it
    should be connected with data vector in my project like this:

    data(7 downto 0) <= (2-sign value from text file);


    how can I do that?
    have you got a similiar vhdl example witch I can use?

    Thanks for any help

    Paul
    magik, Jun 23, 2005
    #1
    1. Advertising

  2. magik

    info_ Guest

    Hi,

    Simple;
    OTOMH (not tested, so you have a little work left ;-)

    use std.textio.all;
    use ieee.std_logic_textio.all; -- Synopsys :)

    readline(L, File_handle);
    for i in 1 to 8 loop
    hread (L, vData); -- variable vData : std_logic_vector(Data'range);
    Data <= vData;
    -- wait some etc...
    end loop;


    and do this while you've not reached the end of file.
    VoilĂ 


    magik wrote:
    > Hi!
    >
    > I have got text file with data wrote in this manner:
    >
    > ........
    > 01 04 A2 FC 10 D0 E4 C2
    > 0A C3 FF 9A D2 E1 00 00
    > ........
    >
    >
    > each 2-sign value is a hex value of std_logic_vector(7 downto 0), and it
    > should be connected with data vector in my project like this:
    >
    > data(7 downto 0) <= (2-sign value from text file);
    >
    >
    > how can I do that?
    > have you got a similiar vhdl example witch I can use?
    >
    > Thanks for any help
    >
    > Paul
    >
    >
    info_, Jun 23, 2005
    #2
    1. Advertising

  3. magik

    info_ Guest

    info_ wrote:

    > Hi,
    >
    > Simple;
    > OTOMH (not tested, so you have a little work left ;-)
    >
    > use std.textio.all;
    > use ieee.std_logic_textio.all; -- Synopsys :)
    >
    > readline(L, File_handle);

    Ooops !
    readline (File_handle,L); -- indeed


    Bert Cuzeau
    info_, Jun 23, 2005
    #3
  4. magik

    magik Guest

    Thanx Bert!! :)

    What if some of my lines are not exactly with 8 2-hex ??

    ok, in real the file looks like this:

    ---------------------------------
    COMAND_A
    01 04 A2 FC 10 D0 E4 C2
    0A C3 FF 9A D2 E1 00 00
    (empty line or comment)
    COMAND_B
    01 04 A2
    ---------------------------------

    I will start from checking first line witch should cover string and I will
    decide what to do. Of course at this moment I will use read(L, string_var);
    where string_var is STRING type. After this I will read data... how can I
    assume that there is no more data in present line or the line is empty or
    has no-hex (0-9, A-F) objects??


    Paul
    magik, Jun 23, 2005
    #4
  5. magik

    info_ Guest

    magik wrote:

    > Thanx Bert!! :)
    >
    > What if some of my lines are not exactly with 8 2-hex ??
    >
    > ok, in real the file looks like this:
    >
    > ---------------------------------
    > COMAND_A
    > 01 04 A2 FC 10 D0 E4 C2
    > 0A C3 FF 9A D2 E1 00 00
    > (empty line or comment)
    > COMAND_B
    > 01 04 A2
    > ---------------------------------
    >
    > I will start from checking first line witch should cover string and I will
    > decide what to do. Of course at this moment I will use read(L, string_var);
    > where string_var is STRING type. After this I will read data... how can I
    > assume that there is no more data in present line or the line is empty or
    > has no-hex (0-9, A-F) objects??
    >
    >
    > Paul
    >
    >


    Can test L(1), but your example is quite unfriendly as "C" is a
    valid hex character :-(
    Why not use a semicolumn for non-data (& comments) lines ?

    Testing L'length is recommended. Less than 2 is hopeless
    for hreading a byte. (it gets easily rid of blank lines too)

    Could use the "safe" version of read & test the boolean to see if the
    extraction went okay or not.

    Writing a robust data parser in VHDL isn't terribly exciting,
    but it isn't very difficult either.
    Once you'll have yours, keep it : it's very useful and resusable code.

    Bert Cuzeau
    info_, Jun 23, 2005
    #5
  6. magik

    magik Guest

    Thanx again !! :)

    OK my test model is working, but how can I finish testing ?
    For now, when the end of the input text file is reached my AHDL is crashing
    down...


    Paul
    magik, Jun 24, 2005
    #6
  7. magik

    Bert Cuzeau Guest

    magik wrote:
    > Thanx again !! :)
    >
    > OK my test model is working, but how can I finish testing ?
    > For now, when the end of the input text file is reached my AHDL is crashing
    > down...

    AHDL ? ! you mean VHDL ?

    while not ENDFILE(F) loop
    -- process the file
    end loop;
    should do the trick.


    Bert Cuzeau
    Bert Cuzeau, Jun 25, 2005
    #7
    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. Replies:
    10
    Views:
    6,136
    Neredbojias
    Aug 19, 2005
  2. Bengt Richter
    Replies:
    6
    Views:
    449
    Juha Autero
    Aug 19, 2003
  3. jack
    Replies:
    4
    Views:
    575
  4. tim

    hex string to hex value

    tim, Nov 22, 2005, in forum: Python
    Replies:
    8
    Views:
    18,795
  5. tim
    Replies:
    2
    Views:
    1,539
    Dennis Lee Bieber
    Nov 23, 2005
Loading...

Share This Page