library ieee;
use ieee.std_logic_1164.all;
-- it is basically nand based sbar Rbar latch
entity sr_latch is
port (S,R:in std_logic;Q,Qbar : out std_logic);
end entity sr_latch;
architecture exm1 of sr_latch is
begin
prc:process (R,S)
begin
case std_logic_vector(R,S) is
when "00"=>
Q<='1';
Qbar<='1';
when "01"=>
Q<= '1';
Qbar<='0';
when "10"=>
Q<='0';
Qbar<='1';
when others=>
null;
end case;
end process prc;
end architecture exm1;
these are the errors:
** Error: C:/Modeltech_pe_edu_10.1a/examples/sr latch.vhd(14): Type conversion (to STD_LOGIC_VECTOR) can not have aggregate operand.
** Error: C:/Modeltech_pe_edu_10.1a/examples/sr latch.vhd(30): VHDL Compiler exiting
Your use of 'std_logic_vector(R,S) is that of a function that receives two input parameters. But 'std_logic_vector' is a type, therefore 'std_logic_vector(...)' would be a type conversion which makes your usage invalid.
What you want to do is basically concatenate R and S together to create a std_logic_vector. If you were to do this...
case R & S is
you would find that the expression 'R & S' has two interpretations and is therefore ambiguous so the compiler would complain. So what you need to do here is explicitly tell the compiler the type that is intended like this...
case std_logic_vector'(R & S) is
Note the tick mark after the 'std_logic_vector'. That is called a type qualifier and is used in cases like this where you need to have a specific type, but what you have has more than one interpretation.
Another example would be...
"10"...is this a std_logic_vector, a std_ulogic_vector, a bit_vector or a string? Can't tell, so if the compiler complains about an ambiguous type you would again use the tick mark
string'("10") -- example, here to indicate that "10" is meant to be interpreted as a string
That's because case expressions must be static and functions potentially are not. The way to fix the warning is to come up with a local variable that is the concatenation of the two bits as shown in the code below. Note that now, because the result of the concatenation is being assigned to a std_logic_vector variable, the result of 'R & S' is no longer ambiguous so you technically don't need to do the type qualifier tick mark. Either of the two assignments to 'RS' will work, pick which one you prefer.
Code VHDL - [expand]
1
2
3
4
5
6
prc:process(R,S)variable RS:std_logic_vector(1downto0);begin
RS :=std_logic_vector'(R & S);-- This will work
RS := R & S;-- And so will this, because now the compiler knows that the left hand side is a std_logic_vector so the result is not ambiguouscase RS is