Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > VHDL > Help with variables and 'for' loops

Reply
Thread Tools

Help with variables and 'for' loops

 
 
xtaylorandrewsx xtaylorandrewsx is offline
Junior Member
Join Date: Apr 2012
Posts: 2
 
      04-29-2012
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"
 
Reply With Quote
 
 
 
 
jeppe jeppe is offline
Senior Member
Join Date: Mar 2008
Location: Denmark
Posts: 348
 
      04-30-2012
Will this be VHDL code for simulation or synthezing (and implementation in a FPGA)
 
Reply With Quote
 
 
 
 
xtaylorandrewsx xtaylorandrewsx is offline
Junior Member
Join Date: Apr 2012
Posts: 2
 
      04-30-2012
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Put variables into member variables or function variables? tjumail@gmail.com C++ 9 03-23-2008 04:03 PM
For Loops and Variables Jason Cavett Java 18 04-10-2007 02:38 PM
foreach loops and lexically scoped loop variables Derek Basch Perl Misc 6 05-29-2006 07:44 AM
Loops with loops using html-template Me Perl Misc 2 01-12-2006 05:07 PM
declaring variables inside for loops Grey Plastic C++ 3 08-10-2004 10:40 AM



Advertisments