Inverting PWM signal on RGB Light

User avatar
fasani
Posts: 44
Joined: Wed Jan 30, 2019 12:00 pm
Location: Berlin
Contact:

Inverting PWM signal on RGB Light

Postby fasani » Wed Jan 30, 2019 12:15 pm

Hello all, I'm testing the Light example
https://github.com/espressif/esp-mdf/tr ... _kit/light

I tried to compile this and attach an RGB in the Gpios and works great:
https://twitter.com/martinfasani/status ... 5026150400

And as I have a lot of P-Channel mosfets in my garage and RGB leds I though to make my own demo Lights.

So the idea was to receive the PWM signal in the documented GPIOS:

GPIO4 O PWM_R output control
GPIO16 O PWM_G output control; alternate UART interface (URXD)
GPIO5 O PWM_B output control; alternate UART interface (UTXD)

And use them to feed the gate of a Mosfet. The issue is, that this P-Channel mosfets that I have, are closed on HIGH (Also it will be turning off on high instead of ON )
So I though to ask here to the electrical minds more advanced than mine...What would be the best way to go ?
To invert the PWM signal and still use a P-Channel Mosfet ? (Is that possible to do in the ESP32)

To use a different Mosfet that will open on HIGH ? (Tell me what model so I will look in the datasheet)
Or just comment how you will do it or what is wrong in my approach. Basically I would like to use the PWM signal to control many leds instead of just one.
Backend developer-PHP Engineer
https://fasani.de Berlin, Germany

costaud
Posts: 52
Joined: Wed Dec 30, 2015 5:09 pm

Re: Inverting PWM signal on RGB Light

Postby costaud » Thu Jan 31, 2019 3:36 am

I think the best and easiest way to do that is to invert the GPIO output signal in esp32.

Refer to func_out_sel_cfg register in components/soc/esp32/include/soc/gpio_struct.h.
For example, if you want to invert GPIO18, you can use the following code to do that, after initializing light driver.

Code: Select all

GPIO.func_out_sel_cfg[18].inv_sel = 1;  // invert the output of GPIO matrix.
We will add an interface into idf for this kind of scenario.

User avatar
fasani
Posts: 44
Joined: Wed Jan 30, 2019 12:00 pm
Location: Berlin
Contact:

Re: Inverting PWM signal on RGB Light

Postby fasani » Thu Jan 31, 2019 8:29 am

Thank you very much costaud!
That looks like the smartest solution since I can use the P-Channel mosfets.

I though also that we can power the RGB Channels directly from the GPIO, taking in account the they don't consume more than the allowed mA.
Will start a project in Hackaday to make your own smart lights with LED left overs:
https://hackaday.io/project/163672-esp3 ... led-panels

An alternative way without needing a lot of components is to use just one Quad Bus Buffer like 74H125 that supports up to 35 mA per output pin but has two great advantages:

- Separating the Logic from the Led power
- Being able to use another voltage ( In the 35 Leds example on the Hackaday page I'm using 5v instead of the 3.3v from PWM coming grom ESP32 )
Backend developer-PHP Engineer
https://fasani.de Berlin, Germany

User avatar
fasani
Posts: 44
Joined: Wed Jan 30, 2019 12:00 pm
Location: Berlin
Contact:

Re: Inverting PWM signal on RGB Light

Postby fasani » Tue Feb 05, 2019 7:05 am

Thanks!
Another option I found to separate the Logic from the Led power line, is to use one 74HC125 Quad Bus Buffer

Then you have the advantage of not soldiering 3 different components with a max output of 35 mA which is enough to power quite a lot of 5mm leds (35 in my case)
But I will try inverting the PWM in the next model just for fun, great solution!

Photos of the result: https://hackaday.io/project/163672-esp3 ... led-panels
Backend developer-PHP Engineer
https://fasani.de Berlin, Germany

Who is online

Users browsing this forum: No registered users and 5 guests