|
@@ -48,8 +48,8 @@ block_t *current_block; // A pointer to the block currently being traced
|
48
|
48
|
// Variables used by The Stepper Driver Interrupt
|
49
|
49
|
static unsigned char out_bits; // The next stepping-bits to be output
|
50
|
50
|
static long counter_x, // Counter variables for the bresenham line tracer
|
51
|
|
- counter_y,
|
52
|
|
- counter_z,
|
|
51
|
+ counter_y,
|
|
52
|
+ counter_z,
|
53
|
53
|
counter_e;
|
54
|
54
|
volatile static unsigned long step_events_completed; // The number of step events executed in the current block
|
55
|
55
|
#ifdef ADVANCE
|
|
@@ -224,27 +224,27 @@ void enable_endstops(bool check)
|
224
|
224
|
// | BLOCK 1 | BLOCK 2 | d
|
225
|
225
|
//
|
226
|
226
|
// time ----->
|
227
|
|
-//
|
228
|
|
-// The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
|
229
|
|
-// first block->accelerate_until step_events_completed, then keeps going at constant speed until
|
|
227
|
+//
|
|
228
|
+// The trapezoid is the shape the speed curve over time. It starts at block->initial_rate, accelerates
|
|
229
|
+// first block->accelerate_until step_events_completed, then keeps going at constant speed until
|
230
|
230
|
// step_events_completed reaches block->decelerate_after after which it decelerates until the trapezoid generator is reset.
|
231
|
231
|
// The slope of acceleration is calculated with the leib ramp alghorithm.
|
232
|
232
|
|
233
|
233
|
void st_wake_up() {
|
234
|
234
|
// TCNT1 = 0;
|
235
|
|
- ENABLE_STEPPER_DRIVER_INTERRUPT();
|
|
235
|
+ ENABLE_STEPPER_DRIVER_INTERRUPT();
|
236
|
236
|
}
|
237
|
237
|
|
238
|
238
|
void step_wait(){
|
239
|
239
|
for(int8_t i=0; i < 6; i++){
|
240
|
240
|
}
|
241
|
241
|
}
|
242
|
|
-
|
|
242
|
+
|
243
|
243
|
|
244
|
244
|
FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
|
245
|
245
|
unsigned short timer;
|
246
|
246
|
if(step_rate > MAX_STEP_FREQUENCY) step_rate = MAX_STEP_FREQUENCY;
|
247
|
|
-
|
|
247
|
+
|
248
|
248
|
if(step_rate > 20000) { // If steprate > 20kHz >> step 4 times
|
249
|
249
|
step_rate = (step_rate >> 2)&0x3fff;
|
250
|
250
|
step_loops = 4;
|
|
@@ -255,11 +255,11 @@ FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
|
255
|
255
|
}
|
256
|
256
|
else {
|
257
|
257
|
step_loops = 1;
|
258
|
|
- }
|
259
|
|
-
|
|
258
|
+ }
|
|
259
|
+
|
260
|
260
|
if(step_rate < (F_CPU/500000)) step_rate = (F_CPU/500000);
|
261
|
261
|
step_rate -= (F_CPU/500000); // Correct for minimal speed
|
262
|
|
- if(step_rate >= (8*256)){ // higher step rate
|
|
262
|
+ if(step_rate >= (8*256)){ // higher step rate
|
263
|
263
|
unsigned short table_address = (unsigned short)&speed_lookuptable_fast[(unsigned char)(step_rate>>8)][0];
|
264
|
264
|
unsigned char tmp_step_rate = (step_rate & 0x00ff);
|
265
|
265
|
unsigned short gain = (unsigned short)pgm_read_word_near(table_address+2);
|
|
@@ -276,7 +276,7 @@ FORCE_INLINE unsigned short calc_timer(unsigned short step_rate) {
|
276
|
276
|
return timer;
|
277
|
277
|
}
|
278
|
278
|
|
279
|
|
-// Initializes the trapezoid generator from the current block. Called whenever a new
|
|
279
|
+// Initializes the trapezoid generator from the current block. Called whenever a new
|
280
|
280
|
// block begins.
|
281
|
281
|
FORCE_INLINE void trapezoid_generator_reset() {
|
282
|
282
|
#ifdef ADVANCE
|
|
@@ -284,7 +284,7 @@ FORCE_INLINE void trapezoid_generator_reset() {
|
284
|
284
|
final_advance = current_block->final_advance;
|
285
|
285
|
// Do E steps + advance steps
|
286
|
286
|
e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
|
287
|
|
- old_advance = advance >>8;
|
|
287
|
+ old_advance = advance >>8;
|
288
|
288
|
#endif
|
289
|
289
|
deceleration_time = 0;
|
290
|
290
|
// step_rate to timer interval
|
|
@@ -294,7 +294,7 @@ FORCE_INLINE void trapezoid_generator_reset() {
|
294
|
294
|
acc_step_rate = current_block->initial_rate;
|
295
|
295
|
acceleration_time = calc_timer(acc_step_rate);
|
296
|
296
|
OCR1A = acceleration_time;
|
297
|
|
-
|
|
297
|
+
|
298
|
298
|
// SERIAL_ECHO_START;
|
299
|
299
|
// SERIAL_ECHOPGM("advance :");
|
300
|
300
|
// SERIAL_ECHO(current_block->advance/256.0);
|
|
@@ -304,13 +304,13 @@ FORCE_INLINE void trapezoid_generator_reset() {
|
304
|
304
|
// SERIAL_ECHO(current_block->initial_advance/256.0);
|
305
|
305
|
// SERIAL_ECHOPGM("final advance :");
|
306
|
306
|
// SERIAL_ECHOLN(current_block->final_advance/256.0);
|
307
|
|
-
|
|
307
|
+
|
308
|
308
|
}
|
309
|
309
|
|
310
|
|
-// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.
|
311
|
|
-// It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
|
|
310
|
+// "The Stepper Driver Interrupt" - This timer interrupt is the workhorse.
|
|
311
|
+// It pops blocks from the block_buffer and executes them by pulsing the stepper pins appropriately.
|
312
|
312
|
ISR(TIMER1_COMPA_vect)
|
313
|
|
-{
|
|
313
|
+{
|
314
|
314
|
// If there is no current block, attempt to pop one from the buffer
|
315
|
315
|
if (current_block == NULL) {
|
316
|
316
|
// Anything in the buffer?
|
|
@@ -322,24 +322,24 @@ ISR(TIMER1_COMPA_vect)
|
322
|
322
|
counter_y = counter_x;
|
323
|
323
|
counter_z = counter_x;
|
324
|
324
|
counter_e = counter_x;
|
325
|
|
- step_events_completed = 0;
|
326
|
|
-
|
327
|
|
- #ifdef Z_LATE_ENABLE
|
|
325
|
+ step_events_completed = 0;
|
|
326
|
+
|
|
327
|
+ #ifdef Z_LATE_ENABLE
|
328
|
328
|
if(current_block->steps_z > 0) {
|
329
|
329
|
enable_z();
|
330
|
330
|
OCR1A = 2000; //1ms wait
|
331
|
331
|
return;
|
332
|
332
|
}
|
333
|
333
|
#endif
|
334
|
|
-
|
|
334
|
+
|
335
|
335
|
// #ifdef ADVANCE
|
336
|
336
|
// e_steps[current_block->active_extruder] = 0;
|
337
|
337
|
// #endif
|
338
|
|
- }
|
|
338
|
+ }
|
339
|
339
|
else {
|
340
|
340
|
OCR1A=2000; // 1kHz.
|
341
|
|
- }
|
342
|
|
- }
|
|
341
|
+ }
|
|
342
|
+ }
|
343
|
343
|
|
344
|
344
|
if (current_block != NULL) {
|
345
|
345
|
// Set directions TO DO This should be done once during init of trapezoid. Endstops -> interrupt
|
|
@@ -352,7 +352,7 @@ ISR(TIMER1_COMPA_vect)
|
352
|
352
|
if (active_extruder != 0)
|
353
|
353
|
WRITE(X2_DIR_PIN,INVERT_X_DIR);
|
354
|
354
|
else
|
355
|
|
- #endif
|
|
355
|
+ #endif
|
356
|
356
|
WRITE(X_DIR_PIN, INVERT_X_DIR);
|
357
|
357
|
count_direction[X_AXIS]=-1;
|
358
|
358
|
}
|
|
@@ -361,7 +361,7 @@ ISR(TIMER1_COMPA_vect)
|
361
|
361
|
if (active_extruder != 0)
|
362
|
362
|
WRITE(X2_DIR_PIN,!INVERT_X_DIR);
|
363
|
363
|
else
|
364
|
|
- #endif
|
|
364
|
+ #endif
|
365
|
365
|
WRITE(X_DIR_PIN, !INVERT_X_DIR);
|
366
|
366
|
count_direction[X_AXIS]=1;
|
367
|
367
|
}
|
|
@@ -373,7 +373,7 @@ ISR(TIMER1_COMPA_vect)
|
373
|
373
|
WRITE(Y_DIR_PIN, !INVERT_Y_DIR);
|
374
|
374
|
count_direction[Y_AXIS]=1;
|
375
|
375
|
}
|
376
|
|
-
|
|
376
|
+
|
377
|
377
|
// Set direction en check limit switches
|
378
|
378
|
#ifndef COREXY
|
379
|
379
|
if ((out_bits & (1<<X_AXIS)) != 0) { // stepping along -X axis
|
|
@@ -385,10 +385,10 @@ ISR(TIMER1_COMPA_vect)
|
385
|
385
|
#ifdef DUAL_X_CARRIAGE
|
386
|
386
|
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
387
|
387
|
if ((active_extruder == 0 && X_HOME_DIR == -1) || (active_extruder != 0 && X2_HOME_DIR == -1))
|
388
|
|
- #endif
|
|
388
|
+ #endif
|
389
|
389
|
{
|
390
|
390
|
#if defined(X_MIN_PIN) && X_MIN_PIN > -1
|
391
|
|
- bool x_min_endstop=(READ(X_MIN_PIN) != X_ENDSTOPS_INVERTING);
|
|
391
|
+ bool x_min_endstop=(READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING);
|
392
|
392
|
if(x_min_endstop && old_x_min_endstop && (current_block->steps_x > 0)) {
|
393
|
393
|
endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
394
|
394
|
endstop_x_hit=true;
|
|
@@ -400,15 +400,15 @@ ISR(TIMER1_COMPA_vect)
|
400
|
400
|
}
|
401
|
401
|
}
|
402
|
402
|
else { // +direction
|
403
|
|
- CHECK_ENDSTOPS
|
|
403
|
+ CHECK_ENDSTOPS
|
404
|
404
|
{
|
405
|
405
|
#ifdef DUAL_X_CARRIAGE
|
406
|
406
|
// with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
407
|
407
|
if ((active_extruder == 0 && X_HOME_DIR == 1) || (active_extruder != 0 && X2_HOME_DIR == 1))
|
408
|
|
- #endif
|
|
408
|
+ #endif
|
409
|
409
|
{
|
410
|
410
|
#if defined(X_MAX_PIN) && X_MAX_PIN > -1
|
411
|
|
- bool x_max_endstop=(READ(X_MAX_PIN) != X_ENDSTOPS_INVERTING);
|
|
411
|
+ bool x_max_endstop=(READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING);
|
412
|
412
|
if(x_max_endstop && old_x_max_endstop && (current_block->steps_x > 0)){
|
413
|
413
|
endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
414
|
414
|
endstop_x_hit=true;
|
|
@@ -416,7 +416,7 @@ ISR(TIMER1_COMPA_vect)
|
416
|
416
|
}
|
417
|
417
|
old_x_max_endstop = x_max_endstop;
|
418
|
418
|
#endif
|
419
|
|
- }
|
|
419
|
+ }
|
420
|
420
|
}
|
421
|
421
|
}
|
422
|
422
|
|
|
@@ -428,7 +428,7 @@ ISR(TIMER1_COMPA_vect)
|
428
|
428
|
CHECK_ENDSTOPS
|
429
|
429
|
{
|
430
|
430
|
#if defined(Y_MIN_PIN) && Y_MIN_PIN > -1
|
431
|
|
- bool y_min_endstop=(READ(Y_MIN_PIN) != Y_ENDSTOPS_INVERTING);
|
|
431
|
+ bool y_min_endstop=(READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING);
|
432
|
432
|
if(y_min_endstop && old_y_min_endstop && (current_block->steps_y > 0)) {
|
433
|
433
|
endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
|
434
|
434
|
endstop_y_hit=true;
|
|
@@ -442,7 +442,7 @@ ISR(TIMER1_COMPA_vect)
|
442
|
442
|
CHECK_ENDSTOPS
|
443
|
443
|
{
|
444
|
444
|
#if defined(Y_MAX_PIN) && Y_MAX_PIN > -1
|
445
|
|
- bool y_max_endstop=(READ(Y_MAX_PIN) != Y_ENDSTOPS_INVERTING);
|
|
445
|
+ bool y_max_endstop=(READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING);
|
446
|
446
|
if(y_max_endstop && old_y_max_endstop && (current_block->steps_y > 0)){
|
447
|
447
|
endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
|
448
|
448
|
endstop_y_hit=true;
|
|
@@ -455,16 +455,16 @@ ISR(TIMER1_COMPA_vect)
|
455
|
455
|
|
456
|
456
|
if ((out_bits & (1<<Z_AXIS)) != 0) { // -direction
|
457
|
457
|
WRITE(Z_DIR_PIN,INVERT_Z_DIR);
|
458
|
|
-
|
|
458
|
+
|
459
|
459
|
#ifdef Z_DUAL_STEPPER_DRIVERS
|
460
|
460
|
WRITE(Z2_DIR_PIN,INVERT_Z_DIR);
|
461
|
461
|
#endif
|
462
|
|
-
|
|
462
|
+
|
463
|
463
|
count_direction[Z_AXIS]=-1;
|
464
|
464
|
CHECK_ENDSTOPS
|
465
|
465
|
{
|
466
|
466
|
#if defined(Z_MIN_PIN) && Z_MIN_PIN > -1
|
467
|
|
- bool z_min_endstop=(READ(Z_MIN_PIN) != Z_ENDSTOPS_INVERTING);
|
|
467
|
+ bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
|
468
|
468
|
if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) {
|
469
|
469
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
470
|
470
|
endstop_z_hit=true;
|
|
@@ -485,7 +485,7 @@ ISR(TIMER1_COMPA_vect)
|
485
|
485
|
CHECK_ENDSTOPS
|
486
|
486
|
{
|
487
|
487
|
#if defined(Z_MAX_PIN) && Z_MAX_PIN > -1
|
488
|
|
- bool z_max_endstop=(READ(Z_MAX_PIN) != Z_ENDSTOPS_INVERTING);
|
|
488
|
+ bool z_max_endstop=(READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING);
|
489
|
489
|
if(z_max_endstop && old_z_max_endstop && (current_block->steps_z > 0)) {
|
490
|
490
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
491
|
491
|
endstop_z_hit=true;
|
|
@@ -506,10 +506,10 @@ ISR(TIMER1_COMPA_vect)
|
506
|
506
|
count_direction[E_AXIS]=1;
|
507
|
507
|
}
|
508
|
508
|
#endif //!ADVANCE
|
509
|
|
-
|
510
|
509
|
|
511
|
|
-
|
512
|
|
- for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+ for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)
|
513
|
513
|
#ifndef AT90USB
|
514
|
514
|
MSerial.checkRx(); // Check for serial chars.
|
515
|
515
|
#endif
|
|
@@ -524,7 +524,7 @@ ISR(TIMER1_COMPA_vect)
|
524
|
524
|
else {
|
525
|
525
|
e_steps[current_block->active_extruder]++;
|
526
|
526
|
}
|
527
|
|
- }
|
|
527
|
+ }
|
528
|
528
|
#endif //ADVANCE
|
529
|
529
|
|
530
|
530
|
counter_x += current_block->steps_x;
|
|
@@ -533,38 +533,38 @@ ISR(TIMER1_COMPA_vect)
|
533
|
533
|
if (active_extruder != 0)
|
534
|
534
|
WRITE(X2_STEP_PIN,!INVERT_X_STEP_PIN);
|
535
|
535
|
else
|
536
|
|
- #endif
|
|
536
|
+ #endif
|
537
|
537
|
WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
|
538
|
538
|
counter_x -= current_block->step_event_count;
|
539
|
|
- count_position[X_AXIS]+=count_direction[X_AXIS];
|
|
539
|
+ count_position[X_AXIS]+=count_direction[X_AXIS];
|
540
|
540
|
#ifdef DUAL_X_CARRIAGE
|
541
|
541
|
if (active_extruder != 0)
|
542
|
542
|
WRITE(X2_STEP_PIN,INVERT_X_STEP_PIN);
|
543
|
543
|
else
|
544
|
|
- #endif
|
|
544
|
+ #endif
|
545
|
545
|
WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
|
546
|
546
|
}
|
547
|
|
-
|
|
547
|
+
|
548
|
548
|
counter_y += current_block->steps_y;
|
549
|
549
|
if (counter_y > 0) {
|
550
|
550
|
WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
|
551
|
|
- counter_y -= current_block->step_event_count;
|
552
|
|
- count_position[Y_AXIS]+=count_direction[Y_AXIS];
|
|
551
|
+ counter_y -= current_block->step_event_count;
|
|
552
|
+ count_position[Y_AXIS]+=count_direction[Y_AXIS];
|
553
|
553
|
WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
|
554
|
554
|
}
|
555
|
|
-
|
|
555
|
+
|
556
|
556
|
counter_z += current_block->steps_z;
|
557
|
557
|
if (counter_z > 0) {
|
558
|
558
|
WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
|
559
|
|
-
|
|
559
|
+
|
560
|
560
|
#ifdef Z_DUAL_STEPPER_DRIVERS
|
561
|
561
|
WRITE(Z2_STEP_PIN, !INVERT_Z_STEP_PIN);
|
562
|
562
|
#endif
|
563
|
|
-
|
|
563
|
+
|
564
|
564
|
counter_z -= current_block->step_event_count;
|
565
|
565
|
count_position[Z_AXIS]+=count_direction[Z_AXIS];
|
566
|
566
|
WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN);
|
567
|
|
-
|
|
567
|
+
|
568
|
568
|
#ifdef Z_DUAL_STEPPER_DRIVERS
|
569
|
569
|
WRITE(Z2_STEP_PIN, INVERT_Z_STEP_PIN);
|
570
|
570
|
#endif
|
|
@@ -579,17 +579,17 @@ ISR(TIMER1_COMPA_vect)
|
579
|
579
|
WRITE_E_STEP(INVERT_E_STEP_PIN);
|
580
|
580
|
}
|
581
|
581
|
#endif //!ADVANCE
|
582
|
|
- step_events_completed += 1;
|
|
582
|
+ step_events_completed += 1;
|
583
|
583
|
if(step_events_completed >= current_block->step_event_count) break;
|
584
|
584
|
}
|
585
|
585
|
// Calculare new timer value
|
586
|
586
|
unsigned short timer;
|
587
|
587
|
unsigned short step_rate;
|
588
|
588
|
if (step_events_completed <= (unsigned long int)current_block->accelerate_until) {
|
589
|
|
-
|
|
589
|
+
|
590
|
590
|
MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
|
591
|
591
|
acc_step_rate += current_block->initial_rate;
|
592
|
|
-
|
|
592
|
+
|
593
|
593
|
// upper limit
|
594
|
594
|
if(acc_step_rate > current_block->nominal_rate)
|
595
|
595
|
acc_step_rate = current_block->nominal_rate;
|
|
@@ -605,13 +605,13 @@ ISR(TIMER1_COMPA_vect)
|
605
|
605
|
//if(advance > current_block->advance) advance = current_block->advance;
|
606
|
606
|
// Do E steps + advance steps
|
607
|
607
|
e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
|
608
|
|
- old_advance = advance >>8;
|
609
|
|
-
|
|
608
|
+ old_advance = advance >>8;
|
|
609
|
+
|
610
|
610
|
#endif
|
611
|
|
- }
|
612
|
|
- else if (step_events_completed > (unsigned long int)current_block->decelerate_after) {
|
|
611
|
+ }
|
|
612
|
+ else if (step_events_completed > (unsigned long int)current_block->decelerate_after) {
|
613
|
613
|
MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate);
|
614
|
|
-
|
|
614
|
+
|
615
|
615
|
if(step_rate > acc_step_rate) { // Check step_rate stays positive
|
616
|
616
|
step_rate = current_block->final_rate;
|
617
|
617
|
}
|
|
@@ -634,7 +634,7 @@ ISR(TIMER1_COMPA_vect)
|
634
|
634
|
if(advance < final_advance) advance = final_advance;
|
635
|
635
|
// Do E steps + advance steps
|
636
|
636
|
e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
|
637
|
|
- old_advance = advance >>8;
|
|
637
|
+ old_advance = advance >>8;
|
638
|
638
|
#endif //ADVANCE
|
639
|
639
|
}
|
640
|
640
|
else {
|
|
@@ -643,12 +643,12 @@ ISR(TIMER1_COMPA_vect)
|
643
|
643
|
step_loops = step_loops_nominal;
|
644
|
644
|
}
|
645
|
645
|
|
646
|
|
- // If current block is finished, reset pointer
|
|
646
|
+ // If current block is finished, reset pointer
|
647
|
647
|
if (step_events_completed >= current_block->step_event_count) {
|
648
|
648
|
current_block = NULL;
|
649
|
649
|
plan_discard_current_block();
|
650
|
|
- }
|
651
|
|
- }
|
|
650
|
+ }
|
|
651
|
+ }
|
652
|
652
|
}
|
653
|
653
|
|
654
|
654
|
#ifdef ADVANCE
|
|
@@ -667,7 +667,7 @@ ISR(TIMER1_COMPA_vect)
|
667
|
667
|
WRITE(E0_DIR_PIN, INVERT_E0_DIR);
|
668
|
668
|
e_steps[0]++;
|
669
|
669
|
WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN);
|
670
|
|
- }
|
|
670
|
+ }
|
671
|
671
|
else if (e_steps[0] > 0) {
|
672
|
672
|
WRITE(E0_DIR_PIN, !INVERT_E0_DIR);
|
673
|
673
|
e_steps[0]--;
|
|
@@ -681,7 +681,7 @@ ISR(TIMER1_COMPA_vect)
|
681
|
681
|
WRITE(E1_DIR_PIN, INVERT_E1_DIR);
|
682
|
682
|
e_steps[1]++;
|
683
|
683
|
WRITE(E1_STEP_PIN, !INVERT_E_STEP_PIN);
|
684
|
|
- }
|
|
684
|
+ }
|
685
|
685
|
else if (e_steps[1] > 0) {
|
686
|
686
|
WRITE(E1_DIR_PIN, !INVERT_E1_DIR);
|
687
|
687
|
e_steps[1]--;
|
|
@@ -696,7 +696,7 @@ ISR(TIMER1_COMPA_vect)
|
696
|
696
|
WRITE(E2_DIR_PIN, INVERT_E2_DIR);
|
697
|
697
|
e_steps[2]++;
|
698
|
698
|
WRITE(E2_STEP_PIN, !INVERT_E_STEP_PIN);
|
699
|
|
- }
|
|
699
|
+ }
|
700
|
700
|
else if (e_steps[2] > 0) {
|
701
|
701
|
WRITE(E2_DIR_PIN, !INVERT_E2_DIR);
|
702
|
702
|
e_steps[2]--;
|
|
@@ -712,7 +712,7 @@ void st_init()
|
712
|
712
|
{
|
713
|
713
|
digipot_init(); //Initialize Digipot Motor Current
|
714
|
714
|
microstep_init(); //Initialize Microstepping Pins
|
715
|
|
-
|
|
715
|
+
|
716
|
716
|
//Initialize Dir Pins
|
717
|
717
|
#if defined(X_DIR_PIN) && X_DIR_PIN > -1
|
718
|
718
|
SET_OUTPUT(X_DIR_PIN);
|
|
@@ -720,17 +720,17 @@ void st_init()
|
720
|
720
|
#if defined(X2_DIR_PIN) && X2_DIR_PIN > -1
|
721
|
721
|
SET_OUTPUT(X2_DIR_PIN);
|
722
|
722
|
#endif
|
723
|
|
- #if defined(Y_DIR_PIN) && Y_DIR_PIN > -1
|
|
723
|
+ #if defined(Y_DIR_PIN) && Y_DIR_PIN > -1
|
724
|
724
|
SET_OUTPUT(Y_DIR_PIN);
|
725
|
725
|
#endif
|
726
|
|
- #if defined(Z_DIR_PIN) && Z_DIR_PIN > -1
|
|
726
|
+ #if defined(Z_DIR_PIN) && Z_DIR_PIN > -1
|
727
|
727
|
SET_OUTPUT(Z_DIR_PIN);
|
728
|
728
|
|
729
|
729
|
#if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_DIR_PIN) && (Z2_DIR_PIN > -1)
|
730
|
730
|
SET_OUTPUT(Z2_DIR_PIN);
|
731
|
731
|
#endif
|
732
|
732
|
#endif
|
733
|
|
- #if defined(E0_DIR_PIN) && E0_DIR_PIN > -1
|
|
733
|
+ #if defined(E0_DIR_PIN) && E0_DIR_PIN > -1
|
734
|
734
|
SET_OUTPUT(E0_DIR_PIN);
|
735
|
735
|
#endif
|
736
|
736
|
#if defined(E1_DIR_PIN) && (E1_DIR_PIN > -1)
|
|
@@ -757,7 +757,7 @@ void st_init()
|
757
|
757
|
#if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1
|
758
|
758
|
SET_OUTPUT(Z_ENABLE_PIN);
|
759
|
759
|
if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
|
760
|
|
-
|
|
760
|
+
|
761
|
761
|
#if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_ENABLE_PIN) && (Z2_ENABLE_PIN > -1)
|
762
|
762
|
SET_OUTPUT(Z2_ENABLE_PIN);
|
763
|
763
|
if(!Z_ENABLE_ON) WRITE(Z2_ENABLE_PIN,HIGH);
|
|
@@ -777,67 +777,67 @@ void st_init()
|
777
|
777
|
#endif
|
778
|
778
|
|
779
|
779
|
//endstops and pullups
|
780
|
|
-
|
|
780
|
+
|
781
|
781
|
#if defined(X_MIN_PIN) && X_MIN_PIN > -1
|
782
|
|
- SET_INPUT(X_MIN_PIN);
|
|
782
|
+ SET_INPUT(X_MIN_PIN);
|
783
|
783
|
#ifdef ENDSTOPPULLUP_XMIN
|
784
|
784
|
WRITE(X_MIN_PIN,HIGH);
|
785
|
785
|
#endif
|
786
|
786
|
#endif
|
787
|
|
-
|
|
787
|
+
|
788
|
788
|
#if defined(Y_MIN_PIN) && Y_MIN_PIN > -1
|
789
|
|
- SET_INPUT(Y_MIN_PIN);
|
|
789
|
+ SET_INPUT(Y_MIN_PIN);
|
790
|
790
|
#ifdef ENDSTOPPULLUP_YMIN
|
791
|
791
|
WRITE(Y_MIN_PIN,HIGH);
|
792
|
792
|
#endif
|
793
|
793
|
#endif
|
794
|
|
-
|
|
794
|
+
|
795
|
795
|
#if defined(Z_MIN_PIN) && Z_MIN_PIN > -1
|
796
|
|
- SET_INPUT(Z_MIN_PIN);
|
|
796
|
+ SET_INPUT(Z_MIN_PIN);
|
797
|
797
|
#ifdef ENDSTOPPULLUP_ZMIN
|
798
|
798
|
WRITE(Z_MIN_PIN,HIGH);
|
799
|
799
|
#endif
|
800
|
800
|
#endif
|
801
|
|
-
|
|
801
|
+
|
802
|
802
|
#if defined(X_MAX_PIN) && X_MAX_PIN > -1
|
803
|
|
- SET_INPUT(X_MAX_PIN);
|
|
803
|
+ SET_INPUT(X_MAX_PIN);
|
804
|
804
|
#ifdef ENDSTOPPULLUP_XMAX
|
805
|
805
|
WRITE(X_MAX_PIN,HIGH);
|
806
|
806
|
#endif
|
807
|
807
|
#endif
|
808
|
|
-
|
|
808
|
+
|
809
|
809
|
#if defined(Y_MAX_PIN) && Y_MAX_PIN > -1
|
810
|
|
- SET_INPUT(Y_MAX_PIN);
|
|
810
|
+ SET_INPUT(Y_MAX_PIN);
|
811
|
811
|
#ifdef ENDSTOPPULLUP_YMAX
|
812
|
812
|
WRITE(Y_MAX_PIN,HIGH);
|
813
|
813
|
#endif
|
814
|
814
|
#endif
|
815
|
|
-
|
|
815
|
+
|
816
|
816
|
#if defined(Z_MAX_PIN) && Z_MAX_PIN > -1
|
817
|
|
- SET_INPUT(Z_MAX_PIN);
|
|
817
|
+ SET_INPUT(Z_MAX_PIN);
|
818
|
818
|
#ifdef ENDSTOPPULLUP_ZMAX
|
819
|
819
|
WRITE(Z_MAX_PIN,HIGH);
|
820
|
820
|
#endif
|
821
|
821
|
#endif
|
822
|
|
-
|
|
822
|
+
|
823
|
823
|
|
824
|
824
|
//Initialize Step Pins
|
825
|
|
- #if defined(X_STEP_PIN) && (X_STEP_PIN > -1)
|
|
825
|
+ #if defined(X_STEP_PIN) && (X_STEP_PIN > -1)
|
826
|
826
|
SET_OUTPUT(X_STEP_PIN);
|
827
|
827
|
WRITE(X_STEP_PIN,INVERT_X_STEP_PIN);
|
828
|
828
|
disable_x();
|
829
|
|
- #endif
|
830
|
|
- #if defined(X2_STEP_PIN) && (X2_STEP_PIN > -1)
|
|
829
|
+ #endif
|
|
830
|
+ #if defined(X2_STEP_PIN) && (X2_STEP_PIN > -1)
|
831
|
831
|
SET_OUTPUT(X2_STEP_PIN);
|
832
|
832
|
WRITE(X2_STEP_PIN,INVERT_X_STEP_PIN);
|
833
|
833
|
disable_x();
|
834
|
|
- #endif
|
835
|
|
- #if defined(Y_STEP_PIN) && (Y_STEP_PIN > -1)
|
|
834
|
+ #endif
|
|
835
|
+ #if defined(Y_STEP_PIN) && (Y_STEP_PIN > -1)
|
836
|
836
|
SET_OUTPUT(Y_STEP_PIN);
|
837
|
837
|
WRITE(Y_STEP_PIN,INVERT_Y_STEP_PIN);
|
838
|
838
|
disable_y();
|
839
|
|
- #endif
|
840
|
|
- #if defined(Z_STEP_PIN) && (Z_STEP_PIN > -1)
|
|
839
|
+ #endif
|
|
840
|
+ #if defined(Z_STEP_PIN) && (Z_STEP_PIN > -1)
|
841
|
841
|
SET_OUTPUT(Z_STEP_PIN);
|
842
|
842
|
WRITE(Z_STEP_PIN,INVERT_Z_STEP_PIN);
|
843
|
843
|
#if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_STEP_PIN) && (Z2_STEP_PIN > -1)
|
|
@@ -845,33 +845,33 @@ void st_init()
|
845
|
845
|
WRITE(Z2_STEP_PIN,INVERT_Z_STEP_PIN);
|
846
|
846
|
#endif
|
847
|
847
|
disable_z();
|
848
|
|
- #endif
|
849
|
|
- #if defined(E0_STEP_PIN) && (E0_STEP_PIN > -1)
|
|
848
|
+ #endif
|
|
849
|
+ #if defined(E0_STEP_PIN) && (E0_STEP_PIN > -1)
|
850
|
850
|
SET_OUTPUT(E0_STEP_PIN);
|
851
|
851
|
WRITE(E0_STEP_PIN,INVERT_E_STEP_PIN);
|
852
|
852
|
disable_e0();
|
853
|
|
- #endif
|
854
|
|
- #if defined(E1_STEP_PIN) && (E1_STEP_PIN > -1)
|
|
853
|
+ #endif
|
|
854
|
+ #if defined(E1_STEP_PIN) && (E1_STEP_PIN > -1)
|
855
|
855
|
SET_OUTPUT(E1_STEP_PIN);
|
856
|
856
|
WRITE(E1_STEP_PIN,INVERT_E_STEP_PIN);
|
857
|
857
|
disable_e1();
|
858
|
|
- #endif
|
859
|
|
- #if defined(E2_STEP_PIN) && (E2_STEP_PIN > -1)
|
|
858
|
+ #endif
|
|
859
|
+ #if defined(E2_STEP_PIN) && (E2_STEP_PIN > -1)
|
860
|
860
|
SET_OUTPUT(E2_STEP_PIN);
|
861
|
861
|
WRITE(E2_STEP_PIN,INVERT_E_STEP_PIN);
|
862
|
862
|
disable_e2();
|
863
|
|
- #endif
|
|
863
|
+ #endif
|
864
|
864
|
|
865
|
865
|
// waveform generation = 0100 = CTC
|
866
|
866
|
TCCR1B &= ~(1<<WGM13);
|
867
|
867
|
TCCR1B |= (1<<WGM12);
|
868
|
|
- TCCR1A &= ~(1<<WGM11);
|
|
868
|
+ TCCR1A &= ~(1<<WGM11);
|
869
|
869
|
TCCR1A &= ~(1<<WGM10);
|
870
|
870
|
|
871
|
871
|
// output mode = 00 (disconnected)
|
872
|
|
- TCCR1A &= ~(3<<COM1A0);
|
873
|
|
- TCCR1A &= ~(3<<COM1B0);
|
874
|
|
-
|
|
872
|
+ TCCR1A &= ~(3<<COM1A0);
|
|
873
|
+ TCCR1A &= ~(3<<COM1B0);
|
|
874
|
+
|
875
|
875
|
// Set the timer pre-scaler
|
876
|
876
|
// Generally we use a divider of 8, resulting in a 2MHz timer
|
877
|
877
|
// frequency on a 16MHz MCU. If you are going to change this, be
|
|
@@ -881,19 +881,19 @@ void st_init()
|
881
|
881
|
|
882
|
882
|
OCR1A = 0x4000;
|
883
|
883
|
TCNT1 = 0;
|
884
|
|
- ENABLE_STEPPER_DRIVER_INTERRUPT();
|
|
884
|
+ ENABLE_STEPPER_DRIVER_INTERRUPT();
|
885
|
885
|
|
886
|
886
|
#ifdef ADVANCE
|
887
|
887
|
#if defined(TCCR0A) && defined(WGM01)
|
888
|
888
|
TCCR0A &= ~(1<<WGM01);
|
889
|
889
|
TCCR0A &= ~(1<<WGM00);
|
890
|
|
- #endif
|
|
890
|
+ #endif
|
891
|
891
|
e_steps[0] = 0;
|
892
|
892
|
e_steps[1] = 0;
|
893
|
893
|
e_steps[2] = 0;
|
894
|
894
|
TIMSK0 |= (1<<OCIE0A);
|
895
|
895
|
#endif //ADVANCE
|
896
|
|
-
|
|
896
|
+
|
897
|
897
|
enable_endstops(true); // Start with endstops active. After homing they can be disabled
|
898
|
898
|
sei();
|
899
|
899
|
}
|
|
@@ -937,13 +937,13 @@ long st_get_position(uint8_t axis)
|
937
|
937
|
|
938
|
938
|
void finishAndDisableSteppers()
|
939
|
939
|
{
|
940
|
|
- st_synchronize();
|
941
|
|
- disable_x();
|
942
|
|
- disable_y();
|
943
|
|
- disable_z();
|
944
|
|
- disable_e0();
|
945
|
|
- disable_e1();
|
946
|
|
- disable_e2();
|
|
940
|
+ st_synchronize();
|
|
941
|
+ disable_x();
|
|
942
|
+ disable_y();
|
|
943
|
+ disable_z();
|
|
944
|
+ disable_e0();
|
|
945
|
+ disable_e1();
|
|
946
|
+ disable_e2();
|
947
|
947
|
}
|
948
|
948
|
|
949
|
949
|
void quickStop()
|
|
@@ -970,10 +970,10 @@ void digipot_init() //Initialize Digipot Motor Current
|
970
|
970
|
{
|
971
|
971
|
#if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
|
972
|
972
|
const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT;
|
973
|
|
-
|
974
|
|
- SPI.begin();
|
975
|
|
- pinMode(DIGIPOTSS_PIN, OUTPUT);
|
976
|
|
- for(int i=0;i<=4;i++)
|
|
973
|
+
|
|
974
|
+ SPI.begin();
|
|
975
|
+ pinMode(DIGIPOTSS_PIN, OUTPUT);
|
|
976
|
+ for(int i=0;i<=4;i++)
|
977
|
977
|
//digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
|
978
|
978
|
digipot_current(i,digipot_motor_current[i]);
|
979
|
979
|
#endif
|