mirror of
https://github.com/MarlinFirmware/Marlin.git
synced 2024-11-23 20:18:52 +00:00
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.
This commit is contained in:
parent
8bf07684d2
commit
50059690e0
@ -331,6 +331,14 @@ void Stepper::set_directions() {
|
||||
ISR(TIMER1_COMPA_vect) { Stepper::isr(); }
|
||||
|
||||
void Stepper::isr() {
|
||||
//Disable Timer0 ISRs and enable global ISR again to capture UART events (incoming chars)
|
||||
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
||||
CBI(TIMSK0, OCIE0A); //estepper ISR
|
||||
#endif
|
||||
CBI(TIMSK0, OCIE0B); //Temperature ISR
|
||||
DISABLE_STEPPER_DRIVER_INTERRUPT();
|
||||
sei();
|
||||
|
||||
if (cleaning_buffer_counter) {
|
||||
current_block = NULL;
|
||||
planner.discard_current_block();
|
||||
@ -339,6 +347,12 @@ void Stepper::isr() {
|
||||
#endif
|
||||
cleaning_buffer_counter--;
|
||||
OCR1A = 200; // Run at max speed - 10 KHz
|
||||
//re-enable ISRs
|
||||
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
||||
SBI(TIMSK0, OCIE0A);
|
||||
#endif
|
||||
SBI(TIMSK0, OCIE0B);
|
||||
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
||||
return;
|
||||
}
|
||||
|
||||
@ -368,6 +382,11 @@ void Stepper::isr() {
|
||||
if (current_block->steps[Z_AXIS] > 0) {
|
||||
enable_z();
|
||||
OCR1A = 2000; // Run at slow speed - 1 KHz
|
||||
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
||||
SBI(TIMSK0, OCIE0A);
|
||||
#endif
|
||||
SBI(TIMSK0, OCIE0B);
|
||||
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
@ -378,6 +397,11 @@ void Stepper::isr() {
|
||||
}
|
||||
else {
|
||||
OCR1A = 2000; // Run at slow speed - 1 KHz
|
||||
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
||||
SBI(TIMSK0, OCIE0A);
|
||||
#endif
|
||||
SBI(TIMSK0, OCIE0B);
|
||||
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -402,10 +426,6 @@ void Stepper::isr() {
|
||||
// Take multiple steps per interrupt (For high speed moves)
|
||||
bool all_steps_done = false;
|
||||
for (int8_t i = 0; i < step_loops; i++) {
|
||||
#ifndef USBCON
|
||||
customizedSerial.checkRx(); // Check for serial chars.
|
||||
#endif
|
||||
|
||||
#if ENABLED(LIN_ADVANCE)
|
||||
|
||||
counter_E += current_block->steps[E_AXIS];
|
||||
@ -694,6 +714,11 @@ void Stepper::isr() {
|
||||
current_block = NULL;
|
||||
planner.discard_current_block();
|
||||
}
|
||||
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
||||
SBI(TIMSK0, OCIE0A);
|
||||
#endif
|
||||
SBI(TIMSK0, OCIE0B);
|
||||
ENABLE_STEPPER_DRIVER_INTERRUPT();
|
||||
}
|
||||
|
||||
#if ENABLED(ADVANCE) || ENABLED(LIN_ADVANCE)
|
||||
|
Loading…
Reference in New Issue
Block a user