表达式有16个元素;预计 17 个元素

问题描述 投票:0回答:1

Vivado 不断通知我有关

address <= address & std_logic_vector(to_unsigned(1, 1))
处两个值不匹配的问题,但我已经检查过,不应该出现相差一错误。
我不会尝试在任何其他代码行中访问
address

library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;

...

architecture behavioral of p1 is

    ...

    signal heading_bit                  :   std_logic_vector(1 downto 0);
    signal heading_counter              :   integer range 0 to 2 := 0;
    signal address                      :   std_logic_vector(15 downto 0);
    signal address_counter              :   integer range 0 to 16 := 0;

begin process(i_clk, i_rst)

       ...
                
                    if(i_start = '1' and heading_counter < 2) then
                    
                        if(i_w = '1') then
                            heading_bit <= heading_bit(heading_counter) & std_logic_vector(to_unsigned(1, 1));
                        else
                            heading_bit <= heading_bit(heading_counter) & std_logic_vector(to_unsigned(0, 1));
                        end if;

                        heading_counter <= heading_counter + 1;
                        
                    elsif(i_start = '1' and heading_counter >= 2) then
                    
                        if(i_w = '1' and address_counter < 16) then
                            address <= address & std_logic_vector(to_unsigned(1, 1));
                        elsif(i_w = '0' and address_counter < 16) then
                            address <= address & std_logic_vector(to_unsigned(0, 1));
                        end if;
                        
                        ...
            
    end process; 

我已经查找了之前关于同一问题的查询,然后再次检查了我的代码,但我似乎找不到问题的根源。

vhdl fpga vivado
1个回答
0
投票

分配的左侧 (LHS) 和右侧 (RHS) 需要具有相同的位数。

您问为什么这对

heading_bit
有效。作业是:

        heading_bit <= heading_bit(heading_counter) & std_logic_vector(to_unsigned(1, 1)); -- or (0, 1)

通过对

heading_bit
的一位进行索引并将其与一位
std_logic_vector
连接起来,RHS 的宽度为 2 位。 LHS 也是
heading_bit
,也是 2 位宽。从语法上来说,一切都很好。

但是对于这个作业你会得到一个错误:

        address <= address & std_logic_vector(to_unsigned(1, 1)); -- or (0, 1)

当然,因为您将一位附加到右侧的

address
,然后将其分配给左侧的
address
。宽度不匹配。

假设您想要左移

address
中的位并移入右侧的一位
std_logic_vector
。那么解决办法就是索引
address
的适当部分:

        address <= address(15 downto 1) & std_logic_vector(to_unsigned(1, 1)); -- or (0, 1)
© www.soinside.com 2019 - 2024. All rights reserved.