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.

Parse a VHDL string array

Status
Not open for further replies.

rzsmith

Newbie
Joined
Apr 29, 2021
Messages
5
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
27
I would like to parse separate characters inside a VHDL string array. The actual code is quite large and 99.99% of it has nothing to do with this question.

I am getting an error: Error: Indexed name is not a 'std_logic_vector'

Sample code:

component TestRun is
port ( StrAr : in string(1 to 3) :="ABC" );
...
signal Char_Two : std_logic_vector( 7 downto 0 );

What is the correct syntax to:

Char_Two <= StrAr(1); -- ie Char_Two = 'B'
 

Hi,

Any editor that can work with "regular expressions" should do.

What OS are you using?

Klaus
 

The string type in VHDL is defined as:

Code VHDL - [expand]
1
type string is array(positive range <>) of character;



The Character type is an enumerated type containing all 256 ASCII chars.

So a character cannot be assigned to a std_logic_vector, because they are not the same type.
You will need some form of conversion between the two. The way I would do this using the numeric_std package is:


Code VHDL - [expand]
1
Char_Two <= std_logic_vector(to_unsigned(character'pos(StrAr(1)), 8));

 
  • Like
Reactions: jenish

    jenish

    Points: 2
    Helpful Answer Positive Rating
Hi,

Any editor that can work with "regular expressions" should do.

What OS are you using?

Klaus
I am using both Windows and Linux. I am familiar and use regular expressions in Linux commands, but was not aware that RE are available in VHDL.
 

Hi,

I guess I misunderstood what you want to achieve.....

.. but RE do not belong to any "specific language". You may use them an any text based file.
You may use them for German, English, C, python, scripts, batch files ....

Klaus
 


Code VHDL - [expand]
1
2
3
4
5
6
component TestRun is
port ( StrAr : in string(1 to 3) :="ABC" );
...
signal Char_Two : character;
 
Char_Two <= StrAr(2); -- ie Char_Two = 'B'



You don't mean synthesable design, right?
 


Code VHDL - [expand]
1
2
3
4
5
6
component TestRun is
port ( StrAr : in string(1 to 3) :="ABC" );
...
signal Char_Two : character;
 
Char_Two <= StrAr(2); -- ie Char_Two = 'B'



You don't mean synthesable design, right?
 

The string type in VHDL is defined as:

Code VHDL - [expand]
1
type string is array(positive range <>) of character;



The Character type is an enumerated type containing all 256 ASCII chars.

So a character cannot be assigned to a std_logic_vector, because they are not the same type.
You will need some form of conversion between the two. The way I would do this using the numeric_std package is:


Code VHDL - [expand]
1
Char_Two <= std_logic_vector(to_unsigned(character'pos(StrAr(1)), 8));

That solved the problem. Thank-you for your post, it really helped me out.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top