forked from Traumflug/Teacup_Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.c
299 lines (264 loc) · 5.57 KB
/
home.c
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
299
#include "home.h"
/** \file
\brief Homing routines
*/
#include "dda.h"
#include "dda_queue.h"
#include "delay.h"
#include "pinio.h"
/// home all 3 axes
void home() {
#if defined X_MIN_PIN
home_x_negative();
#elif defined X_MAX_PIN
home_x_positive();
#endif
#if defined Y_MIN_PIN
home_y_negative();
#elif defined Y_MAX_PIN
home_y_positive();
#endif
#if defined Z_MAX_PIN
home_z_positive();
#elif defined Z_MIN_PIN
home_z_negative();
#endif
}
/// find X MIN endstop
void home_x_negative() {
queue_wait();
#if defined X_MIN_PIN
uint8_t denoise_count = 0;
// home X
x_enable();
// hit home hard
x_direction(0);
while (denoise_count < 8) {
// denoise
if (x_min())
denoise_count++;
else
denoise_count = 0;
// step
x_step();
delay(5);
unstep();
// wait until next step time
delay((uint32_t) (60.0 * 1000000.0 / STEPS_PER_MM_X / ((float) MAXIMUM_FEEDRATE_X)));
}
denoise_count = 0;
// back off slowly
x_direction(1);
while (x_min() != 0) {
// step
x_step();
delay(5);
unstep();
// wait until next step time
delay((uint32_t) (60.0 * 1000000.0 / STEPS_PER_MM_X / ((float) SEARCH_FEEDRATE_X)));
}
// set X home
startpoint.X = current_position.X = 0;
#endif
}
/// find X_MAX endstop
void home_x_positive() {
queue_wait();
#if defined X_MAX_PIN
uint8_t denoise_count = 0;
// home X
x_enable();
// hit home hard
x_direction(1);
while (denoise_count < 8) {
// denoise
if (x_max())
denoise_count++;
else
denoise_count = 0;
// step
x_step();
delay(5);
unstep();
// wait until next step time
delay((uint32_t) (60.0 * 1000000.0 / STEPS_PER_MM_X / ((float) MAXIMUM_FEEDRATE_X)));
}
denoise_count = 0;
// back off slowly
x_direction(0);
while (x_max() != 0) {
// step
x_step();
delay(5);
unstep();
// wait until next step time
delay((uint32_t) (60.0 * 1000000.0 / STEPS_PER_MM_X / ((float) SEARCH_FEEDRATE_X)));
}
// set X home
TARGET t = {0, 0, 0, 0, 0};
// set position to MAX
startpoint.X = current_position.X = (int32_t) (X_MAX * STEPS_PER_MM_X);
// go to zero
t.F = MAXIMUM_FEEDRATE_X;
enqueue(&t);
#endif
}
/// fund Y MIN endstop
void home_y_negative() {
queue_wait();
#if defined Y_MIN_PIN
uint8_t denoise_count = 0;
// home Y
y_enable();
// hit home hard
y_direction(0);
while (denoise_count < 8) {
// denoise
if (y_min())
denoise_count++;
else
denoise_count = 0;
// step
y_step();
delay(5);
unstep();
// wait until neyt step time
delay((uint32_t) (60.0 * 1000000.0 / STEPS_PER_MM_Y / ((float) MAXIMUM_FEEDRATE_Y)));
}
denoise_count = 0;
// back off slowly
y_direction(1);
while (y_min() != 0) {
// step
y_step();
delay(5);
unstep();
// wait until next step time
delay((uint32_t) (60.0 * 1000000.0 / STEPS_PER_MM_Y / ((float) SEARCH_FEEDRATE_Y)));
}
// set Y home
startpoint.Y = current_position.Y = 0;
#endif
}
/// find Y MAX endstop
void home_y_positive() {
queue_wait();
#if defined Y_MAX_PIN
uint8_t denoise_count = 0;
// home Y
y_enable();
// hit home hard
y_direction(1);
while (denoise_count < 8) {
// denoise
if (y_max())
denoise_count++;
else
denoise_count = 0;
// step
y_step();
delay(5);
unstep();
// wait until neyt step time
delay((uint32_t) (60.0 * 1000000.0 / STEPS_PER_MM_Y / ((float) MAXIMUM_FEEDRATE_Y)));
}
denoise_count = 0;
// back off slowly
y_direction(0);
while (y_max() != 0) {
// step
y_step();
delay(5);
unstep();
// wait until next step time
delay((uint32_t) (60.0 * 1000000.0 / STEPS_PER_MM_Y / ((float) SEARCH_FEEDRATE_Y)));
}
// set Y home
TARGET t = {0, 0, 0, 0, 0};
// set position to MAX
startpoint.Y = current_position.Y = (int32_t) (Y_MAX * STEPS_PER_MM_Y);
// go to zero
t.F = MAXIMUM_FEEDRATE_Y;
enqueue(&t);
#endif
}
/// find Z MIN endstop
void home_z_negative() {
queue_wait();
#if defined Z_MIN_PIN
uint8_t denoise_count = 0;
// home Z
z_enable();
// hit home hard
z_direction(0);
while (denoise_count < 8) {
// denoise
if (z_min())
denoise_count++;
else
denoise_count = 0;
// step
z_step();
delay(5);
unstep();
// wait until next step time
delay((uint32_t) (60.0 * 1000000.0 / STEPS_PER_MM_Z / ((float) MAXIMUM_FEEDRATE_Z)));
}
denoise_count = 0;
// back off slowly
z_direction(1);
while (z_min() != 0) {
// step
z_step();
delay(5);
unstep();
// wait until next step time
delay((uint32_t) (60.0 * 1000000.0 / STEPS_PER_MM_Z / ((float) SEARCH_FEEDRATE_Z)));
}
// set Z home
startpoint.Z = current_position.Z = 0;
z_disable();
#endif
}
/// find Z MAX endstop
void home_z_positive() {
queue_wait();
#if defined Z_MAX_PIN
uint8_t denoise_count = 0;
// home Z
z_enable();
// hit home hard
z_direction(1);
while (denoise_count < 8) {
// denoise
if (z_max())
denoise_count++;
else
denoise_count = 0;
// step
z_step();
delay(5);
unstep();
// wait until next step time
delay((uint32_t) (60.0 * 1000000.0 / STEPS_PER_MM_Z / ((float) MAXIMUM_FEEDRATE_Z)));
}
denoise_count = 0;
// back off slowly
z_direction(0);
while (z_max() != 0) {
// step
z_step();
delay(5);
unstep();
// wait until next step time
delay((uint32_t) (60.0 * 1000000.0 / STEPS_PER_MM_Z / ((float) SEARCH_FEEDRATE_Z)));
}
// set Z home
TARGET t = {0, 0, 0, 0, 0};
// set position to MAX
startpoint.Z = current_position.Z = (int32_t) (Z_MAX * STEPS_PER_MM_Z);
// go to zero
t.F = MAXIMUM_FEEDRATE_Z;
enqueue(&t);
#endif
}