【问题标题】:Width mismatch vhdl at constant declaration常量声明处的宽度不匹配 vhdl
【发布时间】:2014-01-25 05:58:16
【问题描述】:

我真的不明白。这是一个简单的常量向量声明。

如果它是一个向量,是否应该允许它具有任何值(在我的情况下为 3)?

错误:

  Width mismatch, location has width 2, value 3

在代码处:

    constant s0: std_logic_vector := "000";

【问题讨论】:

  • 声明constant s0: std_logic_vector := "000";是合法的,导致std_logic_vector的范围是0到2,所以这个错误一定是由于一些未公开的代码。

标签: vhdl


【解决方案1】:

原来问题出在代码的其他地方,我试图用错误宽度的向量进行计算。问题是在常量声明处报错,而不是在出错的地方报错

【讨论】:

    【解决方案2】:

    去做吧:

    constant s0: std_logic_vector(0 to 2) := "000";
    

    constant s0: std_logic_vector(2 downto 0) := "000";
    

    constant s0: std_logic_vector(CONSTANT_X to CONSTANT_X+2) := "000";
    

    您不能声明没有 RANGE(大小)的常量/信号。 Unranged 样式仅在函数中支持,您必须将其分配到具有范围的信号/变量中。

    function cast_v(vector_in: std_logic_vector; OUT_W: integer) return std_logic_vector is
        constant IN_W : integer := vector_in'length;
        constant CAST_W : integer := OUT_W - IN_W;
        variable cast_vector: std_logic_vector(CAST_W-1 downto 0);
        variable vector_out : std_logic_vector(OUT_W-1 downto 0);
      begin
        gen_bits: for i in CAST_W-1 downto 0 loop
          cast_vector(i) := vector_in(IN_W-1);
        end loop gen_bits;
        vector_out := cast_vector & vector_in;
        return vector_out;
      end cast_v;
    

    还有一件事,先生。请仔细阅读您的 VHDL 食谱。

    【讨论】:

    • 可以用初始化器声明一个没有范围的常量,正如 Morten Zilmer 已经在问题下方评论过的那样
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多