Skip to content

Core Renesas / PWM / fixing wrong pulse setting #372

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading