Skip to content

Commit

Permalink
Merge pull request #372 from maidnl/fix_rounding_error_pwm_pulse
Browse files Browse the repository at this point in the history
Core Renesas / PWM / fixing wrong pulse setting
  • Loading branch information
facchinm authored Sep 3, 2024
2 parents 4606b85 + a2ae013 commit fedf789
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions cores/arduino/FspTimer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,11 @@ bool FspTimer::set_pulse_ms(double ms,TimerPWMChannel_t pwm_ch) {
freq_hz = R_FSP_SystemClockHzGet(FSP_PRIV_CLOCK_PCLKB) >> timer_cfg.source_div;
}

uint32_t pulse_counts_ms = (uint32_t) ((uint64_t) freq_hz/1000 * ms);
uint32_t pulse_counts_ms = (uint32_t) ((uint64_t) (freq_hz * ms)/1000);
if(!set_duty_cycle(pulse_counts_ms, pwm_ch)) {
return false;
}

return true;

return true;
}

/* -------------------------------------------------------------------------- */
Expand All @@ -399,12 +397,11 @@ bool FspTimer::set_pulse_us(double us,TimerPWMChannel_t pwm_ch) {
else if(type == AGT_TIMER){
freq_hz = R_FSP_SystemClockHzGet(FSP_PRIV_CLOCK_PCLKB) >> timer_cfg.source_div;
}
uint32_t pulse_counts_us = (uint32_t) ((uint64_t) freq_hz/1000000 * us);

uint32_t pulse_counts_us = (uint32_t) ((uint64_t) (freq_hz * us)/1000000 );
if(!set_duty_cycle(pulse_counts_us, pwm_ch)) {
return false;
}

return true;
}

Expand Down

0 comments on commit fedf789

Please sign in to comment.