2014-06-18 61 views
0

我是VHDL的新手。这是一个划分代码。VHDL-变量的使用

library ieee; 
    USE ieee.std_logic_1164.all; 
    USE ieee.std_logic_unsigned.all; 
    use IEEE.numeric_std.all; 

entity division3 is 
    port(num1, num2 : in std_logic_vector(7 DOWNTO 0); 
    quotient : out std_logic_vector(15 DOWNTO 0)); 
    end division3; 

    architecture arch_div3 of division3 is 
    variable n_times: integer:=1; 
      signal v_TEST_VARIABLE1 : integer; 
      signal v_TEST_VARIABLE2 : integer; 
        begin 
     P3: PROCESS(num1, num2) 
     begin 

     if(num1>num2) then 
     v_TEST_VARIABLE1 <= to_integer(unsigned(num1)) ; 
     v_TEST_VARIABLE2 <= to_integer(unsigned(num2)) ; 
     L1:loop 
     n_times := n_times + 1; 
     exit when (v_TEST_VARIABLE2 - v_TEST_VARIABLE1)>0 
     v_TEST_VARIABLE1 <= v_TEST_VARIABLE1 - v_TEST_VARIABLE2; 
     end loop L1; 


    quotient <= std_logic_vector(to_unsigned(n_times-1,quotient'length)); 

    elsif (num2>num1) then 
     v_TEST_VARIABLE1 <= to_integer(unsigned(num1)) ; 
     v_TEST_VARIABLE2 <= to_integer(unsigned(num2)) ; 
     L2:loop 
     n_times:=n_times+1; 
     exit when (v_TEST_VARIABLE1 - v_TEST_VARIABLE2)>0 
     v_TEST_VARIABLE2 <= v_TEST_VARIABLE2 - v_TEST_VARIABLE1; 

    quotient <= std_logic_vector(to_unsigned(n_times-1,quotient'length)); 


    else 
     quotient <= x"0001"; 
    end if; 

    end PROCESS P3; 
    end arch_div3; 

我在编译时遇到错误。

** Error: C:/Actel/Libero_v9.1/Model/division3.vhd(25): Physical unit hidden by declaration of 'v_test_variable1' at line 13. 
** Error: C:/Actel/Libero_v9.1/Model/division3.vhd(25): near "<=": expecting ';' 
** Error: C:/Actel/Libero_v9.1/Model/division3.vhd(37): Physical unit hidden by declaration of 'v_test_variable2' at line 14. 
** Error: C:/Actel/Libero_v9.1/Model/division3.vhd(37): near "<=": expecting ';' 
** Error: C:/Actel/Libero_v9.1/Model/division3.vhd(42): near "else": expecting "END" 
** Error: C:/Actel/Libero_v9.1/Model/division3.vhd(12): Variable declaration 'n_times' not allowed in this region. 
** Error: C:/Actel/Libero_v9.1/Model/division3.vhd(47): VHDL Compiler exiting 

我对信号和变量的使用很不清楚。我认为这是我搞乱的地方。有人可以帮我吗? 在此先感谢。 对于相同的代码测试平台 -

LIBRARY ieee; 
USE ieee.std_logic_1164.ALL; 
use IEEE.numeric_std.all; 


ENTITY division3_tb IS 
END division3_tb; 

ARCHITECTURE behavior OF division3_tb IS 

    COMPONENT test --'test' is the name of the module needed to be tested. 

    port(num1, num2 : in std_logic_vector(7 DOWNTO 0); 
    quotient : out std_logic_vector(15 DOWNTO 0)); 

    END COMPONENT; 

    signal num1 : std_logic_vector := "00000000"; 
    signal num2 : std_logic_vector := "00000000"; 

    signal quotient : std_logic_vector(15 downto 0); 

    constant clk_period : time := 1 ns; 
BEGIN 

    uut: test PORT MAP (
     num1 => num1, 
      num2 => num2, 
      quotient => quotient 
     );  


    clk_process :process 
    begin 
     num1 <= "00001000"; 
     wait for clk_period/2; --for 0.5 ns signal is '0'. 
     num1 <= "00001110"; 
     wait for clk_period/2; --for next 0.5 ns signal is '1'. 
    end process; 

    stim_proc: process 
    begin   
     wait for 7 ns; 
     num2 <="00000001"; 
     wait for 3 ns; 
     num2 <="00000010"; 
     wait for 17 ns; 
     num2 <= "00000011"; 
     wait for 1 ns; 
     num2 <= "00000110"; 
     wait; 
    end process; 

END; 

它说:在编译

** Error: C:/Actel/Libero_v9.1/Model/division3_tb.vhd(19): Array type for 'num1' is not constrained. 
** Error: C:/Actel/Libero_v9.1/Model/division3_tb.vhd(20): Array type for 'num2' is not constrained. 
** Error: C:/Actel/Libero_v9.1/Model/division3_tb.vhd(55): VHDL Compiler exiting 

。我如何在测试平台中实例化?

回答

1

Error: ...: Physical unit hidden by declaration of ...是由于在exit when ...语句,由此代码是 的解释为端缺乏 ;

exit when ... > 0 v_TEST_VARIABLE1 ... 

所以表达式看起来像一个物理值与单元v_TEST_VARIABLE1, 因此错误信息。

其他一些VHDL相关评论的代码:

  • end loop L2;quotient <=前失踪。因为 ieee.std_logic_unsigned不是VHDL IEEE标准包。

  • 可变n_times应的过程中被声明,而不是在 架构,因为可变使用是本地的过程中,和(共享)体系结构中的声明的变量 通常是用于测试台使用。

  • 过程变量n_times必须在 过程的开始时初始化,以使初始化在每次计算中都生效。 声明中的初始值仅适用于第一次进程运行。

  • 分配到信号v_TEST_VARIABLE1v_TEST_VARIABLE2<= 不会生效直到增量周期后,使新的值是不迭代,它看起来像在代码的意图期间 可用。 将v_TEST_VARIABLE1v_TEST_VARIABLE2更改为过程变量, 和使用:=进行分配。

  • loop .. exit when ... end loop构造并不 合成的,由于退出条件取决于运行时间值,从而 不能在合成时确定用于创建电路。 考虑将算法更改为使用固定数量的循环与for ...

  • 请记住做一个测试台来测试算法的正确性。 这也将允许您优化代码,并通过简单的 更新代码测试。

+0

非常感谢Morten。作品..! :) –