Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
13 years ago

VHDL getting Array elements with std_logic_vector

Hello,

I'm having some trouble synthesizing my code, I'm running out of logic cells on my DE2 Altera board.

I want to use the values from 4 std_logic_vectors(7 downto 0) to retrieve the elements of an array, CollisionReg which consists of 119 std_logic_vectors(159 downto 0). I'm doing this by converting the std_logic_vectors to integer using to_integer( unsigned( some std_logic_vector ). If I remove the integer conversions, I can compile fine. I've also tried storing the conversion into some integer variable of a fixed range 0 to 160, but it doesn't help. Is there a reason why integer conversion is taking so many logic cells? Is there a better way for me to do this?

My code creates a matrix equal to the screen resolution and detects if a coordinate on the screen has been travelled before. Any help would be appreciated, thanks!

entity CoordinateMatrix is
port(
        XHead: in std_logic_vector(7 downto 0);
        YHead: in std_logic_vector(7 downto 0);
        XTail: in std_logic_vector(7 downto 0);
        YTail: in std_logic_vector(7 downto 0);
        LoadCM: in std_logic;
        initCM: in std_logic;
        CLK: in std_logic;
        didCollide: out std_logic);
end;
architecture behavioural of CoordinateMatrix is
    type CMArray is array(119 downto 0) of std_logic_vector(159 downto 0);
    signal CollisionReg: CMArray;
    
begin
collisionMatrix: process(CLK) 
begin
    if(rising_edge(clk)) then
        if(LoadCM = '1') then
            if(initCM = '1') then        
                -------********* PROBLEM HERE
                didCollide <= CollisionReg(to_integer( unsigned( XHead)))(to_integer( unsigned( YHead))); --return old value    
                CollisionReg(to_integer( unsigned( XHead)))(to_integer( unsigned( YHead))) <= '1'; --update to already been here
                CollisionReg(to_integer( unsigned( XTail)))(to_integer( unsigned( YTail))) <= '0'; --remove last pixel of snake
                --------------------------------
            else
                for i in 119 downto 0 loop
                    for y in 159 downto 0 loop
                        if(i = 0 OR i = 119 OR y = 0 or y = 159) then --border always occupied
                            CollisionReg(i)(y) <= '1';
                        else
                            CollisionReg(i)(y) <= '0';
                        end if;
                    end loop;
                end loop;    
                
            end if;
        end if;
    end if;
end process;

20 Replies