Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit 476dc6e

Browse files
committed
Fix for PWM output found by testing against FPGA shield
Two issues: * Downcasting too early * Potential for a uint32_t overflow in an intermediate calculation Passing test requires ARMmbed#11005 to be merged.
1 parent 28eb39c commit 476dc6e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

targets/TARGET_Silicon_Labs/TARGET_EFM32/pwmout_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,13 @@ void pwmout_pulsewidth(pwmout_t *obj, float seconds)
342342

343343
void pwmout_pulsewidth_ms(pwmout_t *obj, int ms)
344344
{
345-
uint16_t width_cycles = (uint16_t) ((REFERENCE_FREQUENCY >> pwm_prescaler_div) * ms) / 1000;
345+
uint16_t width_cycles = (uint16_t) (((REFERENCE_FREQUENCY >> pwm_prescaler_div) * ms) / 1000);
346346
TIMER_CompareBufSet(PWM_TIMER, obj->channel, width_cycles);
347347
}
348348

349349
void pwmout_pulsewidth_us(pwmout_t *obj, int us)
350350
{
351-
uint16_t width_cycles = (uint16_t) ((REFERENCE_FREQUENCY >> pwm_prescaler_div) * us) / 1000000;
351+
uint16_t width_cycles = (uint16_t) (((uint64_t)(REFERENCE_FREQUENCY >> pwm_prescaler_div) * (uint64_t)us) / 1000000UL);
352352
TIMER_CompareBufSet(PWM_TIMER, obj->channel, width_cycles);
353353
}
354354

0 commit comments

Comments
 (0)