cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
ronnu
Explorer
Explorer
1,182 Views
Registered: ‎10-14-2017

Using predefined attributes

Hello

 

I have a simple question about VHDL. Are the predefined attributes usable only in sequential statements?

 

I had a simple excercise which involved using the attribute T'pos(x) in both sequential and concurrents tatements. In sequential statement it works fine, but I couldn't get it to work in a concurrnet statement. See my example below (from Peter Asheden's book).

 

Exercise with sequential statement which works fine:

 

 

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity charecter_evaluator is
	port (
			char : in character;
			character_class : out integer range 0 to 4
		  );
end charecter_evaluator;

architecture Behavioral of charecter_evaluator is

begin

	char_eval : process (char) is
	
		variable v_char : integer := 0;
		variable v_character_class : integer range 0 to 4 :=0;
		
	begin
		v_char := character'pos(char);
	
		case v_char is
		
			when 65 to 90 | 97 to 122 =>
				v_character_class := 1;
				
			when 48 to 58 =>
				v_character_class := 2;
				
			when 32 to 47 | 59 to 64 | 91 to 96 | 123 to 126 | 128 to character'pos(character'right) =>
				v_character_class := 3;
			
			when 0 to 31 | 127 =>
				v_character_class := 4;
				
			when others =>
				v_character_class := 0;
			
		end case;
		
		character_class <= v_character_class;
		
	end process char_eval;

end Behavioral;

 

Excercise with concurrent statements (select variable assignment) which doesn't give the position number of the character:

 

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity character_evaluator_concurrent is
    Port ( char : in  character;
           character_class : out integer range 0 to 4);
end character_evaluator_concurrent;

architecture Behavioral of character_evaluator_concurrent is

	signal v_char : integer :=0;
	
begin
	
	v_char <= character'pos(char);	
	
	with v_char select
		character_class <= 1 when 65 to 90 | 97 to 122,
								 2 when 48 to 58,
								 3 when 32 to 47 | 59 to 64 | 91 to 96 | 123 to 126 | 128 to character'pos(character'right),
								 4 when 0 to 31 | 127,
								 0 when others;

end Behavioral;

 But when I include the attribute usage into a sequential statement it works fine:

 

 

 

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;

entity character_evaluator_concurrent is
    Port ( char : in  character;
           character_class : out integer range 0 to 4);
end character_evaluator_concurrent;

architecture Behavioral of character_evaluator_concurrent is

	signal v_char : integer :=0;
	
begin
	
	process (char)
	begin
	v_char <= character'pos(char);		-- attributes can only be used in sequential statements??
	end process;
	
	with v_char select
		character_class <= 1 when 65 to 90 | 97 to 122,
								 2 when 48 to 58,
								 3 when 32 to 47 | 59 to 64 | 91 to 96 | 123 to 126 | 128 to character'pos(character'right),
								 4 when 0 to 31 | 127,
								 0 when others;

end Behavioral;

 

To me it seems that attributes can only be used with sequential statements, but maybe I am missing something. Couldn't find the answer from Asheden's book so maybe someone here can answer.

0 Kudos
3 Replies
geoffbarnes
Explorer
Explorer
1,154 Views
Registered: ‎09-07-2011

Is this vivado sim?    Attributes should be ok with concurrent statements, so this could be a bug.

 

In your example, the character'pos(char)  has to evaluate at run-time when the argument changes - just like a concurrent function call.   The tool has to create an equivalent process and make sure the function arguments form the sensitivity list.

 

As far as I know "run-time" concurrent attributes (and functions) are valid in VHDL.  A quick test  in Modelsim seems to work - however it wouldn't hurt to check the standard or Ashenden.

 

Your example used another concurrent attribute , character'pos(character'right).   This worked as expected?   In this case the attribute is evaluated only at elaboration time - so it's effectively a constant.

0 Kudos
ronnu
Explorer
Explorer
1,139 Views
Registered: ‎10-14-2017

No, it's iSIM. 

 

The other attribute works fine, but as you said, it is only evaluated at the beginning, so little bit different.

 

 

0 Kudos
geoffbarnes
Explorer
Explorer
1,130 Views
Registered: ‎09-07-2011

A workaround might be to wrap the attribute call in a function...  assuming isim implemented concurrent function calls correctly.

0 Kudos