-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstepper.v
298 lines (168 loc) · 4.14 KB
/
stepper.v
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company:
// Engineer:
//
// Create Date: 21:13:43 08/13/2018
// Design Name:
// Module Name: stepper
// Project Name:
// Target Devices:
// Tool versions:
// Description:
//
// Dependencies:
//
// Revision:
// Revision 0.01 - File Created
// Additional Comments:
//
//////////////////////////////////////////////////////////////////////////////////
module stepper(
input clk,
input onoff, //Habilita el movimiento del motor
input cwccw, //Sentido de movimiento
input enabler, //Habilitador cada 1 seg
input fushs, //Paso completo o medio paso
input reseteo, //Resetea al estado inicial
input [3:0] state, //Estado
output [3:0] stateout, //Estado
output w1,
output w2,
output w3,
output w4
);
//type state is(reset,first, second, third, fourth, half1,half2,half3,half4);
reg psstate;
reg nxstate; /*: state*/;
localparam state1 = 4'b1;
localparam state2 = 4'b2;
localparam state3 = 4'b4;
localparam state4 = 4'b8;
//signal motor:std_logic_vector(3 downto 0);
/*
process (clk_s,rst)
begin
if Rst = '0' then
Ps_state <= reset;
elsif clk_s'event and clk_s='1' then
if Step_en = '1' then
Ps_state <= Nx_state;
end if;
end if;
end process;
process (ps_state,CW_CCW,Step_en,rst,FS_HS)
begin
case(ps_state) is
when reset =>
Nx_state <= first;
when first =>
if FS_HS = '0' then ---FS_HS='1' then HALF STEPs
if CW_CCW = '1' then
Nx_state <= second; ----assigning each step of motor rotation
else
Nx_state <= fourth;
end if;
else
if CW_CCW = '1' then
Nx_state <= half1;
else
Nx_state <= half4;
end if;
end if;
when half1 =>
if CW_CCW = '1' then
Nx_state <= second;
else
Nx_state <= first;
end if;
when second =>
if FS_HS = '0' then-- FS_HS='1' then HALF STEPs
if CW_CCW = '1' then
Nx_state <= third;
else
Nx_state <= first;
end if;
else
if CW_CCW = '1' then
Nx_state <= half2;
else
Nx_state <= half1;
end if;
end if;
when half2 =>
if CW_CCW = '1' then
Nx_state <= third;
else
Nx_state <= second;
end if;
when third =>
if FS_HS = '0' then -- FS_HS='1' then HALF STEPs
if CW_CCW = '1' then
Nx_state <= fourth;
else
Nx_state <= second;
end if;
else
if CW_CCW = '1' then
Nx_state <= half3;
else
Nx_state <= half2;
end if;
end if;
when half3 =>
if CW_CCW = '1' then
Nx_state <= fourth;
else
Nx_state <= third;
end if;
when fourth =>
if FS_HS = '0' then -- FS_HS='1' then HALF STEPs
if CW_CCW = '1' then
Nx_state <= first;
else
Nx_state <= third;
end if;
else
if CW_CCW = '1' then
Nx_state <= half4;
else
Nx_state <= half3;
end if;
end if;
when half4 =>
if CW_CCW = '1' then
Nx_state <= first;
else
Nx_state <= fourth;
end if;
when others => Nx_state <= reset;
end case;
end process;
process(ps_state)
begin
case ps_state is
when reset =>
Motor <= "0000"; ----assigning motor control on/off
when first =>
Motor <= "1000";
when half1 =>
Motor <= "1100";
when second =>
Motor <= "0100";
when half2 =>
Motor <= "0110";
when third =>
Motor <= "0010";
when half3 =>
Motor <= "0011";
when fourth =>
Motor <= "0001";
when half4 =>
Motor <= "1001";
when others =>
Motor <= "0000";
end case;
end process;
*/
endmodule