[2.0.x] HAL timer set/get count => set/get compare (#9581)

To reduce confusion over the current timer count vs. the compare (aka "top") value. Caution: this re-uses the function name, changing its meaning.
This commit is contained in:
Scott Lahteine 2018-02-10 20:42:00 -06:00 committed by GitHub
parent 7a4029d1b1
commit 03d790451f
Signed by: GitHub
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 65 additions and 65 deletions

View file

@ -147,10 +147,10 @@ extern "C" {
#define HAL_timer_start(timer_num, frequency) #define HAL_timer_start(timer_num, frequency)
#define _CAT(a, ...) a ## __VA_ARGS__ #define _CAT(a, ...) a ## __VA_ARGS__
#define HAL_timer_set_count(timer, count) (_CAT(TIMER_OCR_, timer) = count) #define HAL_timer_set_compare(timer, compare) (_CAT(TIMER_OCR_, timer) = compare)
#define HAL_timer_get_count(timer) _CAT(TIMER_OCR_, timer) #define HAL_timer_get_compare(timer) _CAT(TIMER_OCR_, timer)
#define HAL_timer_set_current_count(timer, count) (_CAT(TIMER_COUNTER_, timer) = count) #define HAL_timer_set_count(timer, count) (_CAT(TIMER_COUNTER_, timer) = count)
#define HAL_timer_get_current_count(timer) _CAT(TIMER_COUNTER_, timer) #define HAL_timer_get_count(timer) _CAT(TIMER_COUNTER_, timer)
#define HAL_timer_isr_prologue(timer_num) #define HAL_timer_isr_prologue(timer_num)

View file

@ -127,9 +127,9 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num) {
} }
#if 0 #if 0
void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) { void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
const tTimerConfig * const pConfig = &TimerConfig[timer_num]; const tTimerConfig * const pConfig = &TimerConfig[timer_num];
TC_SetRC(pConfig->pTimerRegs, pConfig->channel, count); TC_SetRC(pConfig->pTimerRegs, pConfig->channel, compare);
} }
void HAL_timer_isr_prologue(const uint8_t timer_num) { void HAL_timer_isr_prologue(const uint8_t timer_num) {

View file

@ -91,22 +91,22 @@ extern const tTimerConfig TimerConfig[];
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) { FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
const tTimerConfig * const pConfig = &TimerConfig[timer_num]; const tTimerConfig * const pConfig = &TimerConfig[timer_num];
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = count; pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC = compare;
} }
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) { FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
const tTimerConfig * const pConfig = &TimerConfig[timer_num]; const tTimerConfig * const pConfig = &TimerConfig[timer_num];
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC; return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_RC;
} }
FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) { FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
const tTimerConfig * const pConfig = &TimerConfig[timer_num]; const tTimerConfig * const pConfig = &TimerConfig[timer_num];
pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV = count; pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV = count;
} }
FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) { FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
const tTimerConfig * const pConfig = &TimerConfig[timer_num]; const tTimerConfig * const pConfig = &TimerConfig[timer_num];
return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV; return pConfig->pTimerRegs->TC_CHANNEL[pConfig->channel].TC_CV;
} }

View file

@ -87,22 +87,22 @@ typedef uint32_t hal_timer_t;
void HAL_timer_init(void); void HAL_timer_init(void);
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) { FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
switch (timer_num) { switch (timer_num) {
case 0: case 0:
LPC_TIM0->MR0 = count; LPC_TIM0->MR0 = compare;
if (LPC_TIM0->TC > count) if (LPC_TIM0->TC > compare)
LPC_TIM0->TC = count - 5; // generate an immediate stepper ISR LPC_TIM0->TC = compare - 5; // generate an immediate stepper ISR
break; break;
case 1: case 1:
LPC_TIM1->MR0 = count; LPC_TIM1->MR0 = compare;
if (LPC_TIM1->TC > count) if (LPC_TIM1->TC > compare)
LPC_TIM1->TC = count - 5; // make sure we don't have one extra long period LPC_TIM1->TC = compare - 5; // make sure we don't have one extra long period
break; break;
} }
} }
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) { FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
switch (timer_num) { switch (timer_num) {
case 0: return LPC_TIM0->MR0; case 0: return LPC_TIM0->MR0;
case 1: return LPC_TIM1->MR0; case 1: return LPC_TIM1->MR0;
@ -110,14 +110,14 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
return 0; return 0;
} }
FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) { FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
switch (timer_num) { switch (timer_num) {
case 0: LPC_TIM0->TC = count; break; case 0: LPC_TIM0->TC = count; break;
case 1: LPC_TIM1->TC = count; break; case 1: LPC_TIM1->TC = count; break;
} }
} }
FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) { FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
switch (timer_num) { switch (timer_num) {
case 0: return LPC_TIM0->TC; case 0: return LPC_TIM0->TC;
case 1: return LPC_TIM1->TC; case 1: return LPC_TIM1->TC;

View file

@ -46,7 +46,7 @@
typedef uint16_t hal_timer_t; typedef uint16_t hal_timer_t;
#define HAL_TIMER_TYPE_MAX 0xFFFF #define HAL_TIMER_TYPE_MAX 0xFFFF
#if defined MCU_STM32F103CB || defined(MCU_STM32F103C8) #if defined(MCU_STM32F103CB) || defined(MCU_STM32F103C8)
#define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4 #define STEP_TIMER_NUM 4 // For C8/CB boards, use timer 4
#else #else
#define STEP_TIMER_NUM 5 // for other boards, five is fine. #define STEP_TIMER_NUM 5 // for other boards, five is fine.
@ -82,8 +82,8 @@ typedef uint16_t hal_timer_t;
#define ENABLE_TEMPERATURE_INTERRUPT() timer_enable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN) #define ENABLE_TEMPERATURE_INTERRUPT() timer_enable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
#define DISABLE_TEMPERATURE_INTERRUPT() timer_disable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN) #define DISABLE_TEMPERATURE_INTERRUPT() timer_disable_irq(TEMP_TIMER_DEV, TEMP_TIMER_CHAN)
#define HAL_timer_get_current_count(timer_num) timer_get_count(TIMER_DEV(timer_num)) #define HAL_timer_get_count(timer_num) timer_get_count(TIMER_DEV(timer_num))
#define HAL_timer_set_current_count(timer_num, count) timer_set_count(TIMER_DEV(timer_num), (uint16)count) #define HAL_timer_set_count(timer_num, count) timer_set_count(TIMER_DEV(timer_num), (uint16)count)
#define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0) #define HAL_ENABLE_ISRs() do { if (thermalManager.in_temp_isr)DISABLE_TEMPERATURE_INTERRUPT(); else ENABLE_TEMPERATURE_INTERRUPT(); ENABLE_STEPPER_DRIVER_INTERRUPT(); } while(0)
@ -128,21 +128,21 @@ bool HAL_timer_interrupt_enabled(const uint8_t timer_num);
* Todo: Look at that possibility later. * Todo: Look at that possibility later.
*/ */
FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) { FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
//count = min(count, HAL_TIMER_TYPE_MAX); //compare = min(compare, HAL_TIMER_TYPE_MAX);
switch (timer_num) { switch (timer_num) {
case STEP_TIMER_NUM: case STEP_TIMER_NUM:
timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, count); timer_set_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN, compare);
return; return;
case TEMP_TIMER_NUM: case TEMP_TIMER_NUM:
timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, count); timer_set_compare(TEMP_TIMER_DEV, TEMP_TIMER_CHAN, compare);
return; return;
default: default:
return; return;
} }
} }
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) { FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
switch (timer_num) { switch (timer_num) {
case STEP_TIMER_NUM: case STEP_TIMER_NUM:
return timer_get_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN); return timer_get_compare(STEP_TIMER_DEV, STEP_TIMER_CHAN);

View file

@ -117,11 +117,11 @@ extern "C" void TIM7_IRQHandler() {
((void(*)(void))timerConfig[1].callback)(); ((void(*)(void))timerConfig[1].callback)();
} }
void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) { void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare) {
__HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, count); __HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, compare);
} }
void HAL_timer_set_current_count(const uint8_t timer_num, const uint32_t count) { void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count) {
__HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, count); __HAL_TIM_SetAutoreload(&timerConfig[timer_num].timerdef, count);
} }
@ -133,11 +133,11 @@ void HAL_timer_disable_interrupt(const uint8_t timer_num) {
HAL_NVIC_DisableIRQ(timerConfig[timer_num].IRQ_Id); HAL_NVIC_DisableIRQ(timerConfig[timer_num].IRQ_Id);
} }
hal_timer_t HAL_timer_get_count(const uint8_t timer_num) { hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
return __HAL_TIM_GetAutoreload(&timerConfig[timer_num].timerdef); return __HAL_TIM_GetAutoreload(&timerConfig[timer_num].timerdef);
} }
uint32_t HAL_timer_get_current_count(const uint8_t timer_num) { uint32_t HAL_timer_get_count(const uint8_t timer_num) {
return __HAL_TIM_GetCounter(&timerConfig[timer_num].timerdef); return __HAL_TIM_GetCounter(&timerConfig[timer_num].timerdef);
} }

View file

@ -91,12 +91,12 @@ void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
void HAL_timer_enable_interrupt(const uint8_t timer_num); void HAL_timer_enable_interrupt(const uint8_t timer_num);
void HAL_timer_disable_interrupt(const uint8_t timer_num); void HAL_timer_disable_interrupt(const uint8_t timer_num);
void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count); void HAL_timer_set_compare(const uint8_t timer_num, const uint32_t compare);
hal_timer_t HAL_timer_get_count(const uint8_t timer_num); hal_timer_t HAL_timer_get_compare(const uint8_t timer_num);
uint32_t HAL_timer_get_current_count(const uint8_t timer_num); uint32_t HAL_timer_get_count(const uint8_t timer_num);
void HAL_timer_set_current_count(const uint8_t timer_num, const uint32_t count); // New void HAL_timer_set_count(const uint8_t timer_num, const uint32_t count); // New
/*FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) { /*FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
// To do ?? // To do ??
}*/ }*/

View file

@ -80,14 +80,14 @@ typedef uint32_t hal_timer_t;
void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency); void HAL_timer_start(const uint8_t timer_num, const uint32_t frequency);
FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) { FORCE_INLINE static void HAL_timer_set_compare(const uint8_t timer_num, const hal_timer_t compare) {
switch (timer_num) { switch (timer_num) {
case 0: FTM0_C0V = count; break; case 0: FTM0_C0V = compare; break;
case 1: FTM1_C0V = count; break; case 1: FTM1_C0V = compare; break;
} }
} }
FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) { FORCE_INLINE static hal_timer_t HAL_timer_get_compare(const uint8_t timer_num) {
switch (timer_num) { switch (timer_num) {
case 0: return FTM0_C0V; case 0: return FTM0_C0V;
case 1: return FTM1_C0V; case 1: return FTM1_C0V;
@ -95,14 +95,14 @@ FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
return 0; return 0;
} }
FORCE_INLINE static void HAL_timer_set_current_count(const uint8_t timer_num, const hal_timer_t count) { FORCE_INLINE static void HAL_timer_set_count(const uint8_t timer_num, const hal_timer_t count) {
switch (timer_num) { switch (timer_num) {
case 0: FTM0_CNT = count; case 0: FTM0_CNT = count;
case 1: FTM1_CNT = count; case 1: FTM1_CNT = count;
} }
} }
FORCE_INLINE static hal_timer_t HAL_timer_get_current_count(const uint8_t timer_num) { FORCE_INLINE static hal_timer_t HAL_timer_get_count(const uint8_t timer_num) {
switch (timer_num) { switch (timer_num) {
case 0: return FTM0_CNT; case 0: return FTM0_CNT;
case 1: return FTM1_CNT; case 1: return FTM1_CNT;

View file

@ -371,7 +371,7 @@ void Stepper::isr() {
#if DISABLED(LIN_ADVANCE) #if DISABLED(LIN_ADVANCE)
#ifdef CPU_32_BIT #ifdef CPU_32_BIT
HAL_timer_set_count(STEP_TIMER_NUM, ocr_val); HAL_timer_set_compare(STEP_TIMER_NUM, ocr_val);
#else #else
NOLESS(OCR1A, TCNT1 + 16); NOLESS(OCR1A, TCNT1 + 16);
#endif #endif
@ -560,7 +560,7 @@ void Stepper::isr() {
* 10µs = 160 or 200 cycles. * 10µs = 160 or 200 cycles.
*/ */
#if EXTRA_CYCLES_XYZE > 20 #if EXTRA_CYCLES_XYZE > 20
hal_timer_t pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM); hal_timer_t pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
#endif #endif
#if HAS_X_STEP #if HAS_X_STEP
@ -592,8 +592,8 @@ void Stepper::isr() {
// For minimum pulse time wait before stopping pulses // For minimum pulse time wait before stopping pulses
#if EXTRA_CYCLES_XYZE > 20 #if EXTRA_CYCLES_XYZE > 20
while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ } while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM); pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
#elif EXTRA_CYCLES_XYZE > 0 #elif EXTRA_CYCLES_XYZE > 0
DELAY_NOPS(EXTRA_CYCLES_XYZE); DELAY_NOPS(EXTRA_CYCLES_XYZE);
#endif #endif
@ -633,7 +633,7 @@ void Stepper::isr() {
// For minimum pulse time wait after stopping pulses also // For minimum pulse time wait after stopping pulses also
#if EXTRA_CYCLES_XYZE > 20 #if EXTRA_CYCLES_XYZE > 20
if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ } if (i) while (EXTRA_CYCLES_XYZE > (uint32_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
#elif EXTRA_CYCLES_XYZE > 0 #elif EXTRA_CYCLES_XYZE > 0
if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE); if (i) DELAY_NOPS(EXTRA_CYCLES_XYZE);
#endif #endif
@ -750,9 +750,9 @@ void Stepper::isr() {
#if DISABLED(LIN_ADVANCE) #if DISABLED(LIN_ADVANCE)
#ifdef CPU_32_BIT #ifdef CPU_32_BIT
// Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room // Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room
hal_timer_t stepper_timer_count = HAL_timer_get_count(STEP_TIMER_NUM), hal_timer_t stepper_timer_count = HAL_timer_get_compare(STEP_TIMER_NUM),
stepper_timer_current_count = HAL_timer_get_current_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US; stepper_timer_current_count = HAL_timer_get_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US;
HAL_timer_set_count(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count)); HAL_timer_set_compare(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count));
#else #else
NOLESS(OCR1A, TCNT1 + 16); NOLESS(OCR1A, TCNT1 + 16);
#endif #endif
@ -814,7 +814,7 @@ void Stepper::isr() {
for (uint8_t i = step_loops; i--;) { for (uint8_t i = step_loops; i--;) {
#if EXTRA_CYCLES_E > 20 #if EXTRA_CYCLES_E > 20
hal_timer_t pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM); hal_timer_t pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
#endif #endif
START_E_PULSE(0); START_E_PULSE(0);
@ -833,8 +833,8 @@ void Stepper::isr() {
// For minimum pulse time wait before stopping pulses // For minimum pulse time wait before stopping pulses
#if EXTRA_CYCLES_E > 20 #if EXTRA_CYCLES_E > 20
while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ } while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
pulse_start = HAL_timer_get_current_count(PULSE_TIMER_NUM); pulse_start = HAL_timer_get_count(PULSE_TIMER_NUM);
#elif EXTRA_CYCLES_E > 0 #elif EXTRA_CYCLES_E > 0
DELAY_NOPS(EXTRA_CYCLES_E); DELAY_NOPS(EXTRA_CYCLES_E);
#endif #endif
@ -855,7 +855,7 @@ void Stepper::isr() {
// For minimum pulse time wait before looping // For minimum pulse time wait before looping
#if EXTRA_CYCLES_E > 20 #if EXTRA_CYCLES_E > 20
if (i) while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_current_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ } if (i) while (EXTRA_CYCLES_E > (hal_timer_t)(HAL_timer_get_count(PULSE_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
#elif EXTRA_CYCLES_E > 0 #elif EXTRA_CYCLES_E > 0
if (i) DELAY_NOPS(EXTRA_CYCLES_E); if (i) DELAY_NOPS(EXTRA_CYCLES_E);
#endif #endif
@ -878,7 +878,7 @@ void Stepper::isr() {
// Is the next advance ISR scheduled before the next main ISR? // Is the next advance ISR scheduled before the next main ISR?
if (nextAdvanceISR <= nextMainISR) { if (nextAdvanceISR <= nextMainISR) {
// Set up the next interrupt // Set up the next interrupt
HAL_timer_set_count(STEP_TIMER_NUM, nextAdvanceISR); HAL_timer_set_compare(STEP_TIMER_NUM, nextAdvanceISR);
// New interval for the next main ISR // New interval for the next main ISR
if (nextMainISR) nextMainISR -= nextAdvanceISR; if (nextMainISR) nextMainISR -= nextAdvanceISR;
// Will call Stepper::advance_isr on the next interrupt // Will call Stepper::advance_isr on the next interrupt
@ -886,7 +886,7 @@ void Stepper::isr() {
} }
else { else {
// The next main ISR comes first // The next main ISR comes first
HAL_timer_set_count(STEP_TIMER_NUM, nextMainISR); HAL_timer_set_compare(STEP_TIMER_NUM, nextMainISR);
// New interval for the next advance ISR, if any // New interval for the next advance ISR, if any
if (nextAdvanceISR && nextAdvanceISR != ADV_NEVER) if (nextAdvanceISR && nextAdvanceISR != ADV_NEVER)
nextAdvanceISR -= nextMainISR; nextAdvanceISR -= nextMainISR;
@ -897,9 +897,9 @@ void Stepper::isr() {
// Don't run the ISR faster than possible // Don't run the ISR faster than possible
#ifdef CPU_32_BIT #ifdef CPU_32_BIT
// Make sure stepper interrupt does not monopolise CPU by adjusting count to give about 8 us room // 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_count = HAL_timer_get_compare(STEP_TIMER_NUM),
stepper_timer_current_count = HAL_timer_get_current_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US; stepper_timer_current_count = HAL_timer_get_count(STEP_TIMER_NUM) + 8 * HAL_TICKS_PER_US;
HAL_timer_set_count(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count)); HAL_timer_set_compare(STEP_TIMER_NUM, max(stepper_timer_count, stepper_timer_current_count));
#else #else
NOLESS(OCR1A, TCNT1 + 16); NOLESS(OCR1A, TCNT1 + 16);
#endif #endif
@ -1304,8 +1304,8 @@ void Stepper::report_positions() {
#define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true) #define _APPLY_DIR(AXIS, INVERT) AXIS ##_APPLY_DIR(INVERT, true)
#if EXTRA_CYCLES_BABYSTEP > 20 #if EXTRA_CYCLES_BABYSTEP > 20
#define _SAVE_START const hal_timer_t pulse_start = HAL_timer_get_current_count(STEP_TIMER_NUM) #define _SAVE_START const hal_timer_t pulse_start = HAL_timer_get_count(STEP_TIMER_NUM)
#define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(HAL_timer_get_current_count(STEP_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ } #define _PULSE_WAIT while (EXTRA_CYCLES_BABYSTEP > (uint32_t)(HAL_timer_get_count(STEP_TIMER_NUM) - pulse_start) * (PULSE_TIMER_PRESCALE)) { /* nada */ }
#else #else
#define _SAVE_START NOOP #define _SAVE_START NOOP
#if EXTRA_CYCLES_BABYSTEP > 0 #if EXTRA_CYCLES_BABYSTEP > 0

View file

@ -108,7 +108,7 @@ class Stepper {
// i.e., the current amount of pressure applied // i.e., the current amount of pressure applied
// to the spring (=filament). // to the spring (=filament).
#else #else
#define _NEXT_ISR(T) HAL_timer_set_count(STEP_TIMER_NUM, T); #define _NEXT_ISR(T) HAL_timer_set_compare(STEP_TIMER_NUM, T);
#endif // LIN_ADVANCE #endif // LIN_ADVANCE
static long acceleration_time, deceleration_time; static long acceleration_time, deceleration_time;