|
@@ -55,9 +55,9 @@ static long counter_x, // Counter variables for the bresenham line tracer
|
55
|
55
|
volatile static unsigned long step_events_completed; // The number of step events executed in the current block
|
56
|
56
|
#ifdef ADVANCE
|
57
|
57
|
static long advance_rate, advance, final_advance = 0;
|
58
|
|
- static short old_advance = 0;
|
|
58
|
+ static long old_advance = 0;
|
59
|
59
|
#endif
|
60
|
|
-static short e_steps;
|
|
60
|
+static long 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;
|
|
@@ -253,6 +253,9 @@ FORCE_INLINE void trapezoid_generator_reset() {
|
253
|
253
|
#ifdef ADVANCE
|
254
|
254
|
advance = current_block->initial_advance;
|
255
|
255
|
final_advance = current_block->final_advance;
|
|
256
|
+ // Do E steps + advance steps
|
|
257
|
+ e_steps += ((advance >>8) - old_advance);
|
|
258
|
+ old_advance = advance >>8;
|
256
|
259
|
#endif
|
257
|
260
|
deceleration_time = 0;
|
258
|
261
|
// step_rate to timer interval
|
|
@@ -260,6 +263,17 @@ FORCE_INLINE void trapezoid_generator_reset() {
|
260
|
263
|
acceleration_time = calc_timer(acc_step_rate);
|
261
|
264
|
OCR1A = acceleration_time;
|
262
|
265
|
OCR1A_nominal = calc_timer(current_block->nominal_rate);
|
|
266
|
+
|
|
267
|
+// SERIAL_ECHO_START;
|
|
268
|
+// SERIAL_ECHOPGM("advance :");
|
|
269
|
+// SERIAL_ECHO(current_block->advance/256.0);
|
|
270
|
+// SERIAL_ECHOPGM("advance rate :");
|
|
271
|
+// SERIAL_ECHO(current_block->advance_rate/256.0);
|
|
272
|
+// SERIAL_ECHOPGM("initial advance :");
|
|
273
|
+// SERIAL_ECHO(current_block->initial_advance/256.0);
|
|
274
|
+// SERIAL_ECHOPGM("final advance :");
|
|
275
|
+// SERIAL_ECHOLN(current_block->final_advance/256.0);
|
|
276
|
+
|
263
|
277
|
}
|
264
|
278
|
|
265
|
279
|
// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.
|
|
@@ -382,6 +396,9 @@ ISR(TIMER1_COMPA_vect)
|
382
|
396
|
count_direction[E_AXIS]=-1;
|
383
|
397
|
}
|
384
|
398
|
#endif //!ADVANCE
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
385
|
402
|
for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)
|
386
|
403
|
MSerial.checkRx(); // Check for serial chars.
|
387
|
404
|
|
|
@@ -390,19 +407,12 @@ ISR(TIMER1_COMPA_vect)
|
390
|
407
|
if (counter_e > 0) {
|
391
|
408
|
counter_e -= current_block->step_event_count;
|
392
|
409
|
if ((out_bits & (1<<E_AXIS)) != 0) { // - direction
|
393
|
|
- CRITICAL_SECTION_START;
|
394
|
410
|
e_steps--;
|
395
|
|
- CRITICAL_SECTION_END;
|
396
|
411
|
}
|
397
|
412
|
else {
|
398
|
|
- CRITICAL_SECTION_START;
|
399
|
413
|
e_steps++;
|
400
|
|
- CRITICAL_SECTION_END;
|
401
|
414
|
}
|
402
|
415
|
}
|
403
|
|
- // Do E steps + advance steps
|
404
|
|
- e_steps += ((advance >> 16) - old_advance);
|
405
|
|
- old_advance = advance >> 16;
|
406
|
416
|
#endif //ADVANCE
|
407
|
417
|
|
408
|
418
|
counter_x += current_block->steps_x;
|
|
@@ -461,6 +471,11 @@ ISR(TIMER1_COMPA_vect)
|
461
|
471
|
for(int8_t i=0; i < step_loops; i++) {
|
462
|
472
|
advance += advance_rate;
|
463
|
473
|
}
|
|
474
|
+ //if(advance > current_block->advance) advance = current_block->advance;
|
|
475
|
+ // Do E steps + advance steps
|
|
476
|
+ e_steps += ((advance >>8) - old_advance);
|
|
477
|
+ old_advance = advance >>8;
|
|
478
|
+
|
464
|
479
|
#endif
|
465
|
480
|
}
|
466
|
481
|
else if (step_events_completed > current_block->decelerate_after) {
|
|
@@ -485,8 +500,10 @@ ISR(TIMER1_COMPA_vect)
|
485
|
500
|
for(int8_t i=0; i < step_loops; i++) {
|
486
|
501
|
advance -= advance_rate;
|
487
|
502
|
}
|
488
|
|
- if(advance < final_advance)
|
489
|
|
- advance = final_advance;
|
|
503
|
+ if(advance < final_advance) advance = final_advance;
|
|
504
|
+ // Do E steps + advance steps
|
|
505
|
+ e_steps += ((advance >>8) - old_advance);
|
|
506
|
+ old_advance = advance >>8;
|
490
|
507
|
#endif //ADVANCE
|
491
|
508
|
}
|
492
|
509
|
else {
|
|
@@ -507,7 +524,7 @@ ISR(TIMER1_COMPA_vect)
|
507
|
524
|
// Timer 0 is shared with millies
|
508
|
525
|
ISR(TIMER0_COMPA_vect)
|
509
|
526
|
{
|
510
|
|
- old_OCR0A += 25; // ~10kHz interrupt
|
|
527
|
+ old_OCR0A += 52; // ~10kHz interrupt (250000 / 26 = 9615kHz)
|
511
|
528
|
OCR0A = old_OCR0A;
|
512
|
529
|
// Set E direction (Depends on E direction + advance)
|
513
|
530
|
for(unsigned char i=0; i<4;) {
|
|
@@ -519,7 +536,7 @@ ISR(TIMER1_COMPA_vect)
|
519
|
536
|
e_steps++;
|
520
|
537
|
WRITE(E_STEP_PIN, HIGH);
|
521
|
538
|
}
|
522
|
|
- if (e_steps > 0) {
|
|
539
|
+ else if (e_steps > 0) {
|
523
|
540
|
WRITE(E_DIR_PIN,!INVERT_E_DIR);
|
524
|
541
|
e_steps--;
|
525
|
542
|
WRITE(E_STEP_PIN, HIGH);
|