-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjump_fsm.sv
147 lines (125 loc) · 2.77 KB
/
jump_fsm.sv
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/* State machine for jumping
* this reads in keycodes and boundary and sends out
* signals to physics module
*/
module jump_fsm( input Reset, frame_clk, jump_en, hit_ground,
input [31:0] keycode,
output int jump_x_motion,
jump_y_motion);
enum logic [5:0] {
no_jump,
jump_up_1,
jump_up_2,
jump_up_3,
jump_up_4,
jump_up_5,
jump_up_6,
jump_up_7,
jump_up_8,
jump_up_9,
jump_up_10,
jump_up_11,
jump_up_12,
jump_up_13,
jump_up_14,
jump_up_15,
jump_up_16,
jump_up_17,
jump_up_18,
jump_up_19,
jump_up_20
} state, next_state;
always_ff @ (posedge Reset or posedge frame_clk)
begin
if (Reset)
state <= no_jump;
else
state <= next_state;
end
always_comb
begin
jump_x_motion = 0;
jump_y_motion = 0;
if (hit_ground)
next_state = no_jump;
else
next_state = state;
// jump state machine
unique case (state)
no_jump :
if (jump_en)
next_state = jump_up_1;
else
next_state = no_jump;
jump_up_1 :
next_state = jump_up_2;
jump_up_2 :
next_state = jump_up_3;
jump_up_3 :
next_state = jump_up_4;
jump_up_4 :
next_state = jump_up_5;
jump_up_5 :
next_state = jump_up_6;
jump_up_6 :
next_state = jump_up_7;
jump_up_7 :
next_state = jump_up_8;
jump_up_8 :
next_state = jump_up_9;
jump_up_9 :
next_state = jump_up_10;
jump_up_10 :
next_state = jump_up_11;
jump_up_11 :
next_state = jump_up_12;
jump_up_12:
next_state = jump_up_13;
jump_up_13 :
next_state = jump_up_14;
jump_up_14 :
next_state = jump_up_15;
jump_up_15 :
next_state = jump_up_16;
jump_up_16 :
next_state = jump_up_17;
jump_up_17 :
next_state = jump_up_18;
jump_up_18 :
next_state = jump_up_19;
jump_up_19 :
next_state = jump_up_20;
jump_up_20 :
next_state =no_jump;
default : ;
endcase
// assign base velocities for movement
case (state)
no_jump : begin
jump_x_motion = 0;
jump_y_motion = 0;
end
jump_up_1 : jump_y_motion = -12;
jump_up_2 : jump_y_motion = -12;
jump_up_3 : jump_y_motion = -12;
jump_up_4 : jump_y_motion = -12;
jump_up_5 : jump_y_motion = -10;
jump_up_6 : jump_y_motion = -10;
jump_up_7 : jump_y_motion = -10;
jump_up_8 : jump_y_motion = -10;
jump_up_9 : jump_y_motion = -8;
jump_up_10 : jump_y_motion = -8;
jump_up_11 : jump_y_motion = -6;
jump_up_12 : jump_y_motion = -6;
jump_up_13 : jump_y_motion = -4;
jump_up_14 : jump_y_motion = -4;
jump_up_15 : jump_y_motion = -2;
jump_up_16 : jump_y_motion = -2;
jump_up_17 : jump_y_motion = -2;
jump_up_18 : jump_y_motion = -2;
jump_up_19 : jump_y_motion = 0;
jump_up_20 : jump_y_motion = 0;
default : ;
endcase
end
endmodule