aboutsummaryrefslogtreecommitdiff
path: root/src/play_rtl.vhd
blob: 8452236f714df674d3a25e193682e7c002d68362 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
------------------------------------------------------------------
-- module     : play
------------------------------------------------------------------
-- author     : Friedrich Beckmann
-- company    : university of applied sciences augsburg
------------------------------------------------------------------
-- description: Statemachine for LED game
--              
------------------------------------------------------------------
-- revisions : 0.1 - 
------------------------------------------------------------------

-- 5 LED outputs
-- One one-second enable input
-- KEY input with preceding rising_edge detector

-- step LED4 LED3 LED2 LED1 LED0
--  1    x    -    -    -    -
--  2    -    x    -    -    -
--  3    -    -    x    -    -
--  4    -    -    -    x    -
--  5    -    -    -    -    x
--  6    x    -    -    -    -
--  ...  this pattern continues
-- If LED2 is on and KEY is pressed then the pattern continues as follows
--  1    x    -    -    -    -
--  2    -    -    -    -    x
--  ... this pattern continues until
--  KEY is pressed again. Then the previous pattern restarts from LED 2

library ieee;
use ieee.std_logic_1164.all;

entity play is
  port (clk        : in  std_ulogic;
        rst_n      : in  std_ulogic;
        onesec_i   : in  std_ulogic;
        key_i      : in  std_ulogic;
        led_o      : out std_ulogic_vector(4 downto 0));
end play;

architecture rtl of play is

  type state_t is (start_s,one_s,chance_s,four_s,last_s,hit0_s,hit1_s);
  signal current_state,next_state : state_t;

begin

  current_state <= start_s when rst_n = '0' else next_state when rising_edge(clk);

  next_p : process(current_state, onesec_i, key_i)
    begin
      next_state <= current_state;
      led_o <= "00000";
      case current_state is
        when start_s =>
          led_o <= "10000";
          if onesec_i = '1' then
            next_state <= one_s;            
          end if;
        when one_s =>
          led_o <= "01000";
          if onesec_i = '1' then 
            next_state <= chance_s;
          end if;
        when chance_s =>
          led_o <= "00100";
          if key_i = '1' then
            next_state <= hit0_s;
          elsif onesec_i = '1' then
            next_state <= four_s; 
          end if;
        when four_s =>
          led_o <= "00010";
          if onesec_i = '1' then
            next_state <= last_s;
          end if;
        when last_s =>
          led_o <= "00001";
          if onesec_i = '1' then
            next_state <= start_s;
          end if;
        when hit0_s =>
          led_o <= "10000";
          if key_i = '1' then
            next_state <= chance_s;
          elsif onesec_i = '1' then
            next_state <= hit1_s;
          end if;
        when hit1_s =>
          led_o <= "00001";
          if key_i = '1' then
            next_state <= chance_s;
          elsif onesec_i = '1' then
            next_state <= hit0_s;
          end if;         
        when others => null;
      end case;
    end process;
        
end architecture rtl;