I am a newbie in VHDL. This is a code for division.
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;
I am facing errors on compilation.
** 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
I am not very clear with the use of signal and variable very well. i think that is where I am messing up. Can someone help me out? Thanks in advance. The testbench for the same code -
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;
It says that:
** 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
on compilation. how do i instantiate in the test bench?