Skip to content

Commit ff6744c

Browse files
author
Cruz Monrreal
authored
Merge pull request #9105 from LaurentLouf/improve-precision-duty-cycle-pwm-stm
Add some rounding to determine the pulse value for PWM for the STM target
2 parents 0100ced + db3f05e commit ff6744c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

targets/TARGET_STM/pwmout_api.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ void pwmout_write(pwmout_t *obj, float value)
182182
value = 1.0;
183183
}
184184

185-
obj->pulse = (uint32_t)((float)obj->period * value);
185+
obj->pulse = (uint32_t)((float)obj->period * value + 0.5);
186186

187187
// Configure channels
188188
sConfig.OCMode = TIM_OCMODE_PWM1;

0 commit comments

Comments
 (0)