For loop 循环的VHDL-如果分支工作不正常

For loop 循环的VHDL-如果分支工作不正常,for-loop,vhdl,For Loop,Vhdl,我对vhdl相当陌生,但我正在尝试构建一个蛇游戏。在下面的循环中,eating='1'和ate='0'的约束似乎不起作用。就好像嵌套在if语句中的代码总是在运行 有关的if语句 if(snake_body_ram(i)(14)='1' or (eating='1' and ate='0'))then 这是整个过程 process(move, direction, snake_head_reg, snake_body_ram, clk, head_coord, direction, eating

我对vhdl相当陌生,但我正在尝试构建一个蛇游戏。在下面的循环中,eating='1'和ate='0'的约束似乎不起作用。就好像嵌套在if语句中的代码总是在运行

有关的if语句

if(snake_body_ram(i)(14)='1' or (eating='1' and ate='0'))then
这是整个过程

process(move, direction, snake_head_reg, snake_body_ram, clk, head_coord, direction, eating)
        variable dir_next, tail_next_dir : std_logic_vector(1 downto 0);
        variable coord_next : std_logic_vector(13 downto 0);
        variable ate: std_logic := '0';
        variable value : unsigned(5 downto 0) := (others=>'0');
    begin
        if(clk'event and clk='1')then
            if(move='1')then
                dir_next := snake_head_reg(16 downto 15);
                coord_next := snake_head_reg(13 downto 0);
                snake_head_reg(16 downto 15) <= direction;
                snake_head_reg(13 downto 0) <= head_coord;
                ate:='0';
                --look here brian
                bodyLabel: 
                    for i in 0 to 35 loop
                        if(snake_body_ram(i)(14)='1' or (eating='1' and ate='0'))then
                            snake_body_ram(i)(16 downto 15) <= dir_next;    
                            snake_body_ram(i)(13 downto 0) <= coord_next;
                            snake_body_ram(i)(14) <= '1';
                            if(eating='1')then
                                ate:='1';
                            end if;
                            dir_next := snake_body_ram(i)(16 downto 15);
                            coord_next := snake_body_ram(i)(13 downto 0);
                            if(i > 1)then
                                tail_next_dir:=snake_body_ram(i-1)(16 downto 15);
                            end if;
                        end if;
                    end loop;   
                snake_tail_reg(13 downto 0) <= coord_next;
                snake_tail_reg(14)<='1';
                snake_tail_reg(16 downto 15) <= tail_next_dir;
            end if;
        end if;
    end process;
过程(移动、方向、蛇头、蛇身、时钟、头协调、方向、进食)
变量dir\u next,tail\u next\u dir:std\u logic\u vector(1到0);
变量coord_next:std_逻辑_向量(13到0);
变量ate:std_逻辑:='0';
变量值:无符号(5到0):=(其他=>'0');
开始
如果(clk'事件和clk='1'),则
如果(move='1'),则
dir_next:=蛇头(16到15);
协调下一步:=蛇头注册(13到0);

snake_head_reg(16到15)我找到了另一种解决方案,但是我仍然很想知道上面提到的哪些方法不起作用。谢谢。我没有立即发现任何错误,但是您的过程敏感度列表中不应该包含所有这些信号。您编写了一个顺序过程,因此灵敏度列表中应该只有
clk
。把其他的拿走。
process(food_reg, snake_head_reg, clk, move, state, btn, snake_tail_reg, snake_body_ram)
        --variable ate : std_logic := '0';
    begin
        --if(clk'event and clk='1' and move='1' and state=play)then
        if(clk'event and clk='1')then
            eating <= '0';
            if(move='1' and state=play)then
                you_lose <= '0';
                --if()then
                    if(food_reg = snake_head_reg(13 downto 0))then
                        --ate food
                        food_eaten <= food_eaten_next;
                        eating <= '1';
                    elsif(snake_head_reg(13 downto 0) = snake_tail_reg(13 downto 0))then
                        --hit tail
                        you_lose <= '1';
                    elsif(unsigned(snake_head_reg(13 downto 7)) < 2 or unsigned(snake_head_reg(13 downto 7)) > 77 or unsigned(snake_head_reg(6 downto 0)) < 2 or unsigned(snake_head_reg(6 downto 0)) > 57)then
                        --hit a wall
                        you_lose <= '1';
                    else
                        --check for body
                        bodyLabel: 
                            for i in 0 to 35 loop
                                if(snake_body_ram(i)(14)='1' and you_lose = '0')then
                                    if(snake_head_reg(13 downto 0) = snake_body_ram(i)(13 downto 0)) then
                                        you_lose <= '1';
                                        exit;
                                    end if;
                                else
                                    exit;
                                end if;
                            end loop;
                    end if;
                --end if;
            end if;
        else
        end if;
    end process;