|
@@ -66,14 +66,12 @@ static char step_loops;
|
66
|
66
|
|
67
|
67
|
volatile long endstops_trigsteps[3]={0,0,0};
|
68
|
68
|
volatile long endstops_stepsTotal,endstops_stepsDone;
|
69
|
|
-static volatile bool endstops_hit=false;
|
|
69
|
+static volatile bool endstop_x_hit=false;
|
|
70
|
+static volatile bool endstop_y_hit=false;
|
|
71
|
+static volatile bool endstop_z_hit=false;
|
70
|
72
|
|
71
|
|
-// if DEBUG_STEPS is enabled, M114 can be used to compare two methods of determining the X,Y,Z position of the printer.
|
72
|
|
-// for debugging purposes only, should be disabled by default
|
73
|
|
-#ifdef DEBUG_STEPS
|
74
|
|
- volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
|
75
|
|
- volatile int count_direction[NUM_AXIS] = { 1, 1, 1, 1};
|
76
|
|
-#endif
|
|
73
|
+volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
|
|
74
|
+volatile char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
|
77
|
75
|
|
78
|
76
|
//===========================================================================
|
79
|
77
|
//=============================functions ============================
|
|
@@ -155,49 +153,32 @@ asm volatile ( \
|
155
|
153
|
#define ENABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 |= (1<<OCIE1A)
|
156
|
154
|
#define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
|
157
|
155
|
|
158
|
|
-
|
159
|
|
-inline void endstops_triggered(const unsigned long &stepstaken)
|
160
|
|
-{
|
161
|
|
- //this will only work if there is no bufferig
|
162
|
|
- //however, if you perform a move at which the endstops should be triggered, and wait for it to complete, i.e. by blocking command, it should work
|
163
|
|
- //yes, it uses floats, but: if endstops are triggered, thats hopefully not critical anymore anyways.
|
164
|
|
- //endstops_triggerpos;
|
165
|
|
-
|
166
|
|
- if(endstops_hit) //hitting a second time while the first hit is not reported
|
167
|
|
- return;
|
168
|
|
- if(current_block == NULL)
|
169
|
|
- return;
|
170
|
|
- endstops_stepsTotal=current_block->step_event_count;
|
171
|
|
- endstops_stepsDone=stepstaken;
|
172
|
|
- endstops_trigsteps[0]=current_block->steps_x;
|
173
|
|
- endstops_trigsteps[1]=current_block->steps_y;
|
174
|
|
- endstops_trigsteps[2]=current_block->steps_z;
|
175
|
|
-
|
176
|
|
- endstops_hit=true;
|
177
|
|
-}
|
178
|
|
-
|
179
|
156
|
void checkHitEndstops()
|
180
|
157
|
{
|
181
|
|
- if( !endstops_hit)
|
182
|
|
- return;
|
183
|
|
- float endstops_triggerpos[3]={0,0,0};
|
184
|
|
- float ratiodone=endstops_stepsDone/float(endstops_stepsTotal); //ratio of current_block thas was performed
|
185
|
|
-
|
186
|
|
- endstops_triggerpos[0]=current_position[0]-(endstops_trigsteps[0]*ratiodone)/float(axis_steps_per_unit[0]);
|
187
|
|
- endstops_triggerpos[1]=current_position[1]-(endstops_trigsteps[1]*ratiodone)/float(axis_steps_per_unit[1]);
|
188
|
|
- endstops_triggerpos[2]=current_position[2]-(endstops_trigsteps[2]*ratiodone)/float(axis_steps_per_unit[2]);
|
189
|
|
- SERIAL_ECHO_START;
|
190
|
|
- SERIAL_ECHOPGM("endstops hit: ");
|
191
|
|
- SERIAL_ECHOPAIR(" X:",endstops_triggerpos[0]);
|
192
|
|
- SERIAL_ECHOPAIR(" Y:",endstops_triggerpos[1]);
|
193
|
|
- SERIAL_ECHOPAIR(" Z:",endstops_triggerpos[2]);
|
194
|
|
- SERIAL_ECHOLN("");
|
195
|
|
- endstops_hit=false;
|
|
158
|
+ if( endstop_x_hit || endstop_y_hit || endstop_z_hit) {
|
|
159
|
+ SERIAL_ECHO_START;
|
|
160
|
+ SERIAL_ECHOPGM("endstops hit: ");
|
|
161
|
+ if(endstop_x_hit) {
|
|
162
|
+ SERIAL_ECHOPAIR(" X:",(float)endstops_trigsteps[X_AXIS]/axis_steps_per_unit[X_AXIS]);
|
|
163
|
+ }
|
|
164
|
+ if(endstop_y_hit) {
|
|
165
|
+ SERIAL_ECHOPAIR(" Y:",(float)endstops_trigsteps[Y_AXIS]/axis_steps_per_unit[Y_AXIS]);
|
|
166
|
+ }
|
|
167
|
+ if(endstop_z_hit) {
|
|
168
|
+ SERIAL_ECHOPAIR(" Z:",(float)endstops_trigsteps[Z_AXIS]/axis_steps_per_unit[Z_AXIS]);
|
|
169
|
+ }
|
|
170
|
+ SERIAL_ECHOLN("");
|
|
171
|
+ endstop_x_hit=false;
|
|
172
|
+ endstop_y_hit=false;
|
|
173
|
+ endstop_z_hit=false;
|
|
174
|
+ }
|
196
|
175
|
}
|
197
|
176
|
|
198
|
177
|
void endstops_hit_on_purpose()
|
199
|
178
|
{
|
200
|
|
- endstops_hit=false;
|
|
179
|
+ endstop_x_hit=false;
|
|
180
|
+ endstop_y_hit=false;
|
|
181
|
+ endstop_z_hit=false;
|
201
|
182
|
}
|
202
|
183
|
|
203
|
184
|
// __________________________
|
|
@@ -312,24 +293,22 @@ ISR(TIMER1_COMPA_vect)
|
312
|
293
|
// Set direction en check limit switches
|
313
|
294
|
if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
|
314
|
295
|
WRITE(X_DIR_PIN, INVERT_X_DIR);
|
315
|
|
- #ifdef DEBUG_STEPS
|
316
|
|
- count_direction[X_AXIS]=-1;
|
317
|
|
- #endif
|
|
296
|
+ count_direction[X_AXIS]=-1;
|
318
|
297
|
#if X_MIN_PIN > -1
|
319
|
|
- if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) {
|
320
|
|
- // endstops_triggered(step_events_completed);
|
|
298
|
+ if((READ(X_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x > 0)) {
|
|
299
|
+ endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
|
300
|
+ endstop_x_hit=true;
|
321
|
301
|
step_events_completed = current_block->step_event_count;
|
322
|
302
|
}
|
323
|
303
|
#endif
|
324
|
304
|
}
|
325
|
305
|
else { // +direction
|
326
|
306
|
WRITE(X_DIR_PIN,!INVERT_X_DIR);
|
327
|
|
- #ifdef DEBUG_STEPS
|
328
|
|
- count_direction[X_AXIS]=1;
|
329
|
|
- #endif
|
|
307
|
+ count_direction[X_AXIS]=1;
|
330
|
308
|
#if X_MAX_PIN > -1
|
331
|
|
- if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x >0)){
|
332
|
|
- // endstops_triggered(step_events_completed);
|
|
309
|
+ if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x > 0)){
|
|
310
|
+ endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
|
311
|
+ endstop_x_hit=true;
|
333
|
312
|
step_events_completed = current_block->step_event_count;
|
334
|
313
|
}
|
335
|
314
|
#endif
|
|
@@ -337,24 +316,22 @@ ISR(TIMER1_COMPA_vect)
|
337
|
316
|
|
338
|
317
|
if ((out_bits & (1<<Y_AXIS)) != 0) { // -direction
|
339
|
318
|
WRITE(Y_DIR_PIN,INVERT_Y_DIR);
|
340
|
|
- #ifdef DEBUG_STEPS
|
341
|
|
- count_direction[Y_AXIS]=-1;
|
342
|
|
- #endif
|
|
319
|
+ count_direction[Y_AXIS]=-1;
|
343
|
320
|
#if Y_MIN_PIN > -1
|
344
|
|
- if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) {
|
345
|
|
-// endstops_triggered(step_events_completed);
|
|
321
|
+ if((READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y > 0)) {
|
|
322
|
+ endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
|
|
323
|
+ endstop_y_hit=true;
|
346
|
324
|
step_events_completed = current_block->step_event_count;
|
347
|
325
|
}
|
348
|
326
|
#endif
|
349
|
327
|
}
|
350
|
328
|
else { // +direction
|
351
|
329
|
WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
|
352
|
|
- #ifdef DEBUG_STEPS
|
353
|
|
- count_direction[Y_AXIS]=1;
|
354
|
|
- #endif
|
|
330
|
+ count_direction[Y_AXIS]=1;
|
355
|
331
|
#if Y_MAX_PIN > -1
|
356
|
|
- if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y >0)){
|
357
|
|
- // endstops_triggered(step_events_completed);
|
|
332
|
+ if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y > 0)){
|
|
333
|
+ endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
|
|
334
|
+ endstop_y_hit=true;
|
358
|
335
|
step_events_completed = current_block->step_event_count;
|
359
|
336
|
}
|
360
|
337
|
#endif
|
|
@@ -362,34 +339,36 @@ ISR(TIMER1_COMPA_vect)
|
362
|
339
|
|
363
|
340
|
if ((out_bits & (1<<Z_AXIS)) != 0) { // -direction
|
364
|
341
|
WRITE(Z_DIR_PIN,INVERT_Z_DIR);
|
365
|
|
- #ifdef DEBUG_STEPS
|
366
|
342
|
count_direction[Z_AXIS]=-1;
|
367
|
|
- #endif
|
368
|
343
|
#if Z_MIN_PIN > -1
|
369
|
|
- if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) {
|
370
|
|
- // endstops_triggered(step_events_completed);
|
|
344
|
+ if((READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z > 0)) {
|
|
345
|
+ endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
|
346
|
+ endstop_z_hit=true;
|
371
|
347
|
step_events_completed = current_block->step_event_count;
|
372
|
348
|
}
|
373
|
349
|
#endif
|
374
|
350
|
}
|
375
|
351
|
else { // +direction
|
376
|
352
|
WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
|
377
|
|
- #ifdef DEBUG_STEPS
|
378
|
353
|
count_direction[Z_AXIS]=1;
|
379
|
|
- #endif
|
380
|
354
|
#if Z_MAX_PIN > -1
|
381
|
|
- if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z >0)){
|
382
|
|
- // endstops_triggered(step_events_completed);
|
|
355
|
+ if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z > 0)){
|
|
356
|
+ endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
|
357
|
+ endstop_z_hit=true;
|
383
|
358
|
step_events_completed = current_block->step_event_count;
|
384
|
359
|
}
|
385
|
360
|
#endif
|
386
|
361
|
}
|
387
|
362
|
|
388
|
363
|
#ifndef ADVANCE
|
389
|
|
- if ((out_bits & (1<<E_AXIS)) != 0) // -direction
|
|
364
|
+ if ((out_bits & (1<<E_AXIS)) != 0) { // -direction
|
390
|
365
|
WRITE(E_DIR_PIN,INVERT_E_DIR);
|
391
|
|
- else // +direction
|
|
366
|
+ count_direction[E_AXIS]=-1;
|
|
367
|
+ }
|
|
368
|
+ else { // +direction
|
392
|
369
|
WRITE(E_DIR_PIN,!INVERT_E_DIR);
|
|
370
|
+ count_direction[E_AXIS]=-1;
|
|
371
|
+ }
|
393
|
372
|
#endif //!ADVANCE
|
394
|
373
|
|
395
|
374
|
for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)
|
|
@@ -422,9 +401,7 @@ ISR(TIMER1_COMPA_vect)
|
422
|
401
|
WRITE(X_STEP_PIN, HIGH);
|
423
|
402
|
counter_x -= current_block->step_event_count;
|
424
|
403
|
WRITE(X_STEP_PIN, LOW);
|
425
|
|
- #ifdef DEBUG_STEPS
|
426
|
|
- count_position[X_AXIS]+=count_direction[X_AXIS];
|
427
|
|
- #endif
|
|
404
|
+ count_position[X_AXIS]+=count_direction[X_AXIS];
|
428
|
405
|
}
|
429
|
406
|
|
430
|
407
|
counter_y += current_block->steps_y;
|
|
@@ -432,9 +409,7 @@ ISR(TIMER1_COMPA_vect)
|
432
|
409
|
WRITE(Y_STEP_PIN, HIGH);
|
433
|
410
|
counter_y -= current_block->step_event_count;
|
434
|
411
|
WRITE(Y_STEP_PIN, LOW);
|
435
|
|
- #ifdef DEBUG_STEPS
|
436
|
|
- count_position[Y_AXIS]+=count_direction[Y_AXIS];
|
437
|
|
- #endif
|
|
412
|
+ count_position[Y_AXIS]+=count_direction[Y_AXIS];
|
438
|
413
|
}
|
439
|
414
|
|
440
|
415
|
counter_z += current_block->steps_z;
|
|
@@ -442,9 +417,7 @@ ISR(TIMER1_COMPA_vect)
|
442
|
417
|
WRITE(Z_STEP_PIN, HIGH);
|
443
|
418
|
counter_z -= current_block->step_event_count;
|
444
|
419
|
WRITE(Z_STEP_PIN, LOW);
|
445
|
|
- #ifdef DEBUG_STEPS
|
446
|
|
- count_position[Z_AXIS]+=count_direction[Z_AXIS];
|
447
|
|
- #endif
|
|
420
|
+ count_position[Z_AXIS]+=count_direction[Z_AXIS];
|
448
|
421
|
}
|
449
|
422
|
|
450
|
423
|
#ifndef ADVANCE
|
|
@@ -453,6 +426,7 @@ ISR(TIMER1_COMPA_vect)
|
453
|
426
|
WRITE(E_STEP_PIN, HIGH);
|
454
|
427
|
counter_e -= current_block->step_event_count;
|
455
|
428
|
WRITE(E_STEP_PIN, LOW);
|
|
429
|
+ count_position[E_AXIS]+=count_direction[E_AXIS];
|
456
|
430
|
}
|
457
|
431
|
#endif //!ADVANCE
|
458
|
432
|
step_events_completed += 1;
|
|
@@ -669,3 +643,22 @@ void st_synchronize()
|
669
|
643
|
LCD_STATUS;
|
670
|
644
|
}
|
671
|
645
|
}
|
|
646
|
+
|
|
647
|
+void st_set_position(const long &x, const long &y, const long &z, const long &e)
|
|
648
|
+{
|
|
649
|
+ CRITICAL_SECTION_START;
|
|
650
|
+ count_position[X_AXIS] = x;
|
|
651
|
+ count_position[Y_AXIS] = y;
|
|
652
|
+ count_position[Z_AXIS] = z;
|
|
653
|
+ count_position[E_AXIS] = e;
|
|
654
|
+ CRITICAL_SECTION_END;
|
|
655
|
+}
|
|
656
|
+
|
|
657
|
+long st_get_position(char axis)
|
|
658
|
+{
|
|
659
|
+ long count_pos;
|
|
660
|
+ CRITICAL_SECTION_START;
|
|
661
|
+ count_pos = count_position[axis];
|
|
662
|
+ CRITICAL_SECTION_END;
|
|
663
|
+ return count_pos;
|
|
664
|
+}
|