+ Post New Thread
Results 1 to 10 of 10
  1. #1
    Advanced Member level 5
    Points: 12,407, Level: 26

    Join Date
    Aug 2011
    Posts
    2,505
    Helped
    288 / 288
    Points
    12,407
    Level
    26

    Converting an array of std_logic to string

    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 := std_logic_vector_to_string (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"

  2. #2
    Super Moderator
    Points: 61,891, Level: 60
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    12,620
    Helped
    2926 / 2926
    Points
    61,891
    Level
    60

    Re: Converting an array of std_logic to string

    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 by KlausST; 30th March 2018 at 12:19. Reason: Corrected hex value
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



    •   AltAdvertisment

        
       

  3. #3
    Advanced Member level 5
    Points: 36,169, Level: 46
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,614
    Helped
    1927 / 1927
    Points
    36,169
    Level
    46

    Re: Converting an array of std_logic to string

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



    •   AltAdvertisment

        
       

  4. #4
    Super Moderator
    Points: 245,674, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    42,684
    Helped
    13007 / 13007
    Points
    245,674
    Level
    100

    Re: Converting an array of std_logic to string

    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.



    •   AltAdvertisment

        
       

  5. #5
    Advanced Member level 5
    Points: 12,407, Level: 26

    Join Date
    Aug 2011
    Posts
    2,505
    Helped
    288 / 288
    Points
    12,407
    Level
    26

    Re: Converting an array of std_logic to string

    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 ?



  6. #6
    Advanced Member level 5
    Points: 36,169, Level: 46
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,614
    Helped
    1927 / 1927
    Points
    36,169
    Level
    46

    Re: Converting an array of std_logic to string

    use to_hstring instead.


    1 members found this post helpful.

  7. #7
    Advanced Member level 5
    Points: 12,407, Level: 26

    Join Date
    Aug 2011
    Posts
    2,505
    Helped
    288 / 288
    Points
    12,407
    Level
    26

    Re: Converting an array of std_logic to string

    You mean:

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



    •   AltAdvertisment

        
       

  8. #8
    Advanced Member level 5
    Points: 36,169, Level: 46
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,614
    Helped
    1927 / 1927
    Points
    36,169
    Level
    46

    Re: Converting an array of std_logic to string

    constant configuration_sting : string := to_hstring(concatenated_enables );


    1 members found this post helpful.

  9. #9
    Advanced Member level 5
    Points: 12,407, Level: 26

    Join Date
    Aug 2011
    Posts
    2,505
    Helped
    288 / 288
    Points
    12,407
    Level
    26

    Re: Converting an array of std_logic to string

    Sorry, that's what I meant..
    Thanks.

    How well is this function supported with Vivado and Quartus?
    Last edited by shaiko; 30th March 2018 at 20:53.



  10. #10
    Advanced Member level 5
    Points: 36,169, Level: 46
    Achievements:
    7 years registered

    Join Date
    Jun 2010
    Posts
    6,614
    Helped
    1927 / 1927
    Points
    36,169
    Level
    46

    Re: Converting an array of std_logic to string

    No idea. Why dont you tell us?



--[[ ]]--