+ Post New Thread
Results 1 to 8 of 8

11th May 2009, 19:51 #1
 Join Date
 Nov 2005
 Posts
 503
 Helped
 2 / 2
 Points
 5,456
 Level
 17
How to convert std_logic_vector to hexadecimal
How to convert std_logic_vector to hexadecimal ?
Thanks.

Advertisement

12th May 2009, 00:26 #2
 Join Date
 Jan 2003
 Location
 Cairo/Egypt
 Posts
 1,238
 Helped
 56 / 56
 Points
 10,814
 Level
 24
How to convert std_logic_vector to hexadecimal
Hexadecimal is not a type like std_logic_vector. Hexadecimal is a representation. So, you can always represent the std_logic_vector signal in terms of Hex format.
What do you want to do exactly ?

Advertisement

12th May 2009, 16:13 #3
 Join Date
 Nov 2005
 Posts
 503
 Helped
 2 / 2
 Points
 5,456
 Level
 17
Re: How to convert std_logic_vector to hexadecimal
I want to convert std_logic_vector to character.
Should I convert std_logic_vector to hexadecimal first?
the following is my code:
Code:procedure hex2chr( variable hex : in std_logic_vector( 3 downto 0); variable char : out character) is begin case hex is when "0000" => char:='0'; when "0001" => char:='1'; when "0010" => char:='2'; when "0011" => char:='3'; when "0100" => char:='4'; when "0101" => char:='5'; when "0110" => char:='6'; when "0111" => char:='7'; when "1000" => char:='8'; when "1001" => char:='9'; when "1010" => char:='a'; when "1011" => char:='b'; when "1100" => char:='c'; when "1101" => char:='d'; when "1110" => char:='e'; when "1111" => char:='f'; when others => ASSERT (false) REPORT "no hex character read" SEVERITY failure; end case; end hex2chr;

Advertisement

12th May 2009, 16:37 #4
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 45,443
 Helped
 13827 / 13827
 Points
 260,240
 Level
 100
How to convert std_logic_vector to hexadecimal
character is a VHDL standard type, but it has no particular purpose in synthesis, it's mainly used in text_io for simulation purposes. So what do you want to do with the char output of the procedure?

12th May 2009, 20:01 #5
 Join Date
 Nov 2005
 Posts
 503
 Helped
 2 / 2
 Points
 5,456
 Level
 17
Re: How to convert std_logic_vector to hexadecimal
I am doing a closed loop simulation.
I want to record the feedback std_logic_vector.
Thanks.

12th May 2009, 20:56 #6
 Join Date
 Jan 2008
 Location
 Bochum, Germany
 Posts
 45,443
 Helped
 13827 / 13827
 Points
 260,240
 Level
 100
How to convert std_logic_vector to hexadecimal
So you want to perform hexadecimal textio output. This should work.
1 members found this post helpful.

Advertisement

13th May 2009, 16:29 #7
 Join Date
 Nov 2005
 Posts
 503
 Helped
 2 / 2
 Points
 5,456
 Level
 17
Re: How to convert std_logic_vector to hexadecimal
are you sure?
looks like it has erros, keep showing "ASSERT (false) REPORT "no hex character read" SEVERITY failure;"
why?

14th May 2009, 03:25 #8
 Join Date
 Jul 2004
 Posts
 892
 Helped
 177 / 177
 Points
 9,432
 Level
 23
Re: How to convert std_logic_vector to hexadecimal
Check out this one!
Code:function to_hstring (value : STD_ULOGIC_VECTOR) return STRING is constant ne : INTEGER := (value'length+3)/4; variable pad : STD_ULOGIC_VECTOR(0 to (ne*4  value'length)  1); variable ivalue : STD_ULOGIC_VECTOR(0 to ne*4  1); variable result : STRING(1 to ne); variable quad : STD_ULOGIC_VECTOR(0 to 3); begin if value'length < 1 then return NUS; else if value (value'left) = 'Z' then pad := (others => 'Z'); else pad := (others => '0'); end if; ivalue := pad & value; for i in 0 to ne1 loop quad := To_X01Z(ivalue(4*i to 4*i+3)); case quad is when x"0" => result(i+1) := '0'; when x"1" => result(i+1) := '1'; when x"2" => result(i+1) := '2'; when x"3" => result(i+1) := '3'; when x"4" => result(i+1) := '4'; when x"5" => result(i+1) := '5'; when x"6" => result(i+1) := '6'; when x"7" => result(i+1) := '7'; when x"8" => result(i+1) := '8'; when x"9" => result(i+1) := '9'; when x"A" => result(i+1) := 'A'; when x"B" => result(i+1) := 'B'; when x"C" => result(i+1) := 'C'; when x"D" => result(i+1) := 'D'; when x"E" => result(i+1) := 'E'; when x"F" => result(i+1) := 'F'; when "ZZZZ" => result(i+1) := 'Z'; when others => result(i+1) := 'X'; end case; end loop; return result; end if; end function to_hstring;
Hope this helps!
+ Post New Thread
Please login