Re: LED controller PWM timer compare values
Posted: Tue Sep 13, 2022 5:42 pm
Thanks for the explanations. Somehow I can't get this to work. Whatever I do, either the inverted channels or now all channels flash up for an instant when booting. I could clearly see that only the inverted channels had flashed up before I applied your suggestions now. After trying the generic and then the LED-controller-integrated methods, and reverting everything, now all channels flash up at boot, apparently one after the other (but really quick). I don't know why. I even unplugged the power to reset everything.
After boot and initialisation (and the flashing), everything works normally. I set the LED channels according to user input, with every second channel set to PWM_MAXDUTY minus the actual value. The LED brightness is as expected. It's only the initialisation that is jerky.
Here's a part of my current code, for the initialisation:
After boot and initialisation (and the flashing), everything works normally. I set the LED channels according to user input, with every second channel set to PWM_MAXDUTY minus the actual value. The LED brightness is as expected. It's only the initialisation that is jerky.
Here's a part of my current code, for the initialisation:
Code: Select all
// Configure LED timers
ledc_timer_config_t ledc_timer = {
.duty_resolution = PWM_RESOLUTION,
.freq_hz = 2500,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.timer_num = LEDC_TIMER_0,
.clk_cfg = LEDC_AUTO_CLK,
};
ledc_timer_config(&ledc_timer);
// Configure LED channels
gpio_reset_pin(LED0_GPIO);
gpio_set_level(LED0_GPIO, 0);
gpio_set_direction(LED0_GPIO, GPIO_MODE_OUTPUT);
ledc_channel_config_t ledc_channel = {
.channel = LEDC_CHANNEL_0,
.gpio_num = LED0_GPIO,
.duty = 0,
.flags.output_invert = 0,
.speed_mode = LEDC_HIGH_SPEED_MODE,
.hpoint = 0,
.timer_sel = LEDC_TIMER_0};
ledc_channel_config(&ledc_channel);
// Every second channel is inverted (2, 4, 6, 8) to distribute the power load over time
if (CHANNELS >= 2)
{
gpio_reset_pin(LED1_GPIO);
gpio_set_level(LED1_GPIO, 0);
gpio_set_direction(LED1_GPIO, GPIO_MODE_OUTPUT);
ledc_channel.channel = LEDC_CHANNEL_1;
ledc_channel.gpio_num = LED1_GPIO;
ledc_channel.duty = PWM_MAXDUTY;
// new way:
ledc_channel.flags.output_invert = 1;
ledc_channel_config(&ledc_channel);
// old way:
//GPIO.func_out_sel_cfg[LED1_GPIO].inv_sel = 1;
// generic way:
//gpio_hal_iomux_func_sel(GPIO_PIN_MUX_REG[LED1_GPIO], PIN_FUNC_GPIO);
//gpio_set_direction(LED1_GPIO, GPIO_MODE_OUTPUT);
//esp_rom_gpio_connect_out_signal(LED1_GPIO, LEDC_HS_SIG_OUT1_IDX, true, false);
}
// Repeated for LED2...7