相同类型的两个对象的未定义关系运算符 - VHDL
Undefined relational operator for two objects of the same type - VHDL
我目前有一个 VHDL 项目来制作一个简单的自动售货机。我有一个 std_logic
信号来确定现金是否大于或等于物品的价格。成本是一个无符号常量,现金是一个无符号信号,但尽管它们都是等位长度的无符号数,它告诉我 >=
运算符未定义。我查看了多个参考指南,我只能发现这两个参数必须是同一类型(它们是......)所以我不确定为什么会抛出这个错误
我已经包含了正确的 numeric_std
库。
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);
与其他语言一样,VHDL 有一个 boolean
类型。它是一个整体类型,在std.standard
包中提供。因此这个类型总是可见的,因为这个包在默认情况下被引用。
也像在其他语言中一样,关系 运算符产生布尔值。整数类型 bit
和数字逻辑类型 std_logic
都不是布尔值。布尔值具有 true
和 false
,而位具有 0
和 1
。 std_logic
类型支持 9 个值(9 值逻辑,包括例如错误值)。
大多数运算符被定义为接受相同类型的左右操作数,同时再次返回该类型。
因此您需要在某个时候将表达式转换回 std_logic
,因为 candy_vend
需要该类型。
解决方案一:
candy_vend <= candy and ('1' when (cash >= cost_candy) else '0');
方案二:
candy_vend <= '1' when ((candy = '1') and (cash >= cost_candy)) else '0';
方案三:
function to_sl(value : boolean) return std_logic is
begin
if value then
return '1';
else
return '0';
end if;
end function;
用法:
candy_vend <= candy and to_sl(cash >= cost_candy);
candy_vend <= to_sl((candy = '1') and (cash >= cost_candy));
我目前有一个 VHDL 项目来制作一个简单的自动售货机。我有一个 std_logic
信号来确定现金是否大于或等于物品的价格。成本是一个无符号常量,现金是一个无符号信号,但尽管它们都是等位长度的无符号数,它告诉我 >=
运算符未定义。我查看了多个参考指南,我只能发现这两个参数必须是同一类型(它们是......)所以我不确定为什么会抛出这个错误
我已经包含了正确的 numeric_std
库。
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);
与其他语言一样,VHDL 有一个 boolean
类型。它是一个整体类型,在std.standard
包中提供。因此这个类型总是可见的,因为这个包在默认情况下被引用。
也像在其他语言中一样,关系 运算符产生布尔值。整数类型 bit
和数字逻辑类型 std_logic
都不是布尔值。布尔值具有 true
和 false
,而位具有 0
和 1
。 std_logic
类型支持 9 个值(9 值逻辑,包括例如错误值)。
大多数运算符被定义为接受相同类型的左右操作数,同时再次返回该类型。
因此您需要在某个时候将表达式转换回 std_logic
,因为 candy_vend
需要该类型。
解决方案一:
candy_vend <= candy and ('1' when (cash >= cost_candy) else '0');
方案二:
candy_vend <= '1' when ((candy = '1') and (cash >= cost_candy)) else '0';
方案三:
function to_sl(value : boolean) return std_logic is
begin
if value then
return '1';
else
return '0';
end if;
end function;
用法:
candy_vend <= candy and to_sl(cash >= cost_candy);
candy_vend <= to_sl((candy = '1') and (cash >= cost_candy));