LEDC with OUTPUT_OPEN_DRAIN

iamflimflam1
Posts: 12
Joined: Fri May 22, 2020 7:58 am

LEDC with OUTPUT_OPEN_DRAIN

Postby iamflimflam1 » Fri May 22, 2020 8:03 am

I'm using the LEDC functions to control a 3W LED so need to switch the LED using a MOSFET.

I can't seem to use the output pin in open drain mode when using PWM - not sure if I'm doing something wrong or if this is not possible. If I can set it to open drain then I can remove some components from my design.

Code: Select all

const int redPin = 17;
const int freq = 1000;
const int redChannel = 0;
const int resolution = 8;

pinMode(redPin, OUTPUT_OPEN_DRAIN); // doesn't seem to have any effect
ledcSetup(redChannel, freq, resolution);
ledcAttachPin(redPin, redChannel);

iamflimflam1
Posts: 12
Joined: Fri May 22, 2020 7:58 am

Re: LEDC with OUTPUT_OPEN_DRAIN

Postby iamflimflam1 » Fri May 22, 2020 8:30 am

To partly answer my own question - just found the code in the esp32-hal-ledc.c file for ledAttachPin:

Code: Select all

void ledcAttachPin(uint8_t pin, uint8_t chan)
{
    if(chan > 15) {
        return;
    }
    pinMode(pin, OUTPUT);
    pinMatrixOutAttach(pin, ((chan/8)?LEDC_LS_SIG_OUT0_IDX:LEDC_HS_SIG_OUT0_IDX) + (chan%8), false, false);
}
So I'm wondering if I move my pinMode to after I call this I will be able to switch into open drain mode...

iamflimflam1
Posts: 12
Joined: Fri May 22, 2020 7:58 am

Re: LEDC with OUTPUT_OPEN_DRAIN

Postby iamflimflam1 » Fri May 22, 2020 5:29 pm

Can confirm that this works. Moving the pinMode call to after the set up allows for open drain PWM.

ProtoTing
Posts: 2
Joined: Wed Jan 03, 2024 3:51 am

Re: LEDC with OUTPUT_OPEN_DRAIN

Postby ProtoTing » Wed Jan 03, 2024 4:38 am

Your trick did work so far for me too, moving the pinMode call to after the setup allowed for open drain PWM until now.
Now some Librairie changed or something else happened but using the same hardware as before and compiled the same firmware as before (with new librairies unfortunately) and nothing output from the GPIO while it should output PWM it is now continuously pulled low.
I tried putting pinMode call before the setup and it behaved as a regular push-pull output.
If anyone faces the same problem and succeeds in finding the workaround, please help.
How is it possible to output open_drain PWM? how to setup the GPIO?

ProtoTing
Posts: 2
Joined: Wed Jan 03, 2024 3:51 am

Re: LEDC with OUTPUT_OPEN_DRAIN

Postby ProtoTing » Thu Jan 04, 2024 1:31 am

I finally gave up and went back to the last working version 1.0.6 for the esp32 board manager in arduino IDE found here: https://dl.espressif.com/dl/package_esp32_index.json
2.0.10 and 2.0.11 can't output open drain pwm from everything I tried.

Who is online

Users browsing this forum: No registered users and 51 guests