从整数中减去 std_logic_vector

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 的整数中。

该行出现以下错误:

Error: Multiple declarations of unsigned included via multiple use clauses; none are made directly visible

Error: Expecting type unsigned for < unsigned(hcount) >.

Error: Formal < arg > has no actual or default value.

Error: Type integer is not an array type and cannot be indexed

Error: found '0' definitions of operator "=", cannot determine exact overload matching definition for "-"

有人可以帮我解决这个错误吗? (我是VHDL初学者)

你没有在文件的顶部包含你的 use 子句,但是这个错误是说从 use 子句中,它找到了 [=16 的两个不同定义=].因此,该工具忽略了这两个定义,生成错误并迫使您处理该问题。

最可能的解释是您有:

use ieee.numeric_std.all;
use ieee.std_logic_arith.all;

std_logic_arith 是非标准的,您应该仅使用 numeric_std 中可用的类型和函数来实现您的设计。删除 std_logic_arith 行。

一般来说,如果是数字,就用数字类型来表示。例如,您的 hcountvcount 输入显然是计数器,可以使用类型 unsigned。如果您一开始就使用更合适的类型,就可以避免看起来笨拙的类型转换,例如:

xas := hpos - to_integer(unsigned(hcount));

会变成

xas := hpos - hcount;

您的代码中的其他问题:

  • 你的进程敏感列表只包含clk25,但进程实际上不是同步进程,所以所有使用的输入信号都应该在列表中(或者你可以使用保留的all 关键字生成自动列表,即 process(all)).
  • 除非是特殊情况,否则最好养成编写同步进程的习惯。这些看起来像这样:

process(clk)
begin
  if (rising_edge(clk)) then
    -- Do things
  end if;
end process;

  • xas 是一个共享变量,这意味着您也可以在其他进程中分配它。这可能不会像您期望的那样工作。您应该完全避免共享变量,直到您完全了解它们的工作原理以及何时适合使用它们。