Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fedf789

Browse filesBrowse 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
Copy full SHA for fedf789

File tree

1 file changed

+4
-7
lines changed
Filter options

1 file changed

+4
-7
lines changed

‎cores/arduino/FspTimer.cpp

Copy file name to clipboardExpand all lines: cores/arduino/FspTimer.cpp
+4-7Lines changed: 4 additions & 7 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.