代码之家  ›  专栏  ›  技术社区  ›  addadisplayname

同一类型的两个对象的未定义关系运算符-VHDL

  •  1
  • addadisplayname  · 技术社区  · 8 年前

    我目前有一个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);
    
    1 回复  |  直到 8 年前
        1
  •  2
  •   Paebbels    8 年前

    与其他语言一样,VHDL具有 boolean 类型它是一种整体式,以包装形式提供 std.standard 。因此,此类型始终可见,因为默认情况下会引用此包。

    与其他语言一样 关系型 运算符生成布尔值。无论是积分型 bit 也不是数字逻辑类型 std_logic 是布尔值。布尔值具有值 true false ,其中 0 1 这个 std\U逻辑 类型支持9个值(9值逻辑,包括例如错误值)。

    大多数运算符定义为接受相同类型的右操作数和左操作数,同时再次返回该类型。

    所以您需要在某个时候将表达式转换回 std\U逻辑 因为 candy_vend 应为该类型。

    解决方案1:

    candy_vend <= candy and ('1' when (cash >= cost_candy) else '0');
    

    解决方案2:

    candy_vend <= '1' when ((candy = '1') and (cash >= cost_candy)) else '0';
    

    解决方案3:

    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));