0
我試圖使用自己創建的函數(這是我第一次嘗試它,所以我可能在那裏做錯了)。VHDL錯誤:在合格表達式中指定的類型必須匹配上下文表達式所暗示的類型
當我嘗試編譯時,出現以下錯誤消息:錯誤(13815):Averageador.vhd(38)處的VHDL限定表達式錯誤:合格表達式中指定的除法類型必須匹配上下文表達式暗示的無符號類型
劃分是我函數的名稱。該函數將任何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;
有什麼建議?謝謝
您不顯示vector32和vector24的聲明。不要在std_logic_arith(包propios)和numeric_std(Averagador)之間交叉。它絕對不是可移植的,都聲明有符號和無符號,每個聲明都是唯一的(使用numeric_std)。向我們展示失敗的功能測試平臺,而不是平滑者。這個想法是能夠重現問題。你似乎混合了有符號和無符號之間的隱喻。在Averageador中有兩個用於num_vectores的驅動程序,所有的作業都應該在同一個過程中。 – user1155120
'如果posicion <=「00000000」,那麼'posicion是無符號的,它不會小於0 – user1155120
對於Averageador inter(函數參數a)長度24,a_int長度32'a_int(a'length + 7 downto 16):= a ;'會在函數分隔中產生一個錯誤。 IEEE Std 1076-2008 10.6.2簡單變量賦值,10.6.2.1段落5和7.右側表達式的子類型不屬於目標子類型,這是一個錯誤。 – user1155120