Skip to content

Commit b691aa0

Browse files
EddieParisdpgeorge
authored andcommitted
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.
1 parent 0acf868 commit b691aa0

File tree

1 file changed

+3
-10
lines changed

1 file changed

+3
-10
lines changed

ports/esp8266/esppwm.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,8 @@ pwm_start(void)
190190
// start
191191
gpio_output_set(local_single[0].gpio_set, local_single[0].gpio_clear, pwm_gpio, 0);
192192

193-
// yeah, if all channels' duty is 0 or 255, don't need to start timer, otherwise start...
194-
if (*local_channel != 1) {
195-
pwm_timer_down = 0;
196-
RTC_REG_WRITE(FRC1_LOAD_ADDRESS, local_single[0].h_time);
197-
}
193+
pwm_timer_down = 0;
194+
RTC_REG_WRITE(FRC1_LOAD_ADDRESS, local_single[0].h_time);
198195
}
199196

200197
if (pwm_toggle == 1) {
@@ -319,11 +316,7 @@ pwm_tim1_intr_handler(void *dummy)
319316

320317
pwm_current_channel = 0;
321318

322-
if (*pwm_channel != 1) {
323-
RTC_REG_WRITE(FRC1_LOAD_ADDRESS, pwm_single[pwm_current_channel].h_time);
324-
} else {
325-
pwm_timer_down = 1;
326-
}
319+
RTC_REG_WRITE(FRC1_LOAD_ADDRESS, pwm_single[pwm_current_channel].h_time);
327320
} else {
328321
gpio_output_set(pwm_single[pwm_current_channel].gpio_set,
329322
pwm_single[pwm_current_channel].gpio_clear,

0 commit comments

Comments
 (0)