The PWM_FRACTION_TO_WIDTH seems tailored for 16 bits timer :
Code: Select all
#define PWM_FRACTION_TO_WIDTH(pwmp, denominator, numerator) \
((pwmcnt_t)((((pwmcnt_t)(pwmp)->period) * \
(pwmcnt_t)(numerator)) / (pwmcnt_t)(denominator)))
In case of 32 bits timers, period can be large, and period * numerator can overflow.
Is it possible to replace the three last pwmcnt_t casts by uint64_t casts ?
There will be some runtime overhead, but PWM_FRACTION_TO_WIDTH should not be called from a hot path code.
Alexandre