VDHL error: converted type of object near text or symbol "UNSIGNED" must match std_logic_vector type of target object

VDHL error: converted type of object near text or symbol "UNSIGNED" must match std_logic_vector type of target object

我在尝试编译一些 VHDL 代码时遇到此错误:Error (10409): VHDL Type Conversion error at <line>: converted type of object near text or symbol "UNSIGNED" must match std_logic_vector type of target object

我想我明白这个错误是说 a 被实例化为 std_logic_vector,但是因为我在架构中使用 a 时添加了 unsigned,它们不再是同一类型,因此无法正确转换。但是,当我尝试在 SW 的实体声明或信号声明中添加 unsigned 时,我收到另一个错误消息,指出从未使用“unsigned”。有人可以帮忙吗?

这是我的代码:

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

entity E is 
    port( SW:   in   std_logic_vector(9 downto 0); 
          LEDG: out      std_logic_vector(4 downto 0)   
            ); 
end entity E; 

architecture main of E is 
signal a, b, c: std_logic_vector; 

begin 

a <= unsigned(SW(4 downto 0));
b <= unsigned(SW(9 downto 7));
c <= ('0' & a) + ('0' & b);
 
// non-relevant code

end architecture main; 
            

VHDL 对类型非常严格,它不会将一种类型转换为另一种类型,除非您明确告诉它。

因此,要修复您的错误,您只需将 unsigned 值转换回 std_logic_vector,即:

a <= std_logic_vector(unsigned(SW(4 downto 0)));
b <= std_logic_vector(unsigned(SW(9 downto 7)));

但是,没有任何理由转换为 unsigned 然后立即转换回 std_logic_vector。所以你也可以这样做:

a <= SW(4 downto 0);
b <= SW(9 downto 7);

然而,在这两种情况下您仍然会遇到错误,因为您没有定义 abc 的长度。所以你应该修复这些声明:

signal a : std_logic_vector(4 downto 0);
signal b : std_logic_vector(2 downto 0);
signal c : std_logic_vector(? downto ?); -- Can't infer this from your code.