Explorar el Código

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 hace 7 años
padre
commit
50059690e0
Se han modificado 1 ficheros con 29 adiciones y 4 borrados
  1. 29
    4
      Marlin/stepper.cpp

+ 29
- 4
Marlin/stepper.cpp Ver fichero

@@ -331,6 +331,14 @@ void Stepper::set_directions() {
331 331
 ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
332 332
 
333 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 342
   if (cleaning_buffer_counter) {
335 343
     current_block = NULL;
336 344
     planner.discard_current_block();
@@ -339,6 +347,12 @@ void Stepper::isr() {
339 347
     #endif
340 348
     cleaning_buffer_counter--;
341 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 356
     return;
343 357
   }
344 358
 
@@ -368,6 +382,11 @@ void Stepper::isr() {
368 382
         if (current_block->steps[Z_AXIS] > 0) {
369 383
           enable_z();
370 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 390
           return;
372 391
         }
373 392
       #endif
@@ -378,6 +397,11 @@ void Stepper::isr() {
378 397
     }
379 398
     else {
380 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 405
       return;
382 406
     }
383 407
   }
@@ -402,10 +426,6 @@ void Stepper::isr() {
402 426
   // Take multiple steps per interrupt (For high speed moves)
403 427
   bool all_steps_done = false;
404 428
   for (int8_t i = 0; i < step_loops; i++) {
405
-    #ifndef USBCON
406
-      customizedSerial.checkRx(); // Check for serial chars.
407
-    #endif
408
-
409 429
     #if ENABLED(LIN_ADVANCE)
410 430
 
411 431
       counter_E += current_block->steps[E_AXIS];
@@ -694,6 +714,11 @@ void Stepper::isr() {
694 714
     current_block = NULL;
695 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 724
 #if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)

Loading…
Cancelar
Guardar