|
@@ -56,8 +56,8 @@ static unsigned long step_events_completed; // The number of step events execute
|
56
|
56
|
#ifdef ADVANCE
|
57
|
57
|
static long advance_rate, advance, final_advance = 0;
|
58
|
58
|
static short old_advance = 0;
|
59
|
|
- static short e_steps;
|
60
|
59
|
#endif
|
|
60
|
+static short e_steps;
|
61
|
61
|
static unsigned char busy = false; // TRUE when SIG_OUTPUT_COMPARE1A is being serviced. Used to avoid retriggering that handler.
|
62
|
62
|
static long acceleration_time, deceleration_time;
|
63
|
63
|
//static unsigned long accelerate_until, decelerate_after, acceleration_rate, initial_rate, final_rate, nominal_rate;
|
|
@@ -156,7 +156,7 @@ asm volatile ( \
|
156
|
156
|
#define DISABLE_STEPPER_DRIVER_INTERRUPT() TIMSK1 &= ~(1<<OCIE1A)
|
157
|
157
|
|
158
|
158
|
|
159
|
|
-void endstops_triggered(const unsigned long &stepstaken)
|
|
159
|
+inline void endstops_triggered(const unsigned long &stepstaken)
|
160
|
160
|
{
|
161
|
161
|
//this will only work if there is no bufferig
|
162
|
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
|
|
@@ -296,9 +296,9 @@ ISR(TIMER1_COMPA_vect)
|
296
|
296
|
counter_z = counter_x;
|
297
|
297
|
counter_e = counter_x;
|
298
|
298
|
step_events_completed = 0;
|
299
|
|
- #ifdef ADVANCE
|
|
299
|
+ // #ifdef ADVANCE
|
300
|
300
|
e_steps = 0;
|
301
|
|
- #endif
|
|
301
|
+// #endif
|
302
|
302
|
}
|
303
|
303
|
else {
|
304
|
304
|
// DISABLE_STEPPER_DRIVER_INTERRUPT();
|
|
@@ -309,29 +309,6 @@ ISR(TIMER1_COMPA_vect)
|
309
|
309
|
// Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt
|
310
|
310
|
out_bits = current_block->direction_bits;
|
311
|
311
|
|
312
|
|
- #ifdef ADVANCE
|
313
|
|
- // Calculate E early.
|
314
|
|
- counter_e += current_block->steps_e;
|
315
|
|
- if (counter_e > 0) {
|
316
|
|
- counter_e -= current_block->step_event_count;
|
317
|
|
- if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
|
318
|
|
- CRITICAL_SECTION_START;
|
319
|
|
- e_steps--;
|
320
|
|
- CRITICAL_SECTION_END;
|
321
|
|
- }
|
322
|
|
- else {
|
323
|
|
- CRITICAL_SECTION_START;
|
324
|
|
- e_steps++;
|
325
|
|
- CRITICAL_SECTION_END;
|
326
|
|
- }
|
327
|
|
- }
|
328
|
|
- // Do E steps + advance steps
|
329
|
|
- CRITICAL_SECTION_START;
|
330
|
|
- e_steps += ((advance >> 16) - old_advance);
|
331
|
|
- CRITICAL_SECTION_END;
|
332
|
|
- old_advance = advance >> 16;
|
333
|
|
- #endif //ADVANCE
|
334
|
|
-
|
335
|
312
|
// Set direction en check limit switches
|
336
|
313
|
if ((out_bits & (1<<X_AXIS)) != 0) { // -direction
|
337
|
314
|
WRITE(X_DIR_PIN, INVERT_X_DIR);
|
|
@@ -339,10 +316,10 @@ ISR(TIMER1_COMPA_vect)
|
339
|
316
|
count_direction[X_AXIS]=-1;
|
340
|
317
|
#endif
|
341
|
318
|
#if X_MIN_PIN > -1
|
342
|
|
- if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) {
|
343
|
|
- // endstops_triggered(step_events_completed);
|
344
|
|
- step_events_completed = current_block->step_event_count;
|
345
|
|
- }
|
|
319
|
+ if(READ(X_MIN_PIN) != ENDSTOPS_INVERTING) {
|
|
320
|
+ // endstops_triggered(step_events_completed);
|
|
321
|
+ step_events_completed = current_block->step_event_count;
|
|
322
|
+ }
|
346
|
323
|
#endif
|
347
|
324
|
}
|
348
|
325
|
else { // +direction
|
|
@@ -355,7 +332,7 @@ ISR(TIMER1_COMPA_vect)
|
355
|
332
|
// endstops_triggered(step_events_completed);
|
356
|
333
|
step_events_completed = current_block->step_event_count;
|
357
|
334
|
}
|
358
|
|
- #endif
|
|
335
|
+ #endif
|
359
|
336
|
}
|
360
|
337
|
|
361
|
338
|
if ((out_bits & (1<<Y_AXIS)) != 0) { // -direction
|
|
@@ -365,7 +342,7 @@ ISR(TIMER1_COMPA_vect)
|
365
|
342
|
#endif
|
366
|
343
|
#if Y_MIN_PIN > -1
|
367
|
344
|
if(READ(Y_MIN_PIN) != ENDSTOPS_INVERTING) {
|
368
|
|
- // endstops_triggered(step_events_completed);
|
|
345
|
+// endstops_triggered(step_events_completed);
|
369
|
346
|
step_events_completed = current_block->step_event_count;
|
370
|
347
|
}
|
371
|
348
|
#endif
|
|
@@ -390,7 +367,7 @@ ISR(TIMER1_COMPA_vect)
|
390
|
367
|
#endif
|
391
|
368
|
#if Z_MIN_PIN > -1
|
392
|
369
|
if(READ(Z_MIN_PIN) != ENDSTOPS_INVERTING) {
|
393
|
|
- endstops_triggered(step_events_completed);
|
|
370
|
+ // endstops_triggered(step_events_completed);
|
394
|
371
|
step_events_completed = current_block->step_event_count;
|
395
|
372
|
}
|
396
|
373
|
#endif
|
|
@@ -416,6 +393,30 @@ ISR(TIMER1_COMPA_vect)
|
416
|
393
|
#endif //!ADVANCE
|
417
|
394
|
|
418
|
395
|
for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)
|
|
396
|
+ /*
|
|
397
|
+ counter_e += current_block->steps_e;
|
|
398
|
+ if (counter_e > 0) {
|
|
399
|
+ counter_e -= current_block->step_event_count;
|
|
400
|
+ if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
|
|
401
|
+ CRITICAL_SECTION_START;
|
|
402
|
+ e_steps--;
|
|
403
|
+ CRITICAL_SECTION_END;
|
|
404
|
+ }
|
|
405
|
+ else {
|
|
406
|
+ CRITICAL_SECTION_START;
|
|
407
|
+ e_steps++;
|
|
408
|
+ CRITICAL_SECTION_END;
|
|
409
|
+ }
|
|
410
|
+ }
|
|
411
|
+ */
|
|
412
|
+ /*
|
|
413
|
+ // Do E steps + advance steps
|
|
414
|
+ CRITICAL_SECTION_START;
|
|
415
|
+ e_steps += ((advance >> 16) - old_advance);
|
|
416
|
+ CRITICAL_SECTION_END;
|
|
417
|
+ old_advance = advance >> 16;
|
|
418
|
+ */
|
|
419
|
+
|
419
|
420
|
counter_x += current_block->steps_x;
|
420
|
421
|
if (counter_x > 0) {
|
421
|
422
|
WRITE(X_STEP_PIN, HIGH);
|
|
@@ -649,7 +650,8 @@ void st_init()
|
649
|
650
|
TCCR1B = (TCCR1B & ~(0x07<<CS10)) | (2<<CS10); // 2MHz timer
|
650
|
651
|
|
651
|
652
|
OCR1A = 0x4000;
|
652
|
|
- DISABLE_STEPPER_DRIVER_INTERRUPT();
|
|
653
|
+ TCNT1 = 0;
|
|
654
|
+ ENABLE_STEPPER_DRIVER_INTERRUPT();
|
653
|
655
|
|
654
|
656
|
#ifdef ADVANCE
|
655
|
657
|
e_steps = 0;
|