LEDC output low configuration how to

chadpham75
Posts: 48
Joined: Thu Sep 12, 2019 11:39 am

LEDC output low configuration how to

Postby chadpham75 » Tue Sep 24, 2019 7:07 am

Hi all,
I use LEDC driver to configure the pwm to drive my leds. The hardware team designed the gpios to control the on/off by signal low/high.
However, I need to configure the output gpios as the high output at the power up to prevent the glitch at the power up at these pins.
This is what I have to do to prevent the glitches
During the pwm initialization I called
1. ledc_channel_config(), which will call
2. gpio_set_direction() which in turn will call
3. gpio_output_enable().
In this function I have to do 2 modifications: change GPIO.enable_w1ts to GPIO.enable_w1tc and call gpio_set_level to 1
static esp_err_t gpio_output_enable2(gpio_num_t gpio_num)
{
GPIO_CHECK(GPIO_IS_VALID_OUTPUT_GPIO(gpio_num), "GPIO output gpio_num error", ESP_ERR_INVALID_ARG);
if (gpio_num < 32) {
GPIO.enable_w1tc = (0x1 << gpio_num);
} else {
GPIO.enable1_w1tc.data = (0x1 << (gpio_num - 32));
}
gpio_set_level(gpio_num, 1); // DT
gpio_matrix_out(gpio_num, SIG_GPIO_OUT_IDX, false, false);
return ESP_OK;
}
I would like to keep the SDK driver the same and only use the app layer to configure the pwm channels. Is there any API or different ways to configure pwm as output high at the power up?
Thank you so much for your helps.

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: LEDC output low configuration how to

Postby WiFive » Tue Sep 24, 2019 8:59 am

Did you try just calling

Code: Select all

gpio_set_level(gpio_num, 1)
first?

chadpham75
Posts: 48
Joined: Thu Sep 12, 2019 11:39 am

Re: LEDC output low configuration how to

Postby chadpham75 » Tue Sep 24, 2019 10:25 am

I did tried but it didn't help. Still see all the LEDs flashing at the power up.
Just to clarify, did you suggested
1. gpio_set_level(gpio_num, 1)
2. then ledc_channel_config()

chadpham75
Posts: 48
Joined: Thu Sep 12, 2019 11:39 am

Re: LEDC output low configuration how to

Postby chadpham75 » Tue Sep 24, 2019 3:45 pm

Also the one needed mod is

if (gpio_num < 32) {
GPIO.enable_w1tc = (0x1 << gpio_num);
} else {
GPIO.enable1_w1tc.data = (0x1 << (gpio_num - 32));
}

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: LEDC output low configuration how to

Postby WiFive » Tue Sep 24, 2019 10:40 pm

Ok but that disables the output

chadpham75
Posts: 48
Joined: Thu Sep 12, 2019 11:39 am

Re: LEDC output low configuration how to

Postby chadpham75 » Wed Sep 25, 2019 12:13 am

@WiFive
That is the point
The original code in the SDK is
if (gpio_num < 32) {
GPIO.enable_w1ts = (0x1 << gpio_num);
} else {
GPIO.enable1_w1ts.data = (0x1 << (gpio_num - 32));
}

If I keep this, at the power up, all the LEDs will flash once, I have to change to
if (gpio_num < 32) {
GPIO.enable_w1tc = (0x1 << gpio_num);
} else {
GPIO.enable1_w1tc.data = (0x1 << (gpio_num - 32));
}
In order for the LEDs are not flashing at the power up.

I am seeking the way to overwrite the SDK without actually modify the SDK itself.
I already have one solution that copy exactly the same source code and call them as the static function and place them on APP's space, but it seems double code defines.
I am trying to search for any API if there is any available that can achieve the same goal

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: LEDC output low configuration how to

Postby WiFive » Wed Sep 25, 2019 1:52 am

So then you manually enable the output later? You could create your own user_ledc_channel_config function.

chadpham75
Posts: 48
Joined: Thu Sep 12, 2019 11:39 am

Re: LEDC output low configuration how to

Postby chadpham75 » Wed Sep 25, 2019 6:26 am

@WiFive,
Yes, once I have all the gpios configured like that, to turn on/off the leds i will call
ledc_set_duty () and ledc_update_duty() with DutyCycle and 0 respectively, my Leds will be on/off.
The part I can't figure out is my method of before configure the gpios to ledc for pwm control, I tried to set gpio_set_level(gpio_num, 1), but someone (boot maybe) still pull the gpios low hence there was a glitch/flash at the power up.

Who is online

Users browsing this forum: asargent, Bing [Bot], Google [Bot] and 104 guests