|
@@ -70,6 +70,13 @@ static volatile bool endstop_x_hit=false;
|
70
|
70
|
static volatile bool endstop_y_hit=false;
|
71
|
71
|
static volatile bool endstop_z_hit=false;
|
72
|
72
|
|
|
73
|
+static bool old_x_min_endstop=false;
|
|
74
|
+static bool old_x_max_endstop=false;
|
|
75
|
+static bool old_y_min_endstop=false;
|
|
76
|
+static bool old_y_max_endstop=false;
|
|
77
|
+static bool old_z_min_endstop=false;
|
|
78
|
+static bool old_z_max_endstop=false;
|
|
79
|
+
|
73
|
80
|
volatile long count_position[NUM_AXIS] = { 0, 0, 0, 0};
|
74
|
81
|
volatile char count_direction[NUM_AXIS] = { 1, 1, 1, 1};
|
75
|
82
|
|
|
@@ -260,6 +267,7 @@ ISR(TIMER1_COMPA_vect)
|
260
|
267
|
SERIAL_ERROR_START
|
261
|
268
|
SERIAL_ERROR(*(unsigned short *)OCR1A);
|
262
|
269
|
SERIAL_ERRORLNPGM(" ISR overtaking itself.");
|
|
270
|
+ OCR1A = 0x30000;
|
263
|
271
|
return;
|
264
|
272
|
} // The busy-flag is used to avoid reentering this interrupt
|
265
|
273
|
|
|
@@ -295,22 +303,26 @@ ISR(TIMER1_COMPA_vect)
|
295
|
303
|
WRITE(X_DIR_PIN, INVERT_X_DIR);
|
296
|
304
|
count_direction[X_AXIS]=-1;
|
297
|
305
|
#if X_MIN_PIN > -1
|
298
|
|
- if((READ(X_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x > 0)) {
|
|
306
|
+ bool x_min_endstop=(READ(X_MIN_PIN) != X_ENDSTOPS_INVERTING);
|
|
307
|
+ if(x_min_endstop && old_x_min_endstop && (current_block->steps_x > 0)) {
|
299
|
308
|
endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
300
|
309
|
endstop_x_hit=true;
|
301
|
310
|
step_events_completed = current_block->step_event_count;
|
302
|
311
|
}
|
|
312
|
+ old_x_min_endstop = x_min_endstop;
|
303
|
313
|
#endif
|
304
|
314
|
}
|
305
|
315
|
else { // +direction
|
306
|
316
|
WRITE(X_DIR_PIN,!INVERT_X_DIR);
|
307
|
317
|
count_direction[X_AXIS]=1;
|
308
|
318
|
#if X_MAX_PIN > -1
|
309
|
|
- if((READ(X_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_x > 0)){
|
|
319
|
+ bool x_max_endstop=(READ(X_MAX_PIN) != X_ENDSTOPS_INVERTING);
|
|
320
|
+ if(x_max_endstop && old_x_max_endstop && (current_block->steps_x > 0)){
|
310
|
321
|
endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
311
|
322
|
endstop_x_hit=true;
|
312
|
323
|
step_events_completed = current_block->step_event_count;
|
313
|
324
|
}
|
|
325
|
+ old_x_max_endstop = x_max_endstop;
|
314
|
326
|
#endif
|
315
|
327
|
}
|
316
|
328
|
|
|
@@ -318,22 +330,26 @@ ISR(TIMER1_COMPA_vect)
|
318
|
330
|
WRITE(Y_DIR_PIN,INVERT_Y_DIR);
|
319
|
331
|
count_direction[Y_AXIS]=-1;
|
320
|
332
|
#if Y_MIN_PIN > -1
|
321
|
|
- if((READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y > 0)) {
|
|
333
|
+ bool y_min_endstop=(READ(Y_MIN_PIN) != Y_ENDSTOPS_INVERTING);
|
|
334
|
+ if(y_min_endstop && old_y_min_endstop && (current_block->steps_y > 0)) {
|
322
|
335
|
endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
|
323
|
336
|
endstop_y_hit=true;
|
324
|
337
|
step_events_completed = current_block->step_event_count;
|
325
|
338
|
}
|
|
339
|
+ old_y_min_endstop = y_min_endstop;
|
326
|
340
|
#endif
|
327
|
341
|
}
|
328
|
342
|
else { // +direction
|
329
|
343
|
WRITE(Y_DIR_PIN,!INVERT_Y_DIR);
|
330
|
344
|
count_direction[Y_AXIS]=1;
|
331
|
345
|
#if Y_MAX_PIN > -1
|
332
|
|
- if((READ(Y_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_y > 0)){
|
|
346
|
+ bool y_max_endstop=(READ(Y_MAX_PIN) != Y_ENDSTOPS_INVERTING);
|
|
347
|
+ if(y_max_endstop && old_y_max_endstop && (current_block->steps_y > 0)){
|
333
|
348
|
endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
|
334
|
349
|
endstop_y_hit=true;
|
335
|
350
|
step_events_completed = current_block->step_event_count;
|
336
|
351
|
}
|
|
352
|
+ old_y_max_endstop = y_max_endstop;
|
337
|
353
|
#endif
|
338
|
354
|
}
|
339
|
355
|
|
|
@@ -341,22 +357,26 @@ ISR(TIMER1_COMPA_vect)
|
341
|
357
|
WRITE(Z_DIR_PIN,INVERT_Z_DIR);
|
342
|
358
|
count_direction[Z_AXIS]=-1;
|
343
|
359
|
#if Z_MIN_PIN > -1
|
344
|
|
- if((READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z > 0)) {
|
|
360
|
+ bool z_min_endstop=(READ(Z_MIN_PIN) != Z_ENDSTOPS_INVERTING);
|
|
361
|
+ if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) {
|
345
|
362
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
346
|
363
|
endstop_z_hit=true;
|
347
|
364
|
step_events_completed = current_block->step_event_count;
|
348
|
365
|
}
|
|
366
|
+ old_z_min_endstop = z_min_endstop;
|
349
|
367
|
#endif
|
350
|
368
|
}
|
351
|
369
|
else { // +direction
|
352
|
370
|
WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
|
353
|
371
|
count_direction[Z_AXIS]=1;
|
354
|
372
|
#if Z_MAX_PIN > -1
|
355
|
|
- if((READ(Z_MAX_PIN) != ENDSTOPS_INVERTING) && (current_block->steps_z > 0)){
|
|
373
|
+ bool z_max_endstop=(READ(Z_MAX_PIN) != Z_ENDSTOPS_INVERTING);
|
|
374
|
+ if(z_max_endstop && old_z_max_endstop && (current_block->steps_z > 0)) {
|
356
|
375
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
357
|
376
|
endstop_z_hit=true;
|
358
|
377
|
step_events_completed = current_block->step_event_count;
|
359
|
378
|
}
|
|
379
|
+ old_z_max_endstop = z_max_endstop;
|
360
|
380
|
#endif
|
361
|
381
|
}
|
362
|
382
|
|
|
@@ -654,6 +674,13 @@ void st_set_position(const long &x, const long &y, const long &z, const long &e)
|
654
|
674
|
CRITICAL_SECTION_END;
|
655
|
675
|
}
|
656
|
676
|
|
|
677
|
+void st_set_e_position(const long &e)
|
|
678
|
+{
|
|
679
|
+ CRITICAL_SECTION_START;
|
|
680
|
+ count_position[E_AXIS] = e;
|
|
681
|
+ CRITICAL_SECTION_END;
|
|
682
|
+}
|
|
683
|
+
|
657
|
684
|
long st_get_position(char axis)
|
658
|
685
|
{
|
659
|
686
|
long count_pos;
|