How to use LEDC with inverted pin?
Posted: Tue Aug 31, 2021 4:16 pm
Hi all,
I have a LED I need to control with LEDC for PWM. The pin is inverted in the hardware, i.e. 1 is off, 0 is on. The LEDC API expects the opposite. I've sort of fixed this by inverting my duty cycle, and that works fine, but when I first enable the LEDC channel there is a very brief flicker where the LED turns on before turning off.
Here is how I am configuring LEDC:
The flicker happens in the call to ledc_channel_config. Before that call the LED is off, during the call it turns on very briefly, and when the call returns it is off again.
So, question: Is there a specific way I should use LEDC with an inverted pin?
And follow up question: Is there a way to avoid the brief "on" before it turns "off"?
Thanks,
Jason
I have a LED I need to control with LEDC for PWM. The pin is inverted in the hardware, i.e. 1 is off, 0 is on. The LEDC API expects the opposite. I've sort of fixed this by inverting my duty cycle, and that works fine, but when I first enable the LEDC channel there is a very brief flicker where the LED turns on before turning off.
Here is how I am configuring LEDC:
Code: Select all
// Configure LEDC for backlight PWM
ledc_timer_config_t ledc_timer = {
.duty_resolution = LEDC_DUTY_RESOLUTION,
.freq_hz = LEDC_FREQ,
.speed_mode = LEDC_SPEED_MODE,
.timer_num = LEDC_TIMER_1
};
ledc_timer_config(&ledc_timer);
ledc_channel_config_t ledc_channel = {
.channel = LEDC_CHANNEL_LCD_BL_BASE,
.duty = (1 << LEDC_DUTY_RESOLUTION) - 1,
.gpio_num = LCD_IO_BACKLIGHT_N,
.speed_mode = LEDC_SPEED_MODE,
.hpoint = 0,
.timer_sel = LEDC_TIMER_1
};
ledc_channel_config(&ledc_channel);
So, question: Is there a specific way I should use LEDC with an inverted pin?
And follow up question: Is there a way to avoid the brief "on" before it turns "off"?
Thanks,
Jason