type my_state is (rst_state, green_state, yellow_state, red_state);
signal next_state, state: my_state;
p_next: process(state, rst)
begin
case state is
when rst_state => if rst = '1' then
next_state <= rst_state;
else
next_state <= green_state;
end if;
when green_state => next_state <= yellow_state;
when yellow_state =>next_state <= red_state;
when red_state => if rst = '1' then
next_state <= rst_state;
else
next_state <= green_state;
end if;
when others => next_state <= rst_state;
end case;
end process;
p_reg: process(clk)
begin
if clk'event and clk = '1' then
state <= next_state;
end if;
end process;
p_out: process(state)
begin
case state is
when rst_state =>
red <= '0';
yellow <= '0';
green <= '0';
when green_state =>
red <= '0';
yellow <= '0';
green <= '1';
when yellow_state =>
red <= '0';
yellow <= '1';
green <= '0';
when red_state =>
red <= '1';
yellow <= '0';
green <= '0';
when others =>
red <= '0';
yellow <= '0';
green <= '0';
end case;
end process;
Opdracht:
Pas de FSM voor de aansturing van verkeerslichten aan zodat er vanuit elke toestand naar rst_state kan worden gesprongen. Teken het nieuwe toestandsdiagramma. Schrijf de nieuwe next state functie (de output functie verandert niet)