[SOLVED] I found this syntax helpful. T'pos(X)

Status
Not open for further replies.

Port Map

Advanced Member level 4
Joined
Aug 24, 2013
Messages
118
Helped
15
Reputation
30
Reaction score
14
Trophy points
1,298
Visit site
Activity points
2,089
sometimes we need to display a state machine's state on LEDs or signals.
the syntax below helps us to display the number of state machine on LEDs.

Syntax: T'pos(X) Returns the position number of X within the type T.

example:
Code:
type tState is (S1,S2,S3);
signal sMainState:tState:=S1;
signal sLeds	:std_logic_vector(2 downto 0);
....
...
sLeds	<=conv_std_logic_vector(tState'pos(sMainState),sLeds'length);
 


Code VHDL - [expand]
1
sLeds   <=conv_std_logic_vector(tState'pos(sMainState), sLeds'length);

And here is how to do it with the standard library numeric_std:

Code VHDL - [expand]
1
sLeds   <= std_logic_vector(to_unsigned(tState'pos(sMainState),sLeds'length));

 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…