Is it possible to invert PWM without flashing this LED at setup using ESP32?

I am using this little breadboard circuit to test out some logic... I want to send inverted PWM to control this transistor which shunts the LED. The purpose of this is to work out an efficient way to do so with a high power LED driver as a way to achieve high frequency dimming beyond what most of those chips can do with their own PWM dimming pin.

Anyways the problem I run in to seems to be programmatic. If there is no way to do this programmatically I suppose I will just have to do it with hardware in the design. The setup code I am struggling with is as follows:

int frequency = 60;
int resolution = 8;
int testPin = 17;

void setup() {
  ledcSetup(0, frequency, resolution);
  ledcAttachPin(17, 0);
  GPIO.func_out_sel_cfg[testPin].inv_sel = 1;
  Serial.begin(115200); 
}

Now the problem as far as I can figure is that attaching the pin to the channel un-floats it thus making the pin drive the transistor LOW instead of the pull-up resistor keeping it HIGH which then sends all current to the LED until the next line which inverts the signal. Then 0 becomes HIGH at the transistor and the LED goes back to off as I want it to be. This flash is problematic and if there is no software way around it I guess I'll have to use hardware to invert the signal instead. Any ideas? I have tried various orders and lines of code manipulating pinmodes to no avail.

I'm not familiar with your board. The usual way to prevent the output from going LOW would be to first write a HIGH to the pin before setting the pin to output. Maybe you can do the same for the ESP or use ledcWrite() to set the dutycyle to 100% before attaching.

PS
I have a feeling that your schematic is wrong; but my knowldge of electronics is minimal.

Same, but it works, right OP?

The electronics seem to work here. At least on a breadboard it performs as expected. The problem is that I can't seem to avoid the LED being HIGH for a split second using this implementation of inverting the PWM. After setup() it's all good.

what transistor is it?

The circuit may work but it's a bizarre way to drive an LED, using the transistor to shunt the current otherwise passing through the LED! More common would be to just put the LED in series with the transistor and the 4K7.The 10k to Vcc is quite superfluous and can only give you problems, just try taking it out.

Also, Q1 should be an NPN transistor.

Q1 is actually an NPN in the breadboard. It's a 2222A. I chose the wrong symbol for the schematic.
Anyways what I'm going to end up doing is using an N-channel MOSFET for the final design and a gate driver which has an inverting input. Seems to be the simplest way to do what I want and get good performance. I found a good chip from TI that seems perfectly suited to my use.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.