LEDC with OUTPUT_OPEN_DRAIN

iamflimflam1
Posts: 3
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: 3
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: 3
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.

Who is online

Users browsing this forum: Bing [Bot] and 16 guests