Help with variables and 'for' loops

Discussion in 'VHDL' started by xtaylorandrewsx, Apr 29, 2012.

  1. xtaylorandrewsx

    xtaylorandrewsx

    Joined:
    Apr 29, 2012
    Messages:
    2
    I am working on a design for a game of "snake". To determine the next position of the snake, I have a section of code that uses arrays to store the position of the snake and variables to store the index values of the head and tail of the snake. Then I have a 'for' loop that goes through every element of the array to determine the next position of the snake based on the value of the "direction" signal

    My problem is that the positions aren't updating. Now I'm not very familiar with using loops in VHDL but I have a feeling it may have something to do with the way I compare the index values of the loop to values stored in the variables. Any insight you all can give me would be greatly appreciated. Here is part of the code:

    Code:
        snake_motion : process(clk, reset, dir, mov_en, snake_pos, snake_dir)
            variable r_head_next : integer;
            variable c_head_next : integer;
            variable r_tail_next : integer;
            variable c_tail_next : integer;
            variable r_head : integer;
            variable c_head : integer;
            variable r_tail : integer;
            variable c_tail : integer;
        begin
            if reset = '1' then                            -- assign default values upon reset
                snake_pos <= snake_pos_def;
                snake_pos_next <= snake_pos_def;
                snake_dir <= snake_dir_def;
                snake_dir_next <= snake_dir_def;
                r_head := r_head_def;
                r_tail := r_tail_def;
                c_head := c_head_def;
                c_tail := c_tail_def;
            elsif (clk'EVENT and clk = '0') then
                mov_en <= '1';
            elsif (clk'EVENT and clk = '1') then
                snake_pos <= snake_pos_next;
                snake_dir <= snake_dir_next;
                r_head := r_head_next;
                r_tail := r_tail_next;
                c_head := c_head_next;
                c_tail := c_tail_next;
            end if;
            
            if mov_en = '1' then
                for r in 0 to max_row loop
                    for c in 0 to max_col loop
                        if ((r = r_head) and (c = c_head)) then        -- head of snake
                            snake_dir_next(r,c) <= dir;
                            if dir = "000" then
                                if r = max_row then
                                    r_head_next := 0;
                                    snake_pos_next(0,c) <= '1';
                                else
                                    r_head_next := (r+1);
                                    snake_pos_next((r+1),c) <= '1';
                                end if;
                            elsif dir = "001" then
                                   ......
    It should be noted that I currently have the direction fixed to "000"
     
    xtaylorandrewsx, Apr 29, 2012
    #1
    1. Advertising

  2. xtaylorandrewsx

    jeppe

    Joined:
    Mar 10, 2008
    Messages:
    348
    Location:
    Denmark
    Will this be VHDL code for simulation or synthezing (and implementation in a FPGA)
     
    jeppe, Apr 30, 2012
    #2
    1. Advertising

  3. xtaylorandrewsx

    xtaylorandrewsx

    Joined:
    Apr 29, 2012
    Messages:
    2
    I'm trying to implement it onto an FPGA. I'm using a Cyclone II DE2-70. I actually scrapped that design to try another method without using 'for' loops, but now I'm not getting any video output. Here is the section of code I'm working with:


    Code:
        type array1 is array(0 to 14, 0 to 19) of std_logic;
        signal snake_pos_def    : array1 := (    0 => (0 => '1', others => '0'), 
                                                1 => (0 => '1', others => '0'),
                                                2 => (0 => '1', others => '0'),
                                                others => (others => '0'));
               .....
        snake_pos <= snake_pos_def;
        
        snake_display : process(pix_row, pix_col, snake_pos)
        begin
            case pix_row(9 downto 5) is
                when "00000" =>
                    snake_on <= snake_pos(0, conv_integer(pix_col(9 downto 5)));
                when "00001" =>
                    snake_on <= snake_pos(1, conv_integer(pix_col(9 downto 5)));
                when "00010" =>
                    snake_on <= snake_pos(2, conv_integer(pix_col(9 downto 5)));
                when "00011" =>
                    snake_on <= snake_pos(3, conv_integer(pix_col(9 downto 5)));
                when others =>
                    snake_on <= '0';
            end case;
        end process snake_display;
    Right now I'm not going for motion, just trying to see a display
     
    xtaylorandrewsx, Apr 30, 2012
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Grey Plastic

    declaring variables inside for loops

    Grey Plastic, Aug 10, 2004, in forum: C++
    Replies:
    3
    Views:
    533
    Marco Manfredini
    Aug 10, 2004
  2. vijay

    float variables in loops

    vijay, May 4, 2005, in forum: C Programming
    Replies:
    8
    Views:
    363
    Kevin Bracey
    May 5, 2005
  3. Jason Cavett

    For Loops and Variables

    Jason Cavett, Apr 5, 2007, in forum: Java
    Replies:
    18
    Views:
    693
    Oliver Wong
    Apr 10, 2007
  4. Me
    Replies:
    2
    Views:
    249
  5. Derek Basch
    Replies:
    6
    Views:
    177
    Michele Dondi
    May 29, 2006
Loading...

Share This Page