PWM Brightness Control of Small Christmas Lights Using Enable Feature on Voltage Regulator
by kevinjwalters in Circuits > Electronics
162 Views, 1 Favorites, 0 Comments
PWM Brightness Control of Small Christmas Lights Using Enable Feature on Voltage Regulator
This project explores using a pulse-width modulated (PWM) signal on the enable pin of a voltage regulator for brightness control of LED lights. This demonstration is more of an exploration of what can be done with minimal components rather than the optimal or typical solution. An NPN transistor or logic-level MOSFET transistor is the standard, reliable, flexible solution for switching a larger load of a few hundred milliamps using a microcontroller's GPIO.
The enable feature, found on some voltage regulators, is likely to be intended for occasional toggling, perhaps a few times an hour. A PWM signal for LED brightness control at 200Hz is a far higher rate. The Unexpected Maker FeatherS2 board features an ESP32-S2 with a second controllable 3.3V voltage regulator, an Onsemi NCP167, intended for controlling the power to its peripherals. This microcontroller is used here to vary the brightness of a small set of 3V LED Christmas lights using PWM - these would normally be powered by two alkaline AA batteries.
The designer of the FeatherS2 does not recommend using this style of PWM control on the regulator's enable line.
Supplies
- Unexpected Maker FeatherS2: Adafruit | Pimoroni
- Small set of LED lights normally powered by two AA batteries, i.e. intended for 3V use, current measures 80mA on a multimeter for the ones used for this project.
- Female headers, two male-male jumper wires, two crocodile (alligator) clips for temporary connection to battery case.
The NCP167 Low Dropout Voltage Regulator
The FeatherS2 board has a second low-dropout (LDO) voltage regulator described by the manufacturer below.
The second LDO is for you to use to connect external 3V3 modules, sensors and peripherals, and the APA102 RGB LED, and it has programmable EN control tied to GPIO21 + it’s connected to the deep sleep capabilities of the S2, so if the S2 goes into deep sleep, the 2nd LDO is automatically shut down for you!
Both regulators are ultra low noise and have ultra low quiescent current, and both support a maximum of 700mA output.
This is shown in the schematic above as LDO2 with its enable line connected to the ESP32-S2 GPIO IO21 pin in conjunction with the SPI output voltage (VDD_SPI) from the ESP32-S2 using an AND gate.
The NCP167 voltage regulator block diagram is shown above from the datasheet. The datasheet also specifies a typical turn-on time with a 1uF Cout capacitor - "from assertion of Ven to Vout = 95% Vout(NOM) 120 microseconds.". This is quick at a fraction of a millisecond but it has implications for high frequency enabling/disabling using PWM.
The FeatherS2 schematic acts as a reminder that there's a BOOT button on the board. This button only has its boot-related effect when the ESP32-S2 is resetting. It can be used as an application button with a software pull up while the ESP32-S2 is running. The button is easily confused with the RST button but that's not a problem for this project.
Simple CircuitPython Demo Progam
If you are not familiar with CircuitPython then it's worth reading the Welcome to CircuitPython guide first.
- Install the latest version of CircuitPython (9.2.1 on December 2024) from https://circuitpython.org/ - this process is described for a similar ESP32-S2-based board in Adafruit ESP32-S2 Feather: CircuitPython.
- Verify the new installation by connecting to the serial console over USB. The REPL prompt shows the version number. The version can also be checked by inspecting the boot_out.txt file on the CIRCUITPY drive.
- Download the example program to CIRCUITPY by clicking Save link as... on pwm-secondldo.py.
- Rename or delete any existing code.py file on CIRCUITPY, then rename the pwm-secondldo.py to code.py. This file is run when the CircuitPython interpreter starts or reloads.
The versions used for this article were:
- CircuitPython: 9.2.1
Pressing the BOOT button while the programming is running toggles the mode, described below.
- Ramp up to full brightness and ramp down to off over 4 seconds.
- Random fluctuations.
The REPL command line can also be used for a quick simple test, see example below.
The 200Hz value has been chosen to ensure the LED flicker isn't noticeable.
Hardware Connectivity
The connectivity is very simple.
- 3V3O (red) to positive terminal on battery pack.
- GND (black) to negative terminal (typically a spring) on battery pack.
The use of jumper wires and crocodile clips isn't very neat but it's practical for casual testing. Soldered wires would be a better solution but these could also prevent reversion to normal battery power.
The batteries must not be present if the lights are being powered by the microcontroller.
Voltage Regulator - Enable Vs Output Voltage
The oscilloscope is showing:
- cyan - voltage regulator enable line;
- yellow - voltage across LED lights (loaded Vout from second regulator).
The enable line is a square wave from the PWM GPIO output as expected. The LED voltage can be seen to initially fall rapidly as the enable line falls but then drops more slowly when the voltage is below the forward voltage of the LEDs.
One surprise here is the peak 3.3V regulator output voltage does not match the enable 3.3V signal. This is partly explained by the two vertical positions not being set the same on the left image. If the peak voltages are measured they shown up as 2.9V for the regulator and 3.3V for the enable signal. If the LED lights are disconnected the the regulator voltage rises to 3.3V. This is probably due to the presence of a schottky diode on the 3V3O output pin - the voltage drop on these is less at very low currents.
The image on the right has the timescale set to 25us per division to take a closer look at the NCP167 regulator's turn-on time. It takes approximately 110us (4.5 divisions) to turn on which matches the data sheet value of 120us. The Zoyi ZT-703S is failing to measure the duty cycle correctly with this zoomed-in timescale.
The passive probes are set to 10x here to minimise any effect on the circuitry. The pins on the surface-mount technology (SMT) components are tiny and it's very easy to unintentionally short adjacent pins with an oscilloscope probe - caveat prober!
Going Further
Some ideas to explore.
- Run the lights for an extended period to ensure the voltage regulator continues to work as expected. The circuit above was run for 48 hours continuously without any anomalies and without any components getting hot (based on an occasional finger test).
- Use the light sensor on the FeatherS2 to adapt the brightness level of the Christmas lights to ambient conditions.
- Check the effect of load on the voltage output of the second regulator with and without PWM modulation of the enable line to ensure voltage drop is due to the schottky diode.
- The LED current is around 80mA here, the NCP167 regulator can provide up to 700mA, cautiously exploring how the regulator behaves when switching higher loads and capacitive or inductive loads would be interesting.
Related projects:
- Instructables: Constant Current Circuit for Flexible Filament LEDs Using Cytron Maker Nano RP2040 With PWM Brightness Control - show use of NPN transistors for current-limited PWM control of LEDs.
- Instructables: High Power LED Driver Circuits - shows many constant current circuits using logic-level MOSFET transistors to support high currents, note author uses a less-common symbol for an n-channel MOSFET.
Seasonal products featured in the video (no affiliation, no affiliate links):
- Draenog Christmas Cards - mentioned on BBC News: Temu removes copies of tiny firm's cards.
- Etsy: cuteNquirkycreations christmas card
- Redbubble: edcarj82: Nakatomi Christmas party 88 Greeting Card
- A card from The Connection at St-Martin-in-the-Fields UK charity and another supporting Cancer Research UK charity.
- Poundland Christmas Lights from 2023 similar to Christmas Star String Lights, 1.5m - Warm White Silver (Pack of 8) - powered by two AA batteries.
Further reading:
- StackExchange Elecitrical Engineering: Can the enable line on a linear regulator be toggled at high frequencies?
- Adafruit Forums: Feather ADC comparison including 2.6V limited ESP32-S2 - not relevant for this project but caution is required when using analogue inputs on the Espressif ESP32-S2.
- bigclivedotcom: Poundland 2016 Xmas light mass-test. (YouTube) - first one is mains powered.