Re: Writing Hex values to file in VHDL?

Discussion in 'VHDL' started by Magne Munkejord, Mar 23, 2010.

  1. Pete Fraser wrote:
    > I'm trying to dump eight hex values per line
    > into a file, and can't work out how to do it.
    >
    > for index in 0 to 127 loop
    > for sample_sel in 0 to 7 loop
    > sample_val := integer(scale * sin(phase(sample_sel)));
    > write ( sample_line, sample_val, RIGHT, 10);
    > phase(sample_sel) := phase(sample_sel) + phase_inc(sample_sel);
    > end loop;
    > writeline ( ip_dat, sample_line );
    > end loop;
    >
    > does what I want, but with decimal values.
    >
    > If I change to:
    > hwrite ( sample_line, sample_val, RIGHT, 10);
    > or:
    > write ( sample_line, to_hstring(sample_val), RIGHT, 10);
    > it doesn't compile.
    >
    > Any thoughts?
    >
    > Thanks
    >
    > Pete
    >
    >
    >


    From my experiences from modelsim :
    * hwrite works on std_logic_vector but requires the vector to be of
    "even length", that is the length must be a multiple of 4.
    * to_hstring doesn't work for std_logic_vector, you'll have to convert
    it to a bit_vector first.

    In your case I would try using
    hwrite(sample_line, std_logic_vector(to_unsigned(sample_val, <length>)));

    replace <length> with a valid length for your vector: 4,8,12,16... etc.

    (remember to add : use ieee.numeric_std.all;)

    Magne
     
    Magne Munkejord, Mar 23, 2010
    #1
    1. Advertising

  2. Pete Fraser wrote:
    > "Magne Munkejord" <> wrote in message
    > news:hoa188$2opp$...
    >
    >> From my experiences from modelsim :
    >> * hwrite works on std_logic_vector but requires the vector to be of "even
    >> length", that is the length must be a multiple of 4.
    >> * to_hstring doesn't work for std_logic_vector, you'll have to convert it
    >> to a bit_vector first.

    >
    > Probably my problem is that sample_val is an integer.
    > How to I print an integer as hex?
    >
    > Thanks
    >
    > Pete
    >
    >

    It was in the original post, if you missed it:
    std_logic_vector(to_unsigned(sample_val, <length>))

    make sure <length> is multiple of 4 if you intend to use it with hwrite.
     
    Magne Munkejord, Mar 23, 2010
    #2
    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,227
    Neredbojias
    Aug 19, 2005
  2. Bengt Richter
    Replies:
    6
    Views:
    474
    Juha Autero
    Aug 19, 2003
  3. backhus
    Replies:
    0
    Views:
    596
    backhus
    Mar 23, 2010
  4. he
    Replies:
    0
    Views:
    973
  5. Tricky
    Replies:
    0
    Views:
    1,323
    Tricky
    Mar 23, 2010
Loading...

Share This Page