esp8266/esppwm: Always start timer to avoid glitch from full to nonfull.

The PWM at full value was not considered as an "active" channel so if no
other channel was used the timer used to mange PWM was not started.  So
when another duty value was set the PWM timer restarted and there was a
visible glitch when driving LEDs.  Such a glitch can be seen with the
following code (assuming active-low LED on pin 0):

    p = machine.PWM(machine.Pin(0))
    p.duty(1023) # full width, LED is off
    p.duty(1022) # LED flashes brightly then goes dim

This patch fixes the glitch.
pull/1/head
Olivier Ortigues 2018-02-23 15:41:51 +01:00 committed by Damien George
parent 0acf868bb7
commit b691aa0aae
1 changed files with 3 additions and 10 deletions

View File

@ -190,11 +190,8 @@ pwm_start(void)
// start
gpio_output_set(local_single[0].gpio_set, local_single[0].gpio_clear, pwm_gpio, 0);
// yeah, if all channels' duty is 0 or 255, don't need to start timer, otherwise start...
if (*local_channel != 1) {
pwm_timer_down = 0;
RTC_REG_WRITE(FRC1_LOAD_ADDRESS, local_single[0].h_time);
}
pwm_timer_down = 0;
RTC_REG_WRITE(FRC1_LOAD_ADDRESS, local_single[0].h_time);
}
if (pwm_toggle == 1) {
@ -319,11 +316,7 @@ pwm_tim1_intr_handler(void *dummy)
pwm_current_channel = 0;
if (*pwm_channel != 1) {
RTC_REG_WRITE(FRC1_LOAD_ADDRESS, pwm_single[pwm_current_channel].h_time);
} else {
pwm_timer_down = 1;
}
RTC_REG_WRITE(FRC1_LOAD_ADDRESS, pwm_single[pwm_current_channel].h_time);
} else {
gpio_output_set(pwm_single[pwm_current_channel].gpio_set,
pwm_single[pwm_current_channel].gpio_clear,