Altera_Forum
Honored Contributor
12 years agoMarble line
Hello everyone,
I am trying to make a marble line. I have red marbles and blue marbles and I basically want to fill in order an integer vector with the value 2 for blue marbles, 1 for red marbles and 0 for when there are no marbles. The way I want this to work is that I want to start with an empty line and, every time I press a button called redMarble, a red marble will go to the first empty space of this line and every time I press the blueMarble button, a blue marble will go to the first empty space available of the line. The vector that represent the line is called marbleLine, and I made it in a way that I can change its size if I want. Unfortunately though, I have not been able to get this right. I have gone through it over and over again but I can't find what I am doing wrong or another way to do what I want. The code I have so far is:
library IEEE;
use IEEE.std_logic_1164.all;
Entity Central is
generic (N: integer := 9);
port(
redMarble, blueMarble: in std_logic;
-- outLine is here just for tests
outLine: out std_logic_vector(N downto 0)
);
end Central;
architecture archC of Central is
type Vector is array (N downto 0) of integer range 0 to 2;
signal marbleLine : Vector;
begin
process(redMarble, blueMarble) is
variable alreadyFoundFirstZero: std_logic;
begin
alreadyFoundFirstZero := '0';
if(rising_edge(redMarble)) then
-- Here I will look for the first empty space, or 0, in the marbleLine
for i in 0 to N loop
if(alreadyFoundFirstZero = '0') then
if(marbleLine(i) = 0) then
marbleLine(i) <= 1;
alreadyFoundFirstZero := '1';
end if;
end if;
end loop;
end if;
alreadyFoundFirstZero := '0';
if(rising_edge(blueMarble)) then
for i in 0 to N loop
if(alreadyFoundFirstZero = '0') then
if(marbleLine(i) = 0) then
marbleLine(i) <= 2;
alreadyFoundFirstZero := '1';
end if;
end if;
end loop;
end if;
end process;
-- Testing Output
process(marbleLine) is
begin
for i in 0 to N loop
if (marbleLine(i)= 1) then
outLine(i) <= '1';
end if;
if (marbleLine(i)= 2) then
outLine(i) <= '0';
end if;
end loop;
end process;
end archC;
With this code I am getting multiple erros of the kind: Error (10821): HDL error at Central.vhd(34): can't infer register for "marbleLine[0][0]" because its behavior does not match any supported register model and Error (10820): Netlist error at Central.vhd(34): can't infer register for marbleLine[1][0] because its behavior depends on the edges of multiple distinct clocks Does anyone know how to fix these problems, or even, how to make this possible in a different way? Thank you all in advance, Stomp