When I assigned input pins to slide switch of DE10 Nano board, why I push the slide switch to ‘HIGH’ but all LEDs are off. Only a few times it successfully change to another state.
library ieee;
use ieee.std_logic_1164.all;
entity StateMachineProject is
port(
rst : in std_logic;
clk : in std_logic;
sw : in std_logic_vector(3 downto 1);
led : out std_logic_vector(3 downto 1)
);
end entity;
architecture rtl of StateMachineProject is
type stateVariable_type is (STATE1, STATE2, STATE3);
signal stateVariable: stateVariable_type;
begin
process1: process(rst, clk) is
begin
if rst = '0' then
stateVariable <= STATE1;
led <= "000"; -- disables all LEDs
elsif rising_edge(clk) then
case stateVariable is
when STATE1 =>
led <= "001";
if sw(1) = '1' then
stateVariable <= STATE2;
end if;
when STATE2 =>
led <= "010";
if sw(2) = '1' then
stateVariable <= STATE3;
end if;
when STATE3 =>
led <= "100";
if sw(3) = '1' then
stateVariable <= STATE1;
end if;
when others =>
stateVariable <= STATE1;
end case;
end if;
end process;
end rtl;