From fa9ff6be6e1a83b2d4ca1315d4d218b671e47e20 Mon Sep 17 00:00:00 2001 From: kfazz Date: Sat, 12 Aug 2017 20:09:39 -0400 Subject: [PATCH] try to fix LIN_ADVANCE for 32bit --- Marlin/stepper.cpp | 19 +++++++++++++------ Marlin/temperature.cpp | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Marlin/stepper.cpp b/Marlin/stepper.cpp index c3d9808ec0..e1fa297348 100644 --- a/Marlin/stepper.cpp +++ b/Marlin/stepper.cpp @@ -803,9 +803,9 @@ void Stepper::isr() { #if DISABLED(ADVANCE) && DISABLED(LIN_ADVANCE) #ifdef CPU_32_BIT // Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room - uint32_t stepper_timer_count = HAL_timer_get_count(STEP_TIMER_NUM); - uint32_t stepper_timer_current_count = HAL_timer_get_current_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US; - HAL_timer_set_count(STEP_TIMER_NUM, stepper_timer_count < stepper_timer_current_count ? stepper_timer_current_count : stepper_timer_count); + uint32_t stepper_timer_count = HAL_timer_get_count(STEP_TIMER_NUM), + stepper_timer_current_count = HAL_timer_get_current_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US; + HAL_timer_set_count(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count)); #else NOLESS(OCR1A, TCNT1 + 16); #endif @@ -932,7 +932,7 @@ void Stepper::isr() { // Is the next advance ISR scheduled before the next main ISR? if (nextAdvanceISR <= nextMainISR) { // Set up the next interrupt - OCR1A = nextAdvanceISR; + HAL_timer_set_count(STEP_TIMER_NUM, nextAdvanceISR); // New interval for the next main ISR if (nextMainISR) nextMainISR -= nextAdvanceISR; // Will call Stepper::advance_isr on the next interrupt @@ -940,7 +940,7 @@ void Stepper::isr() { } else { // The next main ISR comes first - OCR1A = nextMainISR; + HAL_timer_set_count(STEP_TIMER_NUM, nextMainISR); // New interval for the next advance ISR, if any if (nextAdvanceISR && nextAdvanceISR != ADV_NEVER) nextAdvanceISR -= nextMainISR; @@ -949,7 +949,14 @@ void Stepper::isr() { } // Don't run the ISR faster than possible - NOLESS(OCR1A, TCNT1 + 16); + #ifdef CPU_32_BIT + // Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room + uint32_t stepper_timer_count = HAL_timer_get_count(STEP_TIMER_NUM), + stepper_timer_current_count = HAL_timer_get_current_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US; + HAL_timer_set_count(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count)); + #else + NOLESS(OCR1A, TCNT1 + 16); + #endif // Restore original ISR settings HAL_ENABLE_ISRs(); diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index e2d88775bf..dfda329af3 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -1608,7 +1608,7 @@ void Temperature::isr() { // Allow UART and stepper ISRs DISABLE_TEMPERATURE_INTERRUPT(); //Disable Temperature ISR - #if !defined(CPU_32_BIT) + #ifndef CPU_32_BIT sei(); #endif @@ -2114,7 +2114,7 @@ void Temperature::isr() { } #endif - #if !defined(CPU_32_BIT) + #ifndef CPU_32_BIT cli(); #endif in_temp_isr = false;