I currently have a project in VHDL to make a simple vending machine. I have a std_logic
signal to determine if the cash in is greater than or equal to the price of the item. The cost is an unsigned constant and the cash is an unsigned signal, but despite them both being unsigned numbers of equal bit length, it tells me the >=
operator is undefined. I've looked in multiple reference guides, and all I can find is that the two arguments must be the same type (which they are...) so I'm not sure why it's throwing this error
I have included the proper numeric_std
library.
type STATE_TYPE is (RDY, CLCT, VND);
signal state : STATE_TYPE;
signal next_state : STATE_TYPE;
signal cash : unsigned (7 downto 0);
signal cashnew : unsigned (7 downto 0);
signal candy : std_logic;
signal candy_vend : std_logic;
constant cost_candy : unsigned := to_unsigned(60, 8);
signal chips : std_logic;
signal chips_vend : std_logic;
constant cost_chips : unsigned := to_unsigned(50, 8);
begin
candy <= candy1 or candy2 or candy3;
chips <= chip1 or chip2;
candy_vend <= candy and (cash >= cost_candy);
chips_vend <= chips and (cash >= cost_chips);
As in other languages, VHDL has a
boolean
type. It is a integral type and provided in packagestd.standard
. Thus this type is always visible, because this package is referenced by default.Also like in other languages, a relational operator results in a boolean value. Neither the integral type
bit
nor the digital logic typestd_logic
is a boolean. Boolean has valuestrue
andfalse
, where as bit has0
and1
. Thestd_logic
type supports 9 values (9-valued logic, including e.g. error values).Most operators are defined to accept the right and left operands of the same type, while returning that type again.
So you need to convert your expression at some point back to
std_logic
, becausecandy_vend
is expecting that type.Solution 1:
Solution 2:
Solution 3:
Usage: