Skip to content

Commit

Permalink
fix(hardwaretimer): avoid glitch when PWM configuration changed
Browse files Browse the repository at this point in the history
Fixes #2575.

Note that the issue is that TIM_OCx_SetConfig() disable
in unconditionally the N state output (TIM_CCER_CCxNE).

Signed-off-by: Frederic Pillon <[email protected]>
  • Loading branch information
fpistm committed Nov 21, 2024
1 parent 1df53a4 commit 6c30d95
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions libraries/SrcWrapper/src/HardwareTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,10 @@ void HardwareTimer::setPWM(uint32_t channel, uint32_t pin, uint32_t frequency, u
*/
void HardwareTimer::setPWM(uint32_t channel, PinName pin, uint32_t frequency, uint32_t dutycycle, callback_function_t PeriodCallback, callback_function_t CompareCallback)
{
setMode(channel, TIMER_OUTPUT_COMPARE_PWM1, pin);
TimerModes_t previousMode = getMode(channel);
if (previousMode != TIMER_OUTPUT_COMPARE_PWM1) {
setMode(channel, TIMER_OUTPUT_COMPARE_PWM1, pin);
}
setOverflow(frequency, HERTZ_FORMAT);
setCaptureCompare(channel, dutycycle, PERCENT_COMPARE_FORMAT);
if (PeriodCallback) {
Expand All @@ -934,7 +937,9 @@ void HardwareTimer::setPWM(uint32_t channel, PinName pin, uint32_t frequency, ui
if (CompareCallback) {
attachInterrupt(channel, CompareCallback);
}
resume();
if (previousMode != TIMER_OUTPUT_COMPARE_PWM1) {
resume();
}
}

/**
Expand Down

0 comments on commit 6c30d95

Please sign in to comment.