Skip to content

Commit 65d37f1

Browse files
HardwareTimer: Allow setting preload enable bits
1 parent 16f211c commit 65d37f1

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

cores/arduino/HardwareTimer.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,28 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin)
677677
}
678678
}
679679

680+
/**
681+
* @brief Enable or disable preloading for overflow value
682+
* When disabled, changes to the overflow value take effect
683+
* immediately. When enabled, the value takes effect only at
684+
* the next update event (typically the next overflow).
685+
*
686+
* Note that the capture/compare register has its own preload
687+
* enable bit, which is independent and enabled in PWM modes
688+
* and disabled otherwise. If you need more control of that
689+
* bit, you can use the HAL functions directly.
690+
* @param value: true to enable preloading, false to disable
691+
* @retval None
692+
*/
693+
void HardwareTimer::setPreloadEnable(bool value)
694+
{
695+
if (value) {
696+
LL_TIM_EnableARRPreload(_timerObj.handle.Instance);
697+
} else {
698+
LL_TIM_DisableARRPreload(_timerObj.handle.Instance);
699+
}
700+
}
701+
680702
/**
681703
* @brief Set channel Capture/Compare register
682704
* @param channel: Arduino channel [1..4]

cores/arduino/HardwareTimer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ class HardwareTimer {
118118
void setMode(uint32_t channel, TimerModes_t mode, PinName pin = NC); // Configure timer channel with specified mode on specified pin if available
119119
void setMode(uint32_t channel, TimerModes_t mode, uint32_t pin);
120120

121+
void setPreloadEnable(bool value); // Configure overflow preload enable setting
122+
121123
uint32_t getCaptureCompare(uint32_t channel, TimerCompareFormat_t format = TICK_COMPARE_FORMAT); // return Capture/Compare register value of specified channel depending on format provided
122124
void setCaptureCompare(uint32_t channel, uint32_t compare, TimerCompareFormat_t format = TICK_COMPARE_FORMAT); // set Compare register value of specified channel depending on format provided
123125

0 commit comments

Comments
 (0)