|
@@ -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
|
|
@@ -348,58 +348,22 @@ ISR(TIMER1_COMPA_vect)
|
348
|
348
|
|
349
|
349
|
// Set the direction bits (X_AXIS=A_AXIS and Y_AXIS=B_AXIS for COREXY)
|
350
|
350
|
if((out_bits & (1<<X_AXIS))!=0){
|
351
|
|
- #ifdef DUAL_X_CARRIAGE
|
352
|
|
- if (extruder_duplication_enabled){
|
353
|
|
- WRITE(X_DIR_PIN, INVERT_X_DIR);
|
354
|
|
- WRITE(X2_DIR_PIN, INVERT_X_DIR);
|
355
|
|
- }
|
356
|
|
- else{
|
357
|
|
- if (current_block->active_extruder != 0)
|
358
|
|
- WRITE(X2_DIR_PIN, INVERT_X_DIR);
|
359
|
|
- else
|
360
|
|
- WRITE(X_DIR_PIN, INVERT_X_DIR);
|
361
|
|
- }
|
362
|
|
- #else
|
363
|
|
- WRITE(X_DIR_PIN, INVERT_X_DIR);
|
364
|
|
- #endif
|
|
351
|
+ WRITE(X_DIR_PIN, INVERT_X_DIR);
|
365
|
352
|
count_direction[X_AXIS]=-1;
|
366
|
353
|
}
|
367
|
354
|
else{
|
368
|
|
- #ifdef DUAL_X_CARRIAGE
|
369
|
|
- if (extruder_duplication_enabled){
|
370
|
|
- WRITE(X_DIR_PIN, !INVERT_X_DIR);
|
371
|
|
- WRITE(X2_DIR_PIN, !INVERT_X_DIR);
|
372
|
|
- }
|
373
|
|
- else{
|
374
|
|
- if (current_block->active_extruder != 0)
|
375
|
|
- WRITE(X2_DIR_PIN, !INVERT_X_DIR);
|
376
|
|
- else
|
377
|
|
- WRITE(X_DIR_PIN, !INVERT_X_DIR);
|
378
|
|
- }
|
379
|
|
- #else
|
380
|
|
- WRITE(X_DIR_PIN, !INVERT_X_DIR);
|
381
|
|
- #endif
|
|
355
|
+ WRITE(X_DIR_PIN, !INVERT_X_DIR);
|
382
|
356
|
count_direction[X_AXIS]=1;
|
383
|
357
|
}
|
384
|
358
|
if((out_bits & (1<<Y_AXIS))!=0){
|
385
|
359
|
WRITE(Y_DIR_PIN, INVERT_Y_DIR);
|
386
|
|
-
|
387
|
|
- #ifdef Y_DUAL_STEPPER_DRIVERS
|
388
|
|
- WRITE(Y2_DIR_PIN, !(INVERT_Y_DIR == INVERT_Y2_VS_Y_DIR));
|
389
|
|
- #endif
|
390
|
|
-
|
391
|
360
|
count_direction[Y_AXIS]=-1;
|
392
|
361
|
}
|
393
|
362
|
else{
|
394
|
363
|
WRITE(Y_DIR_PIN, !INVERT_Y_DIR);
|
395
|
|
-
|
396
|
|
- #ifdef Y_DUAL_STEPPER_DRIVERS
|
397
|
|
- WRITE(Y2_DIR_PIN, (INVERT_Y_DIR == INVERT_Y2_VS_Y_DIR));
|
398
|
|
- #endif
|
399
|
|
-
|
400
|
364
|
count_direction[Y_AXIS]=1;
|
401
|
365
|
}
|
402
|
|
-
|
|
366
|
+
|
403
|
367
|
// Set direction en check limit switches
|
404
|
368
|
#ifndef COREXY
|
405
|
369
|
if ((out_bits & (1<<X_AXIS)) != 0) { // stepping along -X axis
|
|
@@ -408,43 +372,29 @@ ISR(TIMER1_COMPA_vect)
|
408
|
372
|
#endif
|
409
|
373
|
CHECK_ENDSTOPS
|
410
|
374
|
{
|
411
|
|
- #ifdef DUAL_X_CARRIAGE
|
412
|
|
- // with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
413
|
|
- if ((current_block->active_extruder == 0 && X_HOME_DIR == -1)
|
414
|
|
- || (current_block->active_extruder != 0 && X2_HOME_DIR == -1))
|
415
|
|
- #endif
|
416
|
|
- {
|
417
|
|
- #if defined(X_MIN_PIN) && X_MIN_PIN > -1
|
418
|
|
- bool x_min_endstop=(READ(X_MIN_PIN) != X_MIN_ENDSTOP_INVERTING);
|
419
|
|
- if(x_min_endstop && old_x_min_endstop && (current_block->steps_x > 0)) {
|
420
|
|
- endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
421
|
|
- endstop_x_hit=true;
|
422
|
|
- step_events_completed = current_block->step_event_count;
|
423
|
|
- }
|
424
|
|
- old_x_min_endstop = x_min_endstop;
|
425
|
|
- #endif
|
426
|
|
- }
|
|
375
|
+ #if defined(X_MIN_PIN) && X_MIN_PIN > -1
|
|
376
|
+ bool x_min_endstop=(READ(X_MIN_PIN) != X_ENDSTOPS_INVERTING);
|
|
377
|
+ if(x_min_endstop && old_x_min_endstop && (current_block->steps_x > 0)) {
|
|
378
|
+ endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
|
379
|
+ endstop_x_hit=true;
|
|
380
|
+ step_events_completed = current_block->step_event_count;
|
|
381
|
+ }
|
|
382
|
+ old_x_min_endstop = x_min_endstop;
|
|
383
|
+ #endif
|
427
|
384
|
}
|
428
|
385
|
}
|
429
|
386
|
else { // +direction
|
430
|
|
- CHECK_ENDSTOPS
|
|
387
|
+ CHECK_ENDSTOPS
|
431
|
388
|
{
|
432
|
|
- #ifdef DUAL_X_CARRIAGE
|
433
|
|
- // with 2 x-carriages, endstops are only checked in the homing direction for the active extruder
|
434
|
|
- if ((current_block->active_extruder == 0 && X_HOME_DIR == 1)
|
435
|
|
- || (current_block->active_extruder != 0 && X2_HOME_DIR == 1))
|
436
|
|
- #endif
|
437
|
|
- {
|
438
|
|
- #if defined(X_MAX_PIN) && X_MAX_PIN > -1
|
439
|
|
- bool x_max_endstop=(READ(X_MAX_PIN) != X_MAX_ENDSTOP_INVERTING);
|
440
|
|
- if(x_max_endstop && old_x_max_endstop && (current_block->steps_x > 0)){
|
441
|
|
- endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
442
|
|
- endstop_x_hit=true;
|
443
|
|
- step_events_completed = current_block->step_event_count;
|
444
|
|
- }
|
445
|
|
- old_x_max_endstop = x_max_endstop;
|
446
|
|
- #endif
|
447
|
|
- }
|
|
389
|
+ #if defined(X_MAX_PIN) && X_MAX_PIN > -1
|
|
390
|
+ bool x_max_endstop=(READ(X_MAX_PIN) != X_ENDSTOPS_INVERTING);
|
|
391
|
+ if(x_max_endstop && old_x_max_endstop && (current_block->steps_x > 0)){
|
|
392
|
+ endstops_trigsteps[X_AXIS] = count_position[X_AXIS];
|
|
393
|
+ endstop_x_hit=true;
|
|
394
|
+ step_events_completed = current_block->step_event_count;
|
|
395
|
+ }
|
|
396
|
+ old_x_max_endstop = x_max_endstop;
|
|
397
|
+ #endif
|
448
|
398
|
}
|
449
|
399
|
}
|
450
|
400
|
|
|
@@ -456,7 +406,7 @@ ISR(TIMER1_COMPA_vect)
|
456
|
406
|
CHECK_ENDSTOPS
|
457
|
407
|
{
|
458
|
408
|
#if defined(Y_MIN_PIN) && Y_MIN_PIN > -1
|
459
|
|
- bool y_min_endstop=(READ(Y_MIN_PIN) != Y_MIN_ENDSTOP_INVERTING);
|
|
409
|
+ bool y_min_endstop=(READ(Y_MIN_PIN) != Y_ENDSTOPS_INVERTING);
|
460
|
410
|
if(y_min_endstop && old_y_min_endstop && (current_block->steps_y > 0)) {
|
461
|
411
|
endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
|
462
|
412
|
endstop_y_hit=true;
|
|
@@ -470,7 +420,7 @@ ISR(TIMER1_COMPA_vect)
|
470
|
420
|
CHECK_ENDSTOPS
|
471
|
421
|
{
|
472
|
422
|
#if defined(Y_MAX_PIN) && Y_MAX_PIN > -1
|
473
|
|
- bool y_max_endstop=(READ(Y_MAX_PIN) != Y_MAX_ENDSTOP_INVERTING);
|
|
423
|
+ bool y_max_endstop=(READ(Y_MAX_PIN) != Y_ENDSTOPS_INVERTING);
|
474
|
424
|
if(y_max_endstop && old_y_max_endstop && (current_block->steps_y > 0)){
|
475
|
425
|
endstops_trigsteps[Y_AXIS] = count_position[Y_AXIS];
|
476
|
426
|
endstop_y_hit=true;
|
|
@@ -484,15 +434,15 @@ ISR(TIMER1_COMPA_vect)
|
484
|
434
|
if ((out_bits & (1<<Z_AXIS)) != 0) { // -direction
|
485
|
435
|
WRITE(Z_DIR_PIN,INVERT_Z_DIR);
|
486
|
436
|
|
487
|
|
- #ifdef Z_DUAL_STEPPER_DRIVERS
|
|
437
|
+ #ifdef Z_DUAL_STEPPER_DRIVERS
|
488
|
438
|
WRITE(Z2_DIR_PIN,INVERT_Z_DIR);
|
489
|
439
|
#endif
|
490
|
|
-
|
|
440
|
+
|
491
|
441
|
count_direction[Z_AXIS]=-1;
|
492
|
442
|
CHECK_ENDSTOPS
|
493
|
443
|
{
|
494
|
444
|
#if defined(Z_MIN_PIN) && Z_MIN_PIN > -1
|
495
|
|
- bool z_min_endstop=(READ(Z_MIN_PIN) != Z_MIN_ENDSTOP_INVERTING);
|
|
445
|
+ bool z_min_endstop=(READ(Z_MIN_PIN) != Z_ENDSTOPS_INVERTING);
|
496
|
446
|
if(z_min_endstop && old_z_min_endstop && (current_block->steps_z > 0)) {
|
497
|
447
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
498
|
448
|
endstop_z_hit=true;
|
|
@@ -505,7 +455,7 @@ ISR(TIMER1_COMPA_vect)
|
505
|
455
|
else { // +direction
|
506
|
456
|
WRITE(Z_DIR_PIN,!INVERT_Z_DIR);
|
507
|
457
|
|
508
|
|
- #ifdef Z_DUAL_STEPPER_DRIVERS
|
|
458
|
+ #ifdef Z_DUAL_STEPPER_DRIVERS
|
509
|
459
|
WRITE(Z2_DIR_PIN,!INVERT_Z_DIR);
|
510
|
460
|
#endif
|
511
|
461
|
|
|
@@ -513,7 +463,7 @@ ISR(TIMER1_COMPA_vect)
|
513
|
463
|
CHECK_ENDSTOPS
|
514
|
464
|
{
|
515
|
465
|
#if defined(Z_MAX_PIN) && Z_MAX_PIN > -1
|
516
|
|
- bool z_max_endstop=(READ(Z_MAX_PIN) != Z_MAX_ENDSTOP_INVERTING);
|
|
466
|
+ bool z_max_endstop=(READ(Z_MAX_PIN) != Z_ENDSTOPS_INVERTING);
|
517
|
467
|
if(z_max_endstop && old_z_max_endstop && (current_block->steps_z > 0)) {
|
518
|
468
|
endstops_trigsteps[Z_AXIS] = count_position[Z_AXIS];
|
519
|
469
|
endstop_z_hit=true;
|
|
@@ -534,10 +484,10 @@ ISR(TIMER1_COMPA_vect)
|
534
|
484
|
count_direction[E_AXIS]=1;
|
535
|
485
|
}
|
536
|
486
|
#endif //!ADVANCE
|
|
487
|
+
|
537
|
488
|
|
538
|
|
-
|
539
|
|
-
|
540
|
|
- for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)
|
|
489
|
+
|
|
490
|
+ for(int8_t i=0; i < step_loops; i++) { // Take multiple steps per interrupt (For high speed moves)
|
541
|
491
|
#ifndef AT90USB
|
542
|
492
|
MSerial.checkRx(); // Check for serial chars.
|
543
|
493
|
#endif
|
|
@@ -552,73 +502,38 @@ ISR(TIMER1_COMPA_vect)
|
552
|
502
|
else {
|
553
|
503
|
e_steps[current_block->active_extruder]++;
|
554
|
504
|
}
|
555
|
|
- }
|
|
505
|
+ }
|
556
|
506
|
#endif //ADVANCE
|
557
|
507
|
|
558
|
508
|
counter_x += current_block->steps_x;
|
559
|
509
|
if (counter_x > 0) {
|
560
|
|
- #ifdef DUAL_X_CARRIAGE
|
561
|
|
- if (extruder_duplication_enabled){
|
562
|
|
- WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
|
563
|
|
- WRITE(X2_STEP_PIN, !INVERT_X_STEP_PIN);
|
564
|
|
- }
|
565
|
|
- else {
|
566
|
|
- if (current_block->active_extruder != 0)
|
567
|
|
- WRITE(X2_STEP_PIN, !INVERT_X_STEP_PIN);
|
568
|
|
- else
|
569
|
|
- WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
|
570
|
|
- }
|
571
|
|
- #else
|
572
|
510
|
WRITE(X_STEP_PIN, !INVERT_X_STEP_PIN);
|
573
|
|
- #endif
|
574
|
511
|
counter_x -= current_block->step_event_count;
|
575
|
512
|
count_position[X_AXIS]+=count_direction[X_AXIS];
|
576
|
|
- #ifdef DUAL_X_CARRIAGE
|
577
|
|
- if (extruder_duplication_enabled){
|
578
|
|
- WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
|
579
|
|
- WRITE(X2_STEP_PIN, INVERT_X_STEP_PIN);
|
580
|
|
- }
|
581
|
|
- else {
|
582
|
|
- if (current_block->active_extruder != 0)
|
583
|
|
- WRITE(X2_STEP_PIN, INVERT_X_STEP_PIN);
|
584
|
|
- else
|
585
|
|
- WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
|
586
|
|
- }
|
587
|
|
- #else
|
588
|
513
|
WRITE(X_STEP_PIN, INVERT_X_STEP_PIN);
|
589
|
|
- #endif
|
590
|
514
|
}
|
591
|
|
-
|
|
515
|
+
|
592
|
516
|
counter_y += current_block->steps_y;
|
593
|
517
|
if (counter_y > 0) {
|
594
|
518
|
WRITE(Y_STEP_PIN, !INVERT_Y_STEP_PIN);
|
595
|
|
-
|
596
|
|
- #ifdef Y_DUAL_STEPPER_DRIVERS
|
597
|
|
- WRITE(Y2_STEP_PIN, !INVERT_Y_STEP_PIN);
|
598
|
|
- #endif
|
599
|
|
-
|
600
|
|
- counter_y -= current_block->step_event_count;
|
601
|
|
- count_position[Y_AXIS]+=count_direction[Y_AXIS];
|
|
519
|
+ counter_y -= current_block->step_event_count;
|
|
520
|
+ count_position[Y_AXIS]+=count_direction[Y_AXIS];
|
602
|
521
|
WRITE(Y_STEP_PIN, INVERT_Y_STEP_PIN);
|
603
|
|
-
|
604
|
|
- #ifdef Y_DUAL_STEPPER_DRIVERS
|
605
|
|
- WRITE(Y2_STEP_PIN, INVERT_Y_STEP_PIN);
|
606
|
|
- #endif
|
607
|
522
|
}
|
608
|
|
-
|
|
523
|
+
|
609
|
524
|
counter_z += current_block->steps_z;
|
610
|
525
|
if (counter_z > 0) {
|
611
|
526
|
WRITE(Z_STEP_PIN, !INVERT_Z_STEP_PIN);
|
612
|
527
|
|
613
|
|
- #ifdef Z_DUAL_STEPPER_DRIVERS
|
|
528
|
+ #ifdef Z_DUAL_STEPPER_DRIVERS
|
614
|
529
|
WRITE(Z2_STEP_PIN, !INVERT_Z_STEP_PIN);
|
615
|
530
|
#endif
|
616
|
|
-
|
|
531
|
+
|
617
|
532
|
counter_z -= current_block->step_event_count;
|
618
|
533
|
count_position[Z_AXIS]+=count_direction[Z_AXIS];
|
619
|
534
|
WRITE(Z_STEP_PIN, INVERT_Z_STEP_PIN);
|
620
|
535
|
|
621
|
|
- #ifdef Z_DUAL_STEPPER_DRIVERS
|
|
536
|
+ #ifdef Z_DUAL_STEPPER_DRIVERS
|
622
|
537
|
WRITE(Z2_STEP_PIN, INVERT_Z_STEP_PIN);
|
623
|
538
|
#endif
|
624
|
539
|
}
|
|
@@ -632,17 +547,17 @@ ISR(TIMER1_COMPA_vect)
|
632
|
547
|
WRITE_E_STEP(INVERT_E_STEP_PIN);
|
633
|
548
|
}
|
634
|
549
|
#endif //!ADVANCE
|
635
|
|
- step_events_completed += 1;
|
|
550
|
+ step_events_completed += 1;
|
636
|
551
|
if(step_events_completed >= current_block->step_event_count) break;
|
637
|
552
|
}
|
638
|
553
|
// Calculare new timer value
|
639
|
554
|
unsigned short timer;
|
640
|
555
|
unsigned short step_rate;
|
641
|
556
|
if (step_events_completed <= (unsigned long int)current_block->accelerate_until) {
|
642
|
|
-
|
|
557
|
+
|
643
|
558
|
MultiU24X24toH16(acc_step_rate, acceleration_time, current_block->acceleration_rate);
|
644
|
559
|
acc_step_rate += current_block->initial_rate;
|
645
|
|
-
|
|
560
|
+
|
646
|
561
|
// upper limit
|
647
|
562
|
if(acc_step_rate > current_block->nominal_rate)
|
648
|
563
|
acc_step_rate = current_block->nominal_rate;
|
|
@@ -658,13 +573,13 @@ ISR(TIMER1_COMPA_vect)
|
658
|
573
|
//if(advance > current_block->advance) advance = current_block->advance;
|
659
|
574
|
// Do E steps + advance steps
|
660
|
575
|
e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
|
661
|
|
- old_advance = advance >>8;
|
662
|
|
-
|
|
576
|
+ old_advance = advance >>8;
|
|
577
|
+
|
663
|
578
|
#endif
|
664
|
|
- }
|
665
|
|
- else if (step_events_completed > (unsigned long int)current_block->decelerate_after) {
|
|
579
|
+ }
|
|
580
|
+ else if (step_events_completed > (unsigned long int)current_block->decelerate_after) {
|
666
|
581
|
MultiU24X24toH16(step_rate, deceleration_time, current_block->acceleration_rate);
|
667
|
|
-
|
|
582
|
+
|
668
|
583
|
if(step_rate > acc_step_rate) { // Check step_rate stays positive
|
669
|
584
|
step_rate = current_block->final_rate;
|
670
|
585
|
}
|
|
@@ -687,7 +602,7 @@ ISR(TIMER1_COMPA_vect)
|
687
|
602
|
if(advance < final_advance) advance = final_advance;
|
688
|
603
|
// Do E steps + advance steps
|
689
|
604
|
e_steps[current_block->active_extruder] += ((advance >>8) - old_advance);
|
690
|
|
- old_advance = advance >>8;
|
|
605
|
+ old_advance = advance >>8;
|
691
|
606
|
#endif //ADVANCE
|
692
|
607
|
}
|
693
|
608
|
else {
|
|
@@ -696,12 +611,12 @@ ISR(TIMER1_COMPA_vect)
|
696
|
611
|
step_loops = step_loops_nominal;
|
697
|
612
|
}
|
698
|
613
|
|
699
|
|
- // If current block is finished, reset pointer
|
|
614
|
+ // If current block is finished, reset pointer
|
700
|
615
|
if (step_events_completed >= current_block->step_event_count) {
|
701
|
616
|
current_block = NULL;
|
702
|
617
|
plan_discard_current_block();
|
703
|
|
- }
|
704
|
|
- }
|
|
618
|
+ }
|
|
619
|
+ }
|
705
|
620
|
}
|
706
|
621
|
|
707
|
622
|
#ifdef ADVANCE
|
|
@@ -720,7 +635,7 @@ ISR(TIMER1_COMPA_vect)
|
720
|
635
|
WRITE(E0_DIR_PIN, INVERT_E0_DIR);
|
721
|
636
|
e_steps[0]++;
|
722
|
637
|
WRITE(E0_STEP_PIN, !INVERT_E_STEP_PIN);
|
723
|
|
- }
|
|
638
|
+ }
|
724
|
639
|
else if (e_steps[0] > 0) {
|
725
|
640
|
WRITE(E0_DIR_PIN, !INVERT_E0_DIR);
|
726
|
641
|
e_steps[0]--;
|
|
@@ -734,7 +649,7 @@ ISR(TIMER1_COMPA_vect)
|
734
|
649
|
WRITE(E1_DIR_PIN, INVERT_E1_DIR);
|
735
|
650
|
e_steps[1]++;
|
736
|
651
|
WRITE(E1_STEP_PIN, !INVERT_E_STEP_PIN);
|
737
|
|
- }
|
|
652
|
+ }
|
738
|
653
|
else if (e_steps[1] > 0) {
|
739
|
654
|
WRITE(E1_DIR_PIN, !INVERT_E1_DIR);
|
740
|
655
|
e_steps[1]--;
|
|
@@ -749,7 +664,7 @@ ISR(TIMER1_COMPA_vect)
|
749
|
664
|
WRITE(E2_DIR_PIN, INVERT_E2_DIR);
|
750
|
665
|
e_steps[2]++;
|
751
|
666
|
WRITE(E2_STEP_PIN, !INVERT_E_STEP_PIN);
|
752
|
|
- }
|
|
667
|
+ }
|
753
|
668
|
else if (e_steps[2] > 0) {
|
754
|
669
|
WRITE(E2_DIR_PIN, !INVERT_E2_DIR);
|
755
|
670
|
e_steps[2]--;
|
|
@@ -765,29 +680,22 @@ void st_init()
|
765
|
680
|
{
|
766
|
681
|
digipot_init(); //Initialize Digipot Motor Current
|
767
|
682
|
microstep_init(); //Initialize Microstepping Pins
|
768
|
|
-
|
|
683
|
+
|
769
|
684
|
//Initialize Dir Pins
|
770
|
685
|
#if defined(X_DIR_PIN) && X_DIR_PIN > -1
|
771
|
686
|
SET_OUTPUT(X_DIR_PIN);
|
772
|
687
|
#endif
|
773
|
|
- #if defined(X2_DIR_PIN) && X2_DIR_PIN > -1
|
774
|
|
- SET_OUTPUT(X2_DIR_PIN);
|
775
|
|
- #endif
|
776
|
|
- #if defined(Y_DIR_PIN) && Y_DIR_PIN > -1
|
|
688
|
+ #if defined(Y_DIR_PIN) && Y_DIR_PIN > -1
|
777
|
689
|
SET_OUTPUT(Y_DIR_PIN);
|
778
|
|
-
|
779
|
|
- #if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_DIR_PIN) && (Y2_DIR_PIN > -1)
|
780
|
|
- SET_OUTPUT(Y2_DIR_PIN);
|
781
|
|
- #endif
|
782
|
690
|
#endif
|
783
|
|
- #if defined(Z_DIR_PIN) && Z_DIR_PIN > -1
|
|
691
|
+ #if defined(Z_DIR_PIN) && Z_DIR_PIN > -1
|
784
|
692
|
SET_OUTPUT(Z_DIR_PIN);
|
785
|
693
|
|
786
|
694
|
#if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_DIR_PIN) && (Z2_DIR_PIN > -1)
|
787
|
695
|
SET_OUTPUT(Z2_DIR_PIN);
|
788
|
696
|
#endif
|
789
|
697
|
#endif
|
790
|
|
- #if defined(E0_DIR_PIN) && E0_DIR_PIN > -1
|
|
698
|
+ #if defined(E0_DIR_PIN) && E0_DIR_PIN > -1
|
791
|
699
|
SET_OUTPUT(E0_DIR_PIN);
|
792
|
700
|
#endif
|
793
|
701
|
#if defined(E1_DIR_PIN) && (E1_DIR_PIN > -1)
|
|
@@ -803,23 +711,14 @@ void st_init()
|
803
|
711
|
SET_OUTPUT(X_ENABLE_PIN);
|
804
|
712
|
if(!X_ENABLE_ON) WRITE(X_ENABLE_PIN,HIGH);
|
805
|
713
|
#endif
|
806
|
|
- #if defined(X2_ENABLE_PIN) && X2_ENABLE_PIN > -1
|
807
|
|
- SET_OUTPUT(X2_ENABLE_PIN);
|
808
|
|
- if(!X_ENABLE_ON) WRITE(X2_ENABLE_PIN,HIGH);
|
809
|
|
- #endif
|
810
|
714
|
#if defined(Y_ENABLE_PIN) && Y_ENABLE_PIN > -1
|
811
|
715
|
SET_OUTPUT(Y_ENABLE_PIN);
|
812
|
716
|
if(!Y_ENABLE_ON) WRITE(Y_ENABLE_PIN,HIGH);
|
813
|
|
-
|
814
|
|
- #if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_ENABLE_PIN) && (Y2_ENABLE_PIN > -1)
|
815
|
|
- SET_OUTPUT(Y2_ENABLE_PIN);
|
816
|
|
- if(!Y_ENABLE_ON) WRITE(Y2_ENABLE_PIN,HIGH);
|
817
|
|
- #endif
|
818
|
717
|
#endif
|
819
|
718
|
#if defined(Z_ENABLE_PIN) && Z_ENABLE_PIN > -1
|
820
|
719
|
SET_OUTPUT(Z_ENABLE_PIN);
|
821
|
720
|
if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH);
|
822
|
|
-
|
|
721
|
+
|
823
|
722
|
#if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_ENABLE_PIN) && (Z2_ENABLE_PIN > -1)
|
824
|
723
|
SET_OUTPUT(Z2_ENABLE_PIN);
|
825
|
724
|
if(!Z_ENABLE_ON) WRITE(Z2_ENABLE_PIN,HIGH);
|
|
@@ -839,71 +738,62 @@ void st_init()
|
839
|
738
|
#endif
|
840
|
739
|
|
841
|
740
|
//endstops and pullups
|
842
|
|
-
|
|
741
|
+
|
843
|
742
|
#if defined(X_MIN_PIN) && X_MIN_PIN > -1
|
844
|
|
- SET_INPUT(X_MIN_PIN);
|
|
743
|
+ SET_INPUT(X_MIN_PIN);
|
845
|
744
|
#ifdef ENDSTOPPULLUP_XMIN
|
846
|
745
|
WRITE(X_MIN_PIN,HIGH);
|
847
|
746
|
#endif
|
848
|
747
|
#endif
|
849
|
|
-
|
|
748
|
+
|
850
|
749
|
#if defined(Y_MIN_PIN) && Y_MIN_PIN > -1
|
851
|
|
- SET_INPUT(Y_MIN_PIN);
|
|
750
|
+ SET_INPUT(Y_MIN_PIN);
|
852
|
751
|
#ifdef ENDSTOPPULLUP_YMIN
|
853
|
752
|
WRITE(Y_MIN_PIN,HIGH);
|
854
|
753
|
#endif
|
855
|
754
|
#endif
|
856
|
|
-
|
|
755
|
+
|
857
|
756
|
#if defined(Z_MIN_PIN) && Z_MIN_PIN > -1
|
858
|
|
- SET_INPUT(Z_MIN_PIN);
|
|
757
|
+ SET_INPUT(Z_MIN_PIN);
|
859
|
758
|
#ifdef ENDSTOPPULLUP_ZMIN
|
860
|
759
|
WRITE(Z_MIN_PIN,HIGH);
|
861
|
760
|
#endif
|
862
|
761
|
#endif
|
863
|
|
-
|
|
762
|
+
|
864
|
763
|
#if defined(X_MAX_PIN) && X_MAX_PIN > -1
|
865
|
|
- SET_INPUT(X_MAX_PIN);
|
|
764
|
+ SET_INPUT(X_MAX_PIN);
|
866
|
765
|
#ifdef ENDSTOPPULLUP_XMAX
|
867
|
766
|
WRITE(X_MAX_PIN,HIGH);
|
868
|
767
|
#endif
|
869
|
768
|
#endif
|
870
|
|
-
|
|
769
|
+
|
871
|
770
|
#if defined(Y_MAX_PIN) && Y_MAX_PIN > -1
|
872
|
|
- SET_INPUT(Y_MAX_PIN);
|
|
771
|
+ SET_INPUT(Y_MAX_PIN);
|
873
|
772
|
#ifdef ENDSTOPPULLUP_YMAX
|
874
|
773
|
WRITE(Y_MAX_PIN,HIGH);
|
875
|
774
|
#endif
|
876
|
775
|
#endif
|
877
|
|
-
|
|
776
|
+
|
878
|
777
|
#if defined(Z_MAX_PIN) && Z_MAX_PIN > -1
|
879
|
|
- SET_INPUT(Z_MAX_PIN);
|
|
778
|
+ SET_INPUT(Z_MAX_PIN);
|
880
|
779
|
#ifdef ENDSTOPPULLUP_ZMAX
|
881
|
780
|
WRITE(Z_MAX_PIN,HIGH);
|
882
|
781
|
#endif
|
883
|
782
|
#endif
|
884
|
|
-
|
|
783
|
+
|
885
|
784
|
|
886
|
785
|
//Initialize Step Pins
|
887
|
|
- #if defined(X_STEP_PIN) && (X_STEP_PIN > -1)
|
|
786
|
+ #if defined(X_STEP_PIN) && (X_STEP_PIN > -1)
|
888
|
787
|
SET_OUTPUT(X_STEP_PIN);
|
889
|
788
|
WRITE(X_STEP_PIN,INVERT_X_STEP_PIN);
|
890
|
789
|
disable_x();
|
891
|
|
- #endif
|
892
|
|
- #if defined(X2_STEP_PIN) && (X2_STEP_PIN > -1)
|
893
|
|
- SET_OUTPUT(X2_STEP_PIN);
|
894
|
|
- WRITE(X2_STEP_PIN,INVERT_X_STEP_PIN);
|
895
|
|
- disable_x();
|
896
|
|
- #endif
|
897
|
|
- #if defined(Y_STEP_PIN) && (Y_STEP_PIN > -1)
|
|
790
|
+ #endif
|
|
791
|
+ #if defined(Y_STEP_PIN) && (Y_STEP_PIN > -1)
|
898
|
792
|
SET_OUTPUT(Y_STEP_PIN);
|
899
|
793
|
WRITE(Y_STEP_PIN,INVERT_Y_STEP_PIN);
|
900
|
|
- #if defined(Y_DUAL_STEPPER_DRIVERS) && defined(Y2_STEP_PIN) && (Y2_STEP_PIN > -1)
|
901
|
|
- SET_OUTPUT(Y2_STEP_PIN);
|
902
|
|
- WRITE(Y2_STEP_PIN,INVERT_Y_STEP_PIN);
|
903
|
|
- #endif
|
904
|
794
|
disable_y();
|
905
|
|
- #endif
|
906
|
|
- #if defined(Z_STEP_PIN) && (Z_STEP_PIN > -1)
|
|
795
|
+ #endif
|
|
796
|
+ #if defined(Z_STEP_PIN) && (Z_STEP_PIN > -1)
|
907
|
797
|
SET_OUTPUT(Z_STEP_PIN);
|
908
|
798
|
WRITE(Z_STEP_PIN,INVERT_Z_STEP_PIN);
|
909
|
799
|
#if defined(Z_DUAL_STEPPER_DRIVERS) && defined(Z2_STEP_PIN) && (Z2_STEP_PIN > -1)
|
|
@@ -911,33 +801,33 @@ void st_init()
|
911
|
801
|
WRITE(Z2_STEP_PIN,INVERT_Z_STEP_PIN);
|
912
|
802
|
#endif
|
913
|
803
|
disable_z();
|
914
|
|
- #endif
|
915
|
|
- #if defined(E0_STEP_PIN) && (E0_STEP_PIN > -1)
|
|
804
|
+ #endif
|
|
805
|
+ #if defined(E0_STEP_PIN) && (E0_STEP_PIN > -1)
|
916
|
806
|
SET_OUTPUT(E0_STEP_PIN);
|
917
|
807
|
WRITE(E0_STEP_PIN,INVERT_E_STEP_PIN);
|
918
|
808
|
disable_e0();
|
919
|
|
- #endif
|
920
|
|
- #if defined(E1_STEP_PIN) && (E1_STEP_PIN > -1)
|
|
809
|
+ #endif
|
|
810
|
+ #if defined(E1_STEP_PIN) && (E1_STEP_PIN > -1)
|
921
|
811
|
SET_OUTPUT(E1_STEP_PIN);
|
922
|
812
|
WRITE(E1_STEP_PIN,INVERT_E_STEP_PIN);
|
923
|
813
|
disable_e1();
|
924
|
|
- #endif
|
925
|
|
- #if defined(E2_STEP_PIN) && (E2_STEP_PIN > -1)
|
|
814
|
+ #endif
|
|
815
|
+ #if defined(E2_STEP_PIN) && (E2_STEP_PIN > -1)
|
926
|
816
|
SET_OUTPUT(E2_STEP_PIN);
|
927
|
817
|
WRITE(E2_STEP_PIN,INVERT_E_STEP_PIN);
|
928
|
818
|
disable_e2();
|
929
|
|
- #endif
|
|
819
|
+ #endif
|
930
|
820
|
|
931
|
821
|
// waveform generation = 0100 = CTC
|
932
|
822
|
TCCR1B &= ~(1<<WGM13);
|
933
|
823
|
TCCR1B |= (1<<WGM12);
|
934
|
|
- TCCR1A &= ~(1<<WGM11);
|
|
824
|
+ TCCR1A &= ~(1<<WGM11);
|
935
|
825
|
TCCR1A &= ~(1<<WGM10);
|
936
|
826
|
|
937
|
827
|
// output mode = 00 (disconnected)
|
938
|
|
- TCCR1A &= ~(3<<COM1A0);
|
939
|
|
- TCCR1A &= ~(3<<COM1B0);
|
940
|
|
-
|
|
828
|
+ TCCR1A &= ~(3<<COM1A0);
|
|
829
|
+ TCCR1A &= ~(3<<COM1B0);
|
|
830
|
+
|
941
|
831
|
// Set the timer pre-scaler
|
942
|
832
|
// Generally we use a divider of 8, resulting in a 2MHz timer
|
943
|
833
|
// frequency on a 16MHz MCU. If you are going to change this, be
|
|
@@ -947,19 +837,19 @@ void st_init()
|
947
|
837
|
|
948
|
838
|
OCR1A = 0x4000;
|
949
|
839
|
TCNT1 = 0;
|
950
|
|
- ENABLE_STEPPER_DRIVER_INTERRUPT();
|
|
840
|
+ ENABLE_STEPPER_DRIVER_INTERRUPT();
|
951
|
841
|
|
952
|
842
|
#ifdef ADVANCE
|
953
|
843
|
#if defined(TCCR0A) && defined(WGM01)
|
954
|
844
|
TCCR0A &= ~(1<<WGM01);
|
955
|
845
|
TCCR0A &= ~(1<<WGM00);
|
956
|
|
- #endif
|
|
846
|
+ #endif
|
957
|
847
|
e_steps[0] = 0;
|
958
|
848
|
e_steps[1] = 0;
|
959
|
849
|
e_steps[2] = 0;
|
960
|
850
|
TIMSK0 |= (1<<OCIE0A);
|
961
|
851
|
#endif //ADVANCE
|
962
|
|
-
|
|
852
|
+
|
963
|
853
|
enable_endstops(true); // Start with endstops active. After homing they can be disabled
|
964
|
854
|
sei();
|
965
|
855
|
}
|
|
@@ -1003,13 +893,13 @@ long st_get_position(uint8_t axis)
|
1003
|
893
|
|
1004
|
894
|
void finishAndDisableSteppers()
|
1005
|
895
|
{
|
1006
|
|
- st_synchronize();
|
1007
|
|
- disable_x();
|
1008
|
|
- disable_y();
|
1009
|
|
- disable_z();
|
1010
|
|
- disable_e0();
|
1011
|
|
- disable_e1();
|
1012
|
|
- disable_e2();
|
|
896
|
+ st_synchronize();
|
|
897
|
+ disable_x();
|
|
898
|
+ disable_y();
|
|
899
|
+ disable_z();
|
|
900
|
+ disable_e0();
|
|
901
|
+ disable_e1();
|
|
902
|
+ disable_e2();
|
1013
|
903
|
}
|
1014
|
904
|
|
1015
|
905
|
void quickStop()
|
|
@@ -1036,10 +926,10 @@ void digipot_init() //Initialize Digipot Motor Current
|
1036
|
926
|
{
|
1037
|
927
|
#if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1
|
1038
|
928
|
const uint8_t digipot_motor_current[] = DIGIPOT_MOTOR_CURRENT;
|
1039
|
|
-
|
1040
|
|
- SPI.begin();
|
1041
|
|
- pinMode(DIGIPOTSS_PIN, OUTPUT);
|
1042
|
|
- for(int i=0;i<=4;i++)
|
|
929
|
+
|
|
930
|
+ SPI.begin();
|
|
931
|
+ pinMode(DIGIPOTSS_PIN, OUTPUT);
|
|
932
|
+ for(int i=0;i<=4;i++)
|
1043
|
933
|
//digitalPotWrite(digipot_ch[i], digipot_motor_current[i]);
|
1044
|
934
|
digipot_current(i,digipot_motor_current[i]);
|
1045
|
935
|
#endif
|