[英]subtracting std_logic_vector from integer
我從整數中減去STD_LOGIC_VECTOR時遇到問題。
這是我現在擁有的代碼:
entity ROM is
Port ( hcount: in STD_LOGIC_VECTOR(9 downto 0);
vcount: in STD_LOGIC_VECTOR(9 downto 0);
hpos: in integer;
vpos: in integer;
clk25: in STD_LOGIC;
Pixeldata: out std_logic);
end ROM;
architecture Behavioral of ROM is
signal romtemp : std_logic_vector(9 downto 0);
shared variable yas : integer range 0 to 9 := 0;
shared variable xas : integer range 0 to 9 := 0;
Type RomType is array (9 downto 0) of std_logic_vector(9 downto 0);
Constant Rom: RomType :=
( "0001111000", "0111111110", "0111111110", "1111111111", "1111111111"
, "1111111111", "1111111111", "0111111110", "0111111110", "0001111000");
begin
process(clk25)
begin
if(hpos > hcount - 10) and (hpos <= hcount) and (vpos > vcount - 10) and (vpos <= vcount) then
xas := hpos - to_integer(unsigned(hcount));
end if;
end process;
end Behavioral;
問題是下面的代碼行:
xas := hpos - to_integer(unsigned(hcount));
我試圖將減法放在名為xas的整數中。
該行發生以下錯誤:
錯誤:通過多個use子句包含了多個unsigned聲明; 沒有一個可以直接看到
錯誤:<unsigned(hcount)>的類型為unsigned。
錯誤:正式<arg>沒有實際值或默認值。
錯誤:整數類型不是數組類型,無法建立索引
錯誤:找到運算符“ =”的“ 0”定義,無法確定“-”的確切過載匹配定義
有人可以幫助我解決此錯誤嗎? (我是VHDL的初學者)
您尚未在文件頂部包含use
子句,但是此錯誤表示的是,從use
子句中,它找到了unsigned
兩個不同定義。 因此,該工具忽略了這兩個定義,從而生成錯誤並迫使您處理問題。
最可能的解釋是您有:
use ieee.numeric_std.all;
use ieee.std_logic_arith.all;
std_logic_arith
是非標准的,您應該僅使用numeric_std
可用的類型和函數來實現設計。 刪除std_logic_arith
行。
通常,如果某物是數字,請使用數字類型來表示它。 例如,您的hcount
和vcount
輸入顯然是計數器,可以使用unsigned
類型。 如果首先使用更合適的類型,則可以避免進行笨拙的類型轉換,例如:
xas := hpos - to_integer(unsigned(hcount));
會成為
xas := hpos - hcount;
代碼中的其他問題:
clk25
,但該過程實際上不是同步過程,因此所有使用的輸入信號都應在列表中(或者您可以使用reserved all
關鍵字生成一個自動列表,即process(all)
)。 process(clk)
begin
if (rising_edge(clk)) then
-- Do things
end if;
end process;
xas
是一個共享變量,這意味着您可能也在其他進程中對其進行分配。 這可能無法正常工作。 在完全了解共享變量的工作方式以及何時使用它們之前,您應該完全避免共享變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.