Interchange HIGH and LOW of PWM

panic mode

Joined Oct 10, 2011
5,281
I am doing experiments on photobiomodulation using pulsed Infrared LEDs. So one LED with one wavelength when it gives pulsing output, another wavelength LED can be used simultaneously with inverted power supply.
still does not explain why this has to be inverted phase but i guess you would want to change the duty cycle at some point and perhaps you want that to have a blend of different wavelengths controlled by PWM.
since chosen LEDs draw very little current, and GPIOs can both sink and source current, both LEDs can be driven by same GPIO. when GPIO is low , one LED is lit (D1), when it is high, the other LED is lit (D2). this way all you need is one extra resistor.

1789674976597.png
 
Last edited:

WBahn

Joined Mar 31, 2012
33,218
still does not explain why this has to be inverted phase but i guess you would want to change the duty cycle at some point and perhaps you want that to have a blend of different wavelengths controlled by PWM.
since chosen LEDs draw very little current, both can be driven by same GPIO. when GPIO is high, one LED is lit, when it is low, the other LED is lit. this way all you need is one extra resistor.

View attachment 371428
I use this arrangement to show bit status (HI/LO) on some digital logic demonstrator circuits in which students build gates using various discrete components, first manual switches, then relays, then MOSFETs. It has another advantage in that it shows floating signals because both LEDs turn on, albeit much more dimly, which is fine for my purposes.
 

Thread Starter

sab201

Joined Nov 18, 2023
322
still does not explain why this has to be inverted phase but i guess you would want to change the duty cycle at some point and perhaps you want that to have a blend of different wavelengths controlled by PWM.
since chosen LEDs draw very little current, and GPIOs can both sink and source current, both LEDs can be driven by same GPIO. when GPIO is low , one LED is lit (D1), when it is high, the other LED is lit (D2). this way all you need is one extra resistor.

View attachment 371429
LEDs have different voltages, one LED needs 5 Volts, another 0.8 Volt and 6 V depending upon their making for various wavelengths. So I have separate voltage sources with resistors to provide appropriate voltages and I need to pulse them.

No I wouldnt be changing duty cycles.
 

Ian0

Joined Aug 7, 2020
13,281
LEDs have different voltages, one LED needs 5 Volts, another 0.8 Volt and 6 V depending upon their making for various wavelengths. So I have separate voltage sources with resistors to provide appropriate voltages and I need to pulse them.

No I wouldnt be changing duty cycles.
Separate voltage sources? All you need is separate resistors. It is far more important to regulate the current to the LEDs. The voltage will sort itself out if you have the appropriate current.
 

Thread Starter

sab201

Joined Nov 18, 2023
322
Separate voltage sources? All you need is separate resistors. It is far more important to regulate the current to the LEDs. The voltage will sort itself out if you have the appropriate current.
I use a SMPS power supply for Desktop Computer. It has 3.3 V, 5 V and 12 V output. Based on LED's Forward Voltage and Forward current I calculate appropriate resistance and use it in series with LED.
 

MrChips

Joined Oct 2, 2009
35,194
I use a SMPS power supply for Desktop Computer. It has 3.3 V, 5 V and 12 V output. Based on LED's Forward Voltage and Forward current I calculate appropriate resistance and use it in series with LED.
Use the 12 V supply. A 10 kΩ series resistor will supply approx. 1 mA to the LED.
 

Thread Starter

sab201

Joined Nov 18, 2023
322
Or use a second output pin?
That is a possible solution, I m not sure how to modify the python program to send out an inverted PWM simultaneously in parellel in another pin.

I suppose Crutschow's inverter IC will work I will try it out seems to be a simpler solution.
 

Thread Starter

sab201

Joined Nov 18, 2023
322
Use the 12 V supply. A 10 kΩ series resistor will supply approx. 1 mA to the LED.
1 mA is not the current of the LED. It is the current drawn by a switching circuit that switches the supply voltage to the LED s. For each LED of different Vf, I use separate switching circuit.
 

LesJones

Joined Jan 8, 2017
4,544
I googled photobiomodulation to try to understand what I think you want. It seems that the to dose of betwee 5 anf 50 joules per square cm has been tried. But it does not say that for a dose of 5 jouls per square cm if that was delivered as 1 watt for 5 seconds or 10 watts for 0.5 seconds. Is this what your experiment is trying to determine ? (What is the optimum way a given dose is delivered.) So you want to be able to adjust the power level and the duration.
Les.
 
Last edited:

B-JoJo-S

Joined Jan 3, 2026
549
LEDs have different voltages, one LED needs 5 Volts, another 0.8 Volt and 6 V depending upon their making for various wavelengths.
What kind of LED's are you using? Ones I'm familiar with come in the following forward voltages: RED, typically around 2Vf. (mine is Super Bright 5mm Red at 1.95Vf). YELLOW: 2.01Vf. GREEN 2.92Vf. BLUE (3mm) 2.82Vf. WHITE 2.97Vf.

Those are the LED's I have. Those are the actual measured numbers based on running them at 10mA from a 5V supply. LED's are current based devices. You can power them from any voltage equal to or greater than their Vf. 3.3V, 5V, 12V, 24V, 100V • • • etc. You control them by limiting the current to them. If you use AC then you need to protect against reverse voltage breakdown. If you wanted to use 100V for a Yellow LED (such as mine) and you wanted it to run at mid range brightness (10mA) then you subtract the Vf from the source voltage. Then you divide the result by the desired amperage (0.01A) to get the proper resistance needed. THEN you have to calculate the total wattage and choose a resistor that can handle the wattage.

However, I still don't understand the need to have two pulses that are 180˚ out of phase. Going on that premises; I'd use a flip flop to separate the two phases. With each clock pulse the FF changes from Q HIGH and NOT-Q LOW to Q LOW and NOT-Q HIGH. Now you have two signals that are at 50% and always 180˚ out of phase.

I'm not certain that is what you're after, but from what I've read so far it seems like you're dead set on having two square waves 180˚ out of phase.
 

B-JoJo-S

Joined Jan 3, 2026
549
For clarity:
The 555 produces the clock pulse rate you desire. It doesn't need to be 50%. You can even use whatever clock source you choose. The 4013 (half shown) has two outputs "Q" and "NOT-Q". (NOT-Q has the bar over the Q) One is exact opposite of the other. That will give you two square waves simultaneously and at the same frequency. One is high when the other is low. Always.

Screenshot 2026-09-18 at 6.15.15 AM.png
I don't know off hand how much current the 4013 can sink or source. For that you'll have to look up the data sheet. I show a CMOS chip in my diagram. There are other versions with different current characteristics. This is my approach to give you the two opposing square waves.
 
Last edited:

MrChips

Joined Oct 2, 2009
35,194
1 mA is not the current of the LED. It is the current drawn by a switching circuit that switches the supply voltage to the LED s. For each LED of different Vf, I use separate switching circuit.
I used that as an example. Use 500 Ω if you want 20 mA LED current.
 

MisterBill2

Joined Jan 23, 2018
28,344
For the simplest inversion scheme to drive LEDs, use a CMOS HEX INVERTER/BUFFER (CD4049) IC!if you set the voltage to the proper level, the current will be OK for many LED types. And no series resistor required in the drive circuit.
 
That is a possible solution, I m not sure how to modify the python program to send out an inverted PWM simultaneously in parellel in another pin.
I’d argue, that’s the problem you need to solve, it’s a coding problem, forget the additional hardware. I guess it depends on the complexity of the code in your application and how important the delay between one output changing and the other output changing, but if you sniff the output with a second pin and invert in code to drive another output pin, unless it’s needed to run blisteringly fast that should do it.

Maybe post the relevant bit of code?
 
Top