Skip to content

Commit fedf789

Browse files
authored
Merge pull request #372 from maidnl/fix_rounding_error_pwm_pulse
Core Renesas / PWM / fixing wrong pulse setting
2 parents 4606b85 + a2ae013 commit fedf789

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

Diff for: cores/arduino/FspTimer.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,11 @@ bool FspTimer::set_pulse_ms(double ms,TimerPWMChannel_t pwm_ch) {
380380
freq_hz = R_FSP_SystemClockHzGet(FSP_PRIV_CLOCK_PCLKB) >> timer_cfg.source_div;
381381
}
382382

383-
uint32_t pulse_counts_ms = (uint32_t) ((uint64_t) freq_hz/1000 * ms);
383+
uint32_t pulse_counts_ms = (uint32_t) ((uint64_t) (freq_hz * ms)/1000);
384384
if(!set_duty_cycle(pulse_counts_ms, pwm_ch)) {
385385
return false;
386386
}
387-
388-
return true;
389-
387+
return true;
390388
}
391389

392390
/* -------------------------------------------------------------------------- */
@@ -399,12 +397,11 @@ bool FspTimer::set_pulse_us(double us,TimerPWMChannel_t pwm_ch) {
399397
else if(type == AGT_TIMER){
400398
freq_hz = R_FSP_SystemClockHzGet(FSP_PRIV_CLOCK_PCLKB) >> timer_cfg.source_div;
401399
}
402-
403-
uint32_t pulse_counts_us = (uint32_t) ((uint64_t) freq_hz/1000000 * us);
400+
401+
uint32_t pulse_counts_us = (uint32_t) ((uint64_t) (freq_hz * us)/1000000 );
404402
if(!set_duty_cycle(pulse_counts_us, pwm_ch)) {
405403
return false;
406404
}
407-
408405
return true;
409406
}
410407

0 commit comments

Comments
 (0)