Skip to content

Commit 95cb038

Browse files
HardwareTimer: Enable preload for ARR/overflow register
This changes the default for preload (i.e. delay updating the overflow value until an update event such as timer overflow) to enabled, since this is will probably make the timer output behave as expected as much as possible (e.g. you cannot make it "skip" an overflow and run it all the way up to 0xffff by lowering the overflow value).
1 parent 531c587 commit 95cb038

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

cores/arduino/HardwareTimer.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ HardwareTimer::HardwareTimer(TIM_TypeDef *instance)
9393
#if defined(TIM_RCR_REP)
9494
_timerObj.handle.Init.RepetitionCounter = 0;
9595
#endif
96-
_timerObj.handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
96+
_timerObj.handle.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
9797
HAL_TIM_Base_Init(&(_timerObj.handle));
9898
}
9999

@@ -442,6 +442,11 @@ uint32_t HardwareTimer::getOverflow(TimerFormat_t format)
442442

443443
/**
444444
* @brief Set overflow (rollover)
445+
*
446+
* Note that by default, the new value will not be applied
447+
* immediately, but become effective at the next update event
448+
* (usually the next timer overflow). See setPreloadEnable()
449+
* for controlling this behaviour.
445450
* @param overflow: depend on format parameter
446451
* @param format of overflow parameter. If ommited default format is Tick
447452
* TICK_FORMAT: overflow is the number of tick for overflow
@@ -680,8 +685,9 @@ void HardwareTimer::setMode(uint32_t channel, TimerModes_t mode, PinName pin)
680685
/**
681686
* @brief Enable or disable preloading for overflow value
682687
* 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).
688+
* immediately. When enabled (the default), the value takes
689+
* effect only at the next update event (typically the next
690+
* overflow).
685691
*
686692
* Note that the capture/compare register has its own preload
687693
* enable bit, which is independent and enabled in PWM modes

0 commit comments

Comments
 (0)