VHDL错误:限定表达式中指定的类型必须与上下文为表达式暗示的类型匹配

VHDL错误:限定表达式中指定的类型必须与上下文为表达式暗示的类型匹配,vhdl,quartus,Vhdl,Quartus,我正在尝试使用自己创建的函数(这是我第一次尝试,所以我可能在那里做了一些错误的事情) 当我尝试编译时,收到以下错误消息:error(13815):VHDL限定表达式Averageador处出错。vhd(38):限定表达式中指定的除法类型必须与上下文为表达式暗示的无符号类型匹配 Divide是我函数的名称。此函数用于将任何16位无符号值除以未知无符号值,并将结果作为固定点32位无符号值给出,其中16位位于点的每一侧。代码如下: library IEEE; use IEEE.std_logic_11

我正在尝试使用自己创建的函数(这是我第一次尝试,所以我可能在那里做了一些错误的事情)

当我尝试编译时,收到以下错误消息:error(13815):VHDL限定表达式Averageador处出错。vhd(38):限定表达式中指定的除法类型必须与上下文为表达式暗示的无符号类型匹配

Divide是我函数的名称。此函数用于将任何16位无符号值除以未知无符号值,并将结果作为固定点32位无符号值给出,其中16位位于点的每一侧。代码如下:

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;

package propios is

 --function declaration.
function divide (a : UNSIGNED; b: UNSIGNED) return UNSIGNED;
end propios;   --end of package.

package body propios is  --start of package body
--definition of function
function  divide (a : UNSIGNED; b: UNSIGNED) return UNSIGNED is
variable a_int : unsigned(a'length+7 downto 0):= (others => '0');
variable b_int : unsigned(b'length-1 downto 0):=b;
variable r : unsigned(b'length downto 0):= (others => '0');
variable q : unsigned(31 downto 0):= (others => '0');
begin
a_int(a'length+7 downto 16):=a;
for i in a'length+7 downto 0 loop
    r(b'length downto 1):=r(b'length-1 downto 0);
    r(0) := a_int(i);
    if (r>=q) then
        r:=r-b_int;
        q(i):='1';
    end if;
end loop;
return q;
end divide;
--end function
end propios;  --end of the package body
我返回q,它是一个32位的无符号

这是我使用函数并提示错误消息的代码:

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

library work;
use work.propios.all;

ENTITY test IS --Con alimentación de datos posición a posición, no vector de golpe.

END test;
Architecture simple of test is
signal a:unsigned(15 downto 0);
signal b:unsigned(13 downto 0);
signal c: unsigned(31 downto 0);
begin


process 
begin
a<="1100100110100111";
b<="00000000000010";
c<= divide(a,b);


end process;


end simple;
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.numeric_std.all;
图书馆工作;
使用work.propios.all;
实体测试是——营养不良是一种疾病,没有病媒。
结束试验;
测试的架构非常简单
信号a:无符号(15到0);
信号b:无符号(13到0);
信号c:无符号(31到0);
开始
过程
开始
a问题是由(用户1155120说的)在包上使用包标准逻辑和在测试上使用数字标准造成的。因此,即使两者都称为unsigned,它们也不兼容

两个代码都包含其他错误,这些错误也已更正,但与第一个错误无关

这是一个软件包,该软件包具有一个函数,用于将2个无符号数字除以昏迷后的16位:

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;

package propios is

 --function declaration.
function divide (a : UNSIGNED; b: UNSIGNED) return UNSIGNED;
end propios;   --end of package.

package body propios is  --start of package body
--definition of function
function  divide (a : UNSIGNED; b: UNSIGNED) return UNSIGNED is
variable a_int : unsigned(a'length+15 downto 0):= (others => '0');--Length is 16 bit longer than a
variable b_int : unsigned(b'length-1 downto 0):=b;
variable r : unsigned(b'length downto 0):= (others => '0');
variable q : unsigned(a'length+15 downto 0):= (others => '0');--Same length as a_int
variable i: natural;

begin
a_int(a'length+15 downto 16):=a;--the MSBits are "a" and the rest will be 0's
for i in a'length+15 downto 0 loop--division using a modified version of integer division (unsigned) with remainder as seen in:
--https://en.wikipedia.org/wiki/Division_algorithm
    r(b'length downto 1):=r(b'length-1 downto 0);
    r(0) := a_int(i);
    if (r>=b_int) then
        r:=r-b_int;
        q(i):='1';
    end if;
end loop;
return q;
end divide;
--end function
end propios;  --end of the package body
这是一个检查其功能的简单测试:

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

library work;
use work.propios.all;

ENTITY test IS --Con alimentación de datos posición a posición, no vector de golpe.

END test;
Architecture simple of test is
signal a:unsigned(23 downto 0);
signal b:unsigned(13 downto 0);
signal c: unsigned(39 downto 0);
begin


process 
begin
a<="000000001100100110100111";
b<="00000000010010";
wait for 200ps;
c<= divide (a , b);

wait;   
end process;


end simple;
ieee库;
使用ieee.std_logic_1164.all;
使用ieee.numeric_std.all;
图书馆工作;
使用work.propios.all;
实体测试是——营养不良是一种疾病,没有病媒。
结束试验;
测试的架构非常简单
信号a:无符号(23至0);
信号b:无符号(13到0);
信号c:无符号(39到0);
开始
过程
开始

A不显示vector32和vector24的声明。不要在标准逻辑和数字标准之间交叉。它绝对不是可移植的,无论是声明有符号还是无符号,每个声明都是唯一的(使用numeric_std)。向我们展示失败的功能测试台,而不是Averageador。这个想法是为了能够重现这个问题。你似乎在有符号和无符号之间混合隐喻。在Averageador中,num_向量有两个驱动程序,所有赋值都应该在同一个过程中。
如果Averageador inter(函数参数a)长度为24,a_int长度为32
a_int(a'length+7到16):=a将在函数divide中生成错误。IEEE标准1076-2008 10.6.2简单变量分配,10.6.2.1第5和7段。右侧表达式的子类型不属于目标子类型,这是一个错误。如果您查看报告的错误,可能是由于在一个位置使用std_logic_arith,在另一个位置使用numeric_std,两者都声明为unsigned,等等。感谢您的快速响应!!正如你所说,这是因为一边使用标准逻辑运算,另一边使用数字标准运算。也谢谢你指出其他问题,我会记住的。为了清楚起见,如果将来有人看到这篇文章,我也会发布测试代码。再次感谢!