Altera_Forum
Honored Contributor
7 years agoHelp with a VHDL code - using an array
Hello!
I want to use an array in order to check if my coordinates are correct, according to certain conditions. The coordinates represent a beginning point of a picture I will print on the screen using VGA and I want to duplicate this picture, I need to check if the coordinates (which I receive from a random numbers generator component) do not overlap. I tried to make an array and fill it according to the conditions, but after running simulations on my VHDL code I noticed that the output does not receive the values from my array, even though I assign them into the output. My code:
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.std_logic_unsigned.all;
use ieee.numeric_std.all;
use ieee.std_logic_arith.all;
entity pigsCoordinate is
port (
clk : in std_logic;
resetN : in std_logic;
limit : in integer;
run : in std_logic;
random : in std_logic_vector(7 downto 0);
coordinate : out integer
);
end pigsCoordinate;
architecture pigsCoordinateArch of pigsCoordinate is
type pigsArray is array (0 to 7) of integer range 0 to limit;
signal pigsArray_signal: pigsArray := (0,0,0,0,0,0,0,0);
signal counter : integer := 0;
signal counterData : integer := 0;
begin
process (clk,resetN)
variable tempLocation: integer := 0;
begin
if (resetN = '0') then
coordinate <= 0;
elsif rising_edge(clk) then
if (run = '1') then
tempLocation := conv_integer(random);
if (counter = 0) then
pigsArray_signal(counter) <= tempLocation;
counter <= counter + 1;
elsif (counter < 8) then
pigsArray_signal(counter) <= tempLocation;
for checkCounter in 0 to 7 loop
exit when ((pigsArray_signal(counter) > pigsArray_signal(checkCounter)) and
(pigsArray_signal(counter) < (pigsArray_signal(checkCounter) + 26) and
(counter /= checkCounter)));
end loop;
counter <= counter + 1;
elsif (counter = 8) and (counterData < 8) then
coordinate <= pigsArray_signal(counterData);
counterData <= counterData + 1;
end if;
end if;
end if;
end process;
end pigsCoordinateArch;
Thank you very much for your help and attention!