Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Re: Writing Hex values to file in VHDL?

Reply
Thread Tools

Re: Writing Hex values to file in VHDL?

 
 
Tricky
Guest
Posts: n/a
 
      03-23-2010
On 23 Mar, 01:10, "Pete Fraser" <pfra...@covad.net> 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


why not create an integer to string function:


------------------------------------------------------------------------------------
--Returns the size of the given integer as if it were a string in
the given Radix

------------------------------------------------------------------------------------
function get_int_length(x : integer; radix : positive range 2 to
36 := 10) return integer is
variable temp : integer := abs x;
variable len : integer := 0;
begin

if x = 0 then
len := 1;
end if;

while temp > 0 loop
temp := temp / radix;

len := len + 1;
end loop;

if x < 0 then
len := len + 1; --add extra character for -ve sign
end if;

return len;
end function get_int_length;

----------------------------------------------
--Converts an integer to a string
----------------------------------------------
function int_to_string( x : integer; radix : positive range 2 to
36 := 10) return string is

constant STRING_LEN : integer := get_int_length(x, radix);
variable ret_string : string(1 to STRING_LEN);

--internal variables
variable temp : integer := abs x;
variable temp_rem : integer;
begin

--downto to make sure the string isnt the wrong way
round.
for i in STRING_LEN downto 1 loop

--add -ve sign
if i = 1 and x < 0 then
ret_string(i) := '-';
else
temp_rem := temp rem radix;

case temp_rem is
when 0 => ret_string(i) := '0';
when 1 => ret_string(i) := '1';
when 2 => ret_string(i) := '2';
when 3 => ret_string(i) := '3';
when 4 => ret_string(i) := '4';
when 5 => ret_string(i) := '5';
when 6 => ret_string(i) := '6';
when 7 => ret_string(i) := '7';
when 8 => ret_string(i) := '8';
when 9 => ret_string(i) := '9';
when 10 => ret_string(i) := 'A';
when 11 => ret_string(i) := 'B';
when 12 => ret_string(i) := 'C';
when 13 => ret_string(i) := 'D';
when 14 => ret_string(i) := 'E';
when 15 => ret_string(i) := 'F';
when 16 => ret_string(i) := 'G';
when 17 => ret_string(i) := 'H';
when 18 => ret_string(i) := 'I';
when 19 => ret_string(i) := 'J';
when 20 => ret_string(i) := 'K';
when 21 => ret_string(i) := 'L';
when 22 => ret_string(i) := 'M';
when 23 => ret_string(i) := 'N';
when 24 => ret_string(i) := 'O';
when 25 => ret_string(i) := 'P';
when 26 => ret_string(i) := 'Q';
when 27 => ret_string(i) := 'R';
when 28 => ret_string(i) := 'S';
when 29 => ret_string(i) := 'T';
when 30 => ret_string(i) := 'U';
when 31 => ret_string(i) := 'V';
when 32 => ret_string(i) := 'W';
when 33 => ret_string(i) := 'X';
when 34 => ret_string(i) := 'Y';
when 35 => ret_string(i) := 'Z';

--something has gone very wrong. Kill simulation
when others => report "Illegal option chosen in converting
integer to string" severity failure;
end case;

temp := temp / radix;
end if;
end loop;

return ret_string;

end function int_to_string;
 
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
Re: Writing Hex values to file in VHDL? Magne Munkejord VHDL 1 03-23-2010 12:43 PM
Re: Writing Hex values to file in VHDL? he VHDL 0 03-23-2010 06:39 AM
Re: Writing Hex values to file in VHDL? backhus VHDL 0 03-23-2010 06:37 AM
Hex Color Codes - Hex 6 <=> Hex 3 lucanos@gmail.com HTML 10 08-18-2005 11:21 PM
hex(-5) => Futurewarning: ugh, can't we have a better hex than '-'[:n<0]+hex(abs(n)) ?? Bengt Richter Python 6 08-19-2003 07:33 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57