【问题标题】:VHDL "Non-shared variable declaration not allowed here"VHDL“此处不允许非共享变量声明”
【发布时间】:2020-06-17 06:29:54
【问题描述】:

我有这段代码可以计算 2 个数字的模

library IEEE;

use ieee.numeric_bit.all;

entity resto is
    port (clock , reset : in bit ;
        inicio : in bit ;
        fim : out bit ;
        dividendo , divisor : in bit_vector (15 downto 0) ;
        resto : out bit_vector (15 downto 0)
    ) ;
    end resto;

architecture processo of resto is
    variable    dividendovar : integer range 0 to  15;
    begin

    process(clock, reset) is
    begin
        if reset = '1' then
            fim <= '0';
            resto <= "0000000000000000";
        elsif clock'event and clock = '1' and inicio = '1' then
            dividendovar <= to_integer(unsigned(dividendo));
                if (divisor = "0000000000000000") then
                    -- report "zero"; 
                    resto <= dividendo;
                    fim <= '1';
                elsif (dividendovar = to_integer(unsigned(divisor))) then
                    -- report "menor"; 
                    -- report "dividendoaux vale "& integer'image(to_integer(unsigned(dividendoaux))) ; 
                    resto <= "0000000000000000";
                    fim <= '1';
                elsif (to_integer(unsigned(dividendo)) < to_integer(unsigned(divisor))) then
                    resto <= dividendo;
                    fim <= '1';
                else -- comeca a subtrair
                    while (dividendovar > to_integer(unsigned(divisor))) loop
                        dividendovar := dividendovar - to_integer(unsigned(divisor));
                    end loop ;
                    resto <= bit_vector(to_unsigned(dividendovar, resto'length));
                    fim <= '1';
                end if;
            end if;
            end process;
end architecture;

但是就行了

variable    dividendovar : integer range 0 to  15;

我收到此错误“此处不允许使用非共享变量声明”

我做错了什么或错过了什么的任何线索?

提前致谢!

【问题讨论】:

  • 整个错误消息包括指向保留字variable 的行号和字符计数。非共享变量声明只能作为子程序参数声明、子程序声明项或进程声明项出现。您的 original question 将信号 dividendo_n 声明为块声明项。仅仅更改名称并将其声明为 variable 类是不够的。
  • 您是否打算让 divendovar 只有 4 位(范围 0 到 15)?我猜它是 16 位。
  • 另一个想法,你的 while 循环可能是不可合成的。您是否考虑过使用 for 循环并可能迭代不超过 N 次,其中 N 是除数中的位数?

标签: vhdl hdl ghdl


【解决方案1】:

变量应在process 内声明,因此范围有限。

library IEEE;

use ieee.numeric_bit.all;

entity resto is
    port (clock , reset : in bit ;
        inicio : in bit ;
        fim : out bit ;
        dividendo , divisor : in bit_vector (15 downto 0) ;
        resto : out bit_vector (15 downto 0)
    ) ;
    end resto;

architecture processo of resto is
    begin

    process(clock, reset) is
    variable    dividendovar : integer range 0 to  15;
    begin
        if reset = '1' then
            fim <= '0';
            resto <= "0000000000000000";
        elsif clock'event and clock = '1' and inicio = '1' then
            dividendovar <= to_integer(unsigned(dividendo));
                if (divisor = "0000000000000000") then
                    -- report "zero"; 
                    resto <= dividendo;
                    fim <= '1';
                elsif (dividendovar = to_integer(unsigned(divisor))) then
                    -- report "menor"; 
                    -- report "dividendoaux vale "& integer'image(to_integer(unsigned(dividendoaux))) ; 
                    resto <= "0000000000000000";
                    fim <= '1';
                elsif (to_integer(unsigned(dividendo)) < to_integer(unsigned(divisor))) then
                    resto <= dividendo;
                    fim <= '1';
                else -- comeca a subtrair
                    while (dividendovar > to_integer(unsigned(divisor))) loop
                        dividendovar := dividendovar - to_integer(unsigned(divisor));
                    end loop ;
                    resto <= bit_vector(to_unsigned(dividendovar, resto'length));
                    fim <= '1';
                end if;
            end if;
            end process;
end architecture;

如 cmets 中所述,全局共享变量在 VHDL2002 标准之前可用。如果仍然需要,我认为现在应该保护它们。但到目前为止,我遇到了一个需要变量的用例。

无论如何,在我的所有设计中,只要有可能,我都会更喜欢signals 而不是variables

【讨论】:

  • 像这样的共享变量只允许在 VHDL 1993 中使用。从 VHDL 2002 开始,共享变量必须是受保护的类型(目前在我知道的任何工具中都不能合成)。
  • OP是新手。最好更新示例以显示进程中声明的变量。就像@Tricky 所说,普通类型的共享变量已被 VHDL-2000(已被 VHDL-2002 取代)弃用和删除。
  • 因此,请从您的解决方案中删除共享变量。
  • 同意,但代码仍可合成,只是不合规...
  • @po.pe WRT 你“更喜欢信号而不是变量”,这个问题说明了哪里需要变量,如果你必须在没有时间过去的情况下迭代一个对象,那么你需要一个立即更新的对象 -因此,一个变量。 while 循环不太可能是可合成的,并且该算法使用的减法可能比必要的要多。
猜你喜欢
  • 1970-01-01
  • 2015-09-22
  • 2016-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-02-20
相关资源
最近更新 更多