Browse Source

Allow UART ISRs inside the stepper ISR

If the stepper ISR takes too long, chars are lost which leads to serial
communication errors like "Line number not +1" or "Wrong checksum". In
worst case, the printer can even do crazy moves.

With this changes, UART interrupts are handled inside the stepper ISR.
This way, no chars should be lost.
Sebastianv650 7 years ago
parent
commit
50059690e0
1 changed files with 29 additions and 4 deletions
  1. 29
    4
      Marlin/stepper.cpp

+ 29
- 4
Marlin/stepper.cpp View File

331
 ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
331
 ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
332
 
332
 
333
 void Stepper::isr() {
333
 void Stepper::isr() {
334
+  //Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
335
+  #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
336
+    CBI(TIMSK0, OCIE0A); //estepper ISR
337
+  #endif
338
+  CBI(TIMSK0, OCIE0B); //Temperature ISR
339
+  DISABLE_STEPPER_DRIVER_INTERRUPT();
340
+  sei();
341
+  
334
   if (cleaning_buffer_counter) {
342
   if (cleaning_buffer_counter) {
335
     current_block = NULL;
343
     current_block = NULL;
336
     planner.discard_current_block();
344
     planner.discard_current_block();
339
     #endif
347
     #endif
340
     cleaning_buffer_counter--;
348
     cleaning_buffer_counter--;
341
     OCR1A = 200; // Run at max speed - 10 KHz
349
     OCR1A = 200; // Run at max speed - 10 KHz
350
+    //re-enable ISRs
351
+    #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
352
+      SBI(TIMSK0, OCIE0A);
353
+    #endif
354
+    SBI(TIMSK0, OCIE0B);
355
+    ENABLE_STEPPER_DRIVER_INTERRUPT();
342
     return;
356
     return;
343
   }
357
   }
344
 
358
 
368
         if (current_block->steps[Z_AXIS] > 0) {
382
         if (current_block->steps[Z_AXIS] > 0) {
369
           enable_z();
383
           enable_z();
370
           OCR1A = 2000; // Run at slow speed - 1 KHz
384
           OCR1A = 2000; // Run at slow speed - 1 KHz
385
+          #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
386
+            SBI(TIMSK0, OCIE0A);
387
+          #endif
388
+          SBI(TIMSK0, OCIE0B);
389
+          ENABLE_STEPPER_DRIVER_INTERRUPT();
371
           return;
390
           return;
372
         }
391
         }
373
       #endif
392
       #endif
378
     }
397
     }
379
     else {
398
     else {
380
       OCR1A = 2000; // Run at slow speed - 1 KHz
399
       OCR1A = 2000; // Run at slow speed - 1 KHz
400
+      #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
401
+        SBI(TIMSK0, OCIE0A);
402
+      #endif
403
+      SBI(TIMSK0, OCIE0B);
404
+      ENABLE_STEPPER_DRIVER_INTERRUPT();
381
       return;
405
       return;
382
     }
406
     }
383
   }
407
   }
402
   // Take multiple steps per interrupt (For high speed moves)
426
   // Take multiple steps per interrupt (For high speed moves)
403
   bool all_steps_done = false;
427
   bool all_steps_done = false;
404
   for (int8_t i = 0; i < step_loops; i++) {
428
   for (int8_t i = 0; i < step_loops; i++) {
405
-    #ifndef USBCON
406
-      customizedSerial.checkRx(); // Check for serial chars.
407
-    #endif
408
-
409
     #if ENABLED(LIN_ADVANCE)
429
     #if ENABLED(LIN_ADVANCE)
410
 
430
 
411
       counter_E += current_block->steps[E_AXIS];
431
       counter_E += current_block->steps[E_AXIS];
694
     current_block = NULL;
714
     current_block = NULL;
695
     planner.discard_current_block();
715
     planner.discard_current_block();
696
   }
716
   }
717
+  #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
718
+    SBI(TIMSK0, OCIE0A);
719
+  #endif
720
+  SBI(TIMSK0, OCIE0B);
721
+  ENABLE_STEPPER_DRIVER_INTERRUPT();
697
 }
722
 }
698
 
723
 
699
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
724
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)

Loading…
Cancel
Save