Skip to content

Commit a2d0b02

Browse files
committed
[NANO130] Fix first PWM pulse may not be correct issue
1 parent 369d65f commit a2d0b02

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

targets/TARGET_NUVOTON/TARGET_NANO100/pwmout_api.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ void pwmout_init(pwmout_t* obj, PinName pin)
9090
obj->period_us = 1000 * 10;
9191
obj->pulsewidth_us = 0;
9292
pwmout_config(obj);
93+
// enable inverter to ensure the first PWM cycle is correct
94+
pwm_base->CTL |= (PWM_CTL_CH0INV_Msk << (chn * 8));
9395

9496
// Enable output of the specified PWM channel
9597
PWM_EnableOutput(pwm_base, 1 << chn);
@@ -200,7 +202,8 @@ static void pwmout_config(pwmout_t* obj)
200202
uint32_t chn = NU_MODSUBINDEX(obj->pwm);
201203
// NOTE: Support period < 1s
202204
//PWM_ConfigOutputChannel(pwm_base, chn, 1000 * 1000 / obj->period_us, obj->pulsewidth_us * 100 / obj->period_us);
203-
PWM_ConfigOutputChannel2(pwm_base, chn, 1000 * 1000, obj->pulsewidth_us * 100 / obj->period_us, obj->period_us);
205+
// enable inverter to ensure the first PWM cycle is correct
206+
PWM_ConfigOutputChannel2(pwm_base, chn, 1000 * 1000, 100 - (obj->pulsewidth_us * 100 / obj->period_us), obj->period_us);
204207
}
205208

206209
#endif

0 commit comments

Comments
 (0)