【发布时间】:2017-03-27 19:23:58
【问题描述】:
我正在尝试使用自己创建的函数(这是我第一次尝试,所以我可能在那里做错了什么)。
当我尝试编译时,我收到以下错误消息:错误 (13815):Averageador.vhd(38) 处的 VHDL 限定表达式错误:限定表达式中指定的除法类型必须匹配上下文表达式隐含的无符号类型
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
我返回一个 32 位无符号的 q。
这是我在其中使用函数并提示错误信息的代码:
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;
有什么建议吗?谢谢
【问题讨论】:
-
您没有显示 vector32 和 vector24 的声明。不要在 std_logic_arith (package propios) 和 numeric_std (Averagador) 之间交叉。它绝对不是可移植的,声明有符号和无符号,每个声明都是唯一的(使用 numeric_std)。向我们展示失败的函数测试台,而不是 Averageador。这个想法是能够重现问题。您似乎在有符号和无符号之间混合了隐喻。在 Averageador 中有两个驱动 num_vectores,所有分配都应该在同一个进程中。
-
if posicion <= "00000000" then位置是无符号的,它永远不会小于 0。 -
对于Averageador inter(函数参数a)长度为24,a_int长度为32
a_int(a'length + 7 downto 16) := a;会产生函数除法错误。 IEEE Std 1076-2008 10.6.2 Simple variable assignments, 10.6.2.1 第 5 和 7 段。右侧表达式的子类型不属于目标子类型,这是一个错误。 -
看VHDL - Qualified Expression must match the type that is implied for the expression by context报错可能是一处使用std_logic_arith,另一处使用numeric_std,均声明unsigned等造成的。
-
感谢您的快速回复!正如您所说,这是因为在一侧使用 std_logic_arith 而在另一侧使用 numeric_std 。也感谢您指出其他问题,我会记住它们。只是为了清楚起见,如果其他人将来看到这篇文章,我也会发布测试代码。再次感谢!