Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Converting an array of std_logic to string

Status
Not open for further replies.

shaiko

Advanced Member level 5
Joined
Aug 20, 2011
Messages
2,644
Helped
303
Reputation
608
Reaction score
297
Trophy points
1,363
Activity points
18,302
Hello,

My entity's "generic" section has a set of 5 enabling configurations (that are concatenated into a vector ) - as follows:
Code:
entity some_entity is

generic 
(
   enable_0 : std_logic ;
   enable_1 : std_logic ;
   enable_2 : std_logic ;
   enable_3 : std_logic ;
   enable_4 : std_logic ;
)

port 
(
...
) ;

end entity some_entity ;

architecture rtl_some_entity is

constant concatenated_enables : std_logic_vector ( 4 downto 0 ) := enable_4 & enable_3 & enable_2 & enable_1 & enable_0 ;

constant configuration_sting : string := [COLOR="#FF0000"]std_logic_vector_to_string [/COLOR](concatenated_enables ) ;

begin
...
end architecture rtl_some_entity ;

The function marked in red shall return the Hex value of "concatenated_enables" in a string format.
For example:

if
enable_4 = '1' ;
enable_3 = '1' ;
enable_2 = '1' ;
enable_1 = '0' ;
enable_0 = '0' ;
so
configuration_sting = "FC"

if
enable_4 = '0' ;
enable_3 = '1' ;
enable_2 = '1' ;
enable_1 = '0' ;
enable_0 = '0' ;
configuration_sting = "0C"
 

Hj,

if
enable_4 = '1' ;
enable_3 = '1' ;
enable_2 = '1' ;
enable_1 = '0' ;
enable_0 = '0' ;
so
configuration_sting = "FC"
Why "FC"? I'd expect "1C"
(Corrected: "8C" --> "1C")

I'd divide it into 4 bit nibbles.
The values are 0...15
For values of 0...9 you could add 0x30 to get values 0x30 ... 0x39 which are the ASCII values if "0" ..."9".
For the other values add (0x41 - 0x0A) = 0x37 to get values 0x41 .... 0x46 which are "A" ... "F"

Klaus
 
Last edited:

Cant even be bothered to try yourself now?
vhdl 2008 has to_string and to_hstring functions for all types, including std_logic_vector.
 

Do you have any specific question about writing the std_logic_vector_to_string() function?

I presume you mean "1C" instead of "FC".

- - - Updated - - -

TrickyDicky is right. to_hstring() does exactly what you want. You may want to copy the code if it isn't provided by your compiler/simulator.
 

Cant even be bothered to try yourself now?
vhdl 2008 has to_string and to_hstring functions for all types, including std_logic_vector.

I tried using the 2008 "to_string" function before posting...
But as far as I understand (correct me if I'm wrong) - it wouldn't convert the "concatenated_enables" std_logic_vector to an ASCII hex string...it would leave it in a binary format.

I guess this can be solved by writing a custom function that converts 4 binary nibbles into characters that represent the hex value - but I want to avoid this.
My question is - how ?
 

You mean:

Code:
hex_string := to_string ( enable_4 & enable_3 & enable_2 & enable_1 & enable_0) ;

?
 

constant configuration_sting : string := to_hstring(concatenated_enables );
 
  • Like
Reactions: shaiko

    shaiko

    Points: 2
    Helpful Answer Positive Rating
Sorry, that's what I meant..
Thanks.

How well is this function supported with Vivado and Quartus?
 
Last edited:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top