Help with Driving 7-Segment Display using STM32F030F4P6 – Low Side MOSFET Failur - Page 1
Forum section: electronics / projects

author: raminrajabi
author_rank: Contributor
timestamp: May 06, 2025, 06:18:06 am
content: Hi everyone,I designed a time and temperature display using an ESP8266 and STM32F030F4P6 for driving a 7-segment display. However, after running for 3–4 hours, the STM32F030F4P6 fails to handle the current required by the LEDs, particularly on the low side MOSFET. The GPIO pins on the STM32F030F4P6 are not capable of sinking enough current for the LEDs, which is causing the failure of the low-side MOSFETs.I used the STM32F030F4P6 because of its low cost, and each pin needs to be set to either low, high, or high impedance (high-z) at any given time. The LEDs are driven directly from the GPIO pins through a current-limiting resistor (calculated at 30Ω for each LED), but the current exceeds what the pins can handle over time, leading to the MOSFET failures.Has anyone encountered similar issues or have any suggestions on how to offload the current sinking to external components like transistors or MOSFETs to protect the STM32F030F4P6 and ensure reliable operation?Any advice would be greatly appreciated! Thanks in advance.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 06, 2025, 06:47:06 am
content: Quote from: raminrajabi on May 06, 2025, 06:18:06 amWith this LED driver scheme, a simple single resistor is also going to give issues in even lighting.When any pin sinks, the varying 1-7 source segments will cause varying drops across the external and internal resistances, so uneven illumination results.Besides that, your own empirical tests suggest the total current of the MCU is being exceeded.You are probably best to select a simple LED driver that has 8 source pins and 8 sink pins, and that is rated for the ~ 150mA your display is trying to draw.

author: bingo600
author_rank: Super Contributor
timestamp: May 06, 2025, 07:02:16 am
content: Led driver seems nice.Else maybe an ULN2803A fed from 5v , as driver.

author: raminrajabi
author_rank: Contributor
timestamp: May 06, 2025, 07:14:26 am
content: How can I control an LED driver IC that has 8 source and 8 sink pins using tristate GPIO logic from my MCU (high, low, or high-Z)? Is there any reference guide or application note I can read to better understand this kind of LED matrix driving approach?

author: bingo600
author_rank: Super Contributor
timestamp: May 06, 2025, 07:45:55 am
content: I'd have a look at for example:MAX7219https://www.analog.com/media/en/technical-documentation/data-sheets/MAX7219-MAX7221.pdfBut i suppose the ULN28xx would run with your existing firmware , just remember it has a "darlington" drop on Vout ~1.4v .. So you can't feed it 3v3 , and reach 2.7v for the led segmentsUnfortunately TI doesn't seem to make the TPL7407L / LA in 8 channelshttps://www.ti.com/product/TPL7407LA

author: raminrajabi
author_rank: Contributor
timestamp: May 06, 2025, 08:10:58 am
content: "Thanks for your help, but I need an IC that supports both common-cathode and common-anode displays. I think the MAX7219 doesn't support this."

author: bingo600
author_rank: Super Contributor
timestamp: May 06, 2025, 08:14:06 am
content: Quote from: raminrajabi on May 06, 2025, 08:10:58 amThen you have to do your own search ...Or ... Think "Out of the box"https://forum.arduino.cc/t/max7219-and-common-anode-displays-with-ledcontrol/118609Btw:The UNL2803 is designed for 5v input , if your MCU runs from 3.3V you should check the drive voltage is sufficient.But according to this , 3v3 should drive it fully :https://forums.raspberrypi.com/viewtopic.php?t=14644#p150960

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 06, 2025, 08:38:34 am
content: Quote from: raminrajabi on May 06, 2025, 07:14:26 amSomething like a 1640 is designed for up to 8 segments and up to 16 grids (sink) with 8 dim steps ( or a 7219 can do 8 x 8 with RSET of max and 16 dim steps)You wire those SEG-GRID together, for 8 IO pins, and set the display array so the SEGn of GRIDn is always off. (even if you get that wrong, it only costs a slight excess current)It does mean your 7 segments look up ROMs need to have multiple copies, as each dight has a different bit-to-seg map.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 06, 2025, 09:00:08 am
content: Edit, oops. as PCB.wiz below mentions, with 22 Ohm resistors current may indeed be much too high and my previous statement below is pretty much invalid.----------------------------------------------With 220 Ohm series resistors in between the LED display and the uC, max I/O current is 15mA. And that's ignoring the "other" resistor, and the voltage drop over the LED's. I/O current for a pin is 25mA, so that is quite safe. However, total current for the power pins is only 100mA and you may exceed that, depending on how the whole display is driven, and the other things connected.Another possibility is that these are fake devices from Aliexpress. I don't know how common (fake) clones of the small STM32 chips are.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 06, 2025, 09:04:20 am
content: Quote from: Doctorandus_P on May 06, 2025, 09:00:08 amI read that as 22Ω

author: raminrajabi
author_rank: Contributor
timestamp: May 06, 2025, 02:54:39 pm
content: I'm thinking of trying a 100Ω resistor to avoid damaging the MOSFET, but I'm concerned the LED might be too dim to be visible from a distance.

author: Sacodepatatas
author_rank: Regular Contributor
timestamp: May 06, 2025, 05:31:42 pm
content: Quote from: raminrajabi on May 06, 2025, 02:54:39 pmI'm using 330ohm with 6 lines of a 3 digit charlieplexed display (red leds, that are less shiny than blue ones). I drive just one segment per multiplex interval. 5V gpios from a PY32F002BW15P6. I have been developing for 1 month at spare times. But since 2 weeks ago, i didn't have enough time to continue my project, so i left the breadboard connected day and night and the display showing numbers and messages (mine is also a highly customizable timer and thermostat). No failures, and i've got a decent display view, not faint at all.

author: raminrajabi
author_rank: Contributor
timestamp: May 06, 2025, 07:03:42 pm
content: SpecificationPY32F002BW15P6STM32F030F4P6CoreCortex-M0+ @ 48 MHzCortex-M0 @ 48 MHzMax Source Current (per pin)~20 mA (typical)6–8 mA (guaranteed min)Max Sink Current (per pin)~20 mA (typical)6–8 mA (guaranteed min)Total GPIO Current~100 mA (estimated safe max)40–60 mA max (ST recommendation)Output Drive ControlSelectable (Low/Med/High)Fixed3.3V LED DrivingOK with 330–1kΩ resistorOK with 470–1kΩ resistorGPIO CountUp to 1815Toolchain SupportLimited (manual setup)Full (STM32Cube/HAL/Arduino)

author: raminrajabi
author_rank: Contributor
timestamp: May 06, 2025, 07:07:40 pm
content: FeaturePY32F002BW15P6STM32F030F4P6STM32G030F6P6CoreCortex-M0+ @ 48 MHzCortex-M0 @ 48 MHzCortex-M0+ @ 64 MHzFlash / RAM16 KB / 2 KB16 KB / 4 KB32 KB / 8 KBGPIO Drive Strength~20 mA (typical)6–8 mA (safe max)Up to 20 mA per pinTotal Port Current~100 mA (estimated)40–60 mA (typical max)80 mA per portPackageSOP-16TSSOP-20TSSOP-20Supply Voltage2.0–5.5 V2.0–3.6 V1.7–3.6 VSTM32 EcosystemNo (limited HAL support)Yes (CubeMX, HAL, etc.)Yes (full STM32 support)If I use STM32G030F6P6 to replace my current IC, will it perform just like yours?

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 06, 2025, 07:27:10 pm
content: Quote from: raminrajabi on May 06, 2025, 02:54:39 pmEasy to try.With this led scheme, your average LED current is iPk/8 and the highest sink current is iPk * 7Some means to dim the display is always good to have.The LED drivers mentioned have dim registers.If you can change to 5V, to get a bit more headroom, another driver choice is 8 x NPN/PNP digital transistor pairs as emitter followers with the resistors in the NPN collectors.These follow the 3 states of the MCU pins. A small deadtime would be added to avoid ghosting from BJT storage times.Addit: Because the PNP (sink) needs higher current, you are better to use std PNP pairs, 500mA~1A ballpark, and NPN RET pairs, > 100mA is ok.Spice says the upper arm has ~1.55-1.6V drop at 5V, so you will have good current precision, via the NPN collector R, and very low MCU loading of < 1mA per pin.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 07, 2025, 12:16:57 am
content: Quote from: raminrajabi on May 06, 2025, 07:14:26 amNew LED drivers from Holtek etc, are designed to drive your type of LED cross-plex to save pins.Seehttps://www.holtek.com/webapi/116711/HT16D31A_Bv151.pdfThat has scan hi-side and linear controlled current sinks low side (I think the opposite to your LED?)Quote from: raminrajabi on May 06, 2025, 08:10:58 amSuch an IC would be rare, as it would need double the high current drivers, and only 50% of them would ever be used on a given PCB.The Holtek part above is a good example of low-pin-count drivers for low pin count LED modules.

author: raminrajabi
author_rank: Contributor
timestamp: May 08, 2025, 03:24:41 pm
content: I will test this configuration and hope it resolves the issue, using the ULN2803A to drive the ground lines instead of the STM32.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 08, 2025, 07:29:15 pm
content: Quote from: raminrajabi on May 08, 2025, 03:24:41 pmThat will struggle with a 3.3v supply and a 2.7v led.It will be more workable at 5V

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 08, 2025, 08:09:59 pm
content: Do you mean the stm32 pins are phisically failing?Which display is that?How is it controlling so many digits with only 8 pins? Charlieplexing?

author: mtwieg
author_rank: Frequent Contributor
timestamp: May 08, 2025, 10:34:24 pm
content: I'm guessing the display has internal charlieplexing network. Would help to see a datasheet for it. The peak/average current on each pin may vary greatly depending on what's being displayed.Also keep in mind that often there will be a max current for individual GPIO pins, and also limits for total current from groups of GPIO pins, or the entire chip. For example, for the STM32F030F4P6, it states the max sink/source current for any single GPIO is +/-25mA, and also the max sink/source current for all GPIOs combined is +/-80mA. Both limits need to be respected.I wonder if there exists a type of transceiver or level shifter which can automatically detect a tristate input without a separate control signal. Sort of like a bidirectional level shifter with automatic direction sensing....

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 09, 2025, 01:19:14 am
content: Quote from: mtwieg on May 08, 2025, 10:34:24 pmEmitter followers can do that.If there is 5V available, they are a possible solution here.If there is only 3.3V, there is less voltage budget.Darlington drivers are out, (too much drop) but there are parts like XL62083 that have DMOS drive, ~2 ohms, tho in a somewhat large package.It seems most designers just use Dual NMOS parts at 1.5-2.5c a pair. There you can get 100m-220m Ohms

author: mtwieg
author_rank: Frequent Contributor
timestamp: May 09, 2025, 02:51:44 am
content: Quote from: PCB.Wiz on May 09, 2025, 01:19:14 amYeah I was thinking a simple class B push pull output might work. Aside from losing the voltage range, it won't be a real tristate output. If Vout and Vin differ by Vbe or more, the output will start sourcing or sinking current. Not what you want if you're trying to do charlieplexing.Here's a rough circuit I came up with which doesn't have that limitation, and seems to work fine at 3.3V. I'm guessing there are further optimizations to reduce the number of components required.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 09, 2025, 05:47:55 am
content: Quote from: mtwieg on May 09, 2025, 02:51:44 amR2,R3,R6 are not really needed, but that's a lot of parts, given it repeats x8.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: May 09, 2025, 07:24:59 am
content: Quote from: PCB.Wiz on May 09, 2025, 05:47:55 amIndeed. That totally swamps the (small) benefits of saving a few I/O pins with charlieplexing.And no matter whether the display is CC or CA (Even that is just software when charlieplexing I think),the simple resistor approach also does not work well, because the CC (or CA) current is much higher because it is the sum of a bunch of segment currents.I would start by increasing the resistors, so the LED current is never more then the max I/O current (20mA or 30mA) divided by the number of segments that are on at the same time. Then you can add schottky diodes to bypass the series resistors in one direction.

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 09, 2025, 02:06:43 pm
content: OP: Are you sure the display routine is 100% fine and you're not creating cross-conduction at some point?Blue led Vdrop is normally around 2.9-3.0V, so current shouldn't be an issue, that's just 13-15mA over 22ohms, I doubt the port can die that easily.To the rest: He didn't even link the display datasheet or told how it works, so avoid wasting your brain juice until then!

author: raminrajabi
author_rank: Contributor
timestamp: May 09, 2025, 05:46:43 pm
content: Thanks for your help. I tested the setup on a breadboard using the ULN2803 and a 3.3V supply — it worked fine. I'll try it with the STM32 tomorrow to see how it performs in the full setup.

author: raminrajabi
author_rank: Contributor
timestamp: May 09, 2025, 05:50:03 pm
content: When switching the pin to ground directly, the MCU's low-side drive started failing after 2–3 hours, likely due to stress or damage to the internal MOSFETs. Based on the suggestions above, I decided to offload the sinking to a ULN2803 to protect the MCU and ensure long-term reliability.

author: raminrajabi
author_rank: Contributor
timestamp: May 09, 2025, 05:58:17 pm
content: Thanks again for your help. English isn’t my first language, so I might not explain things in full detail, but I’ve tried this setup with three different MCUs and saw the same issue each time — the pin used for sinking current eventually got damaged. Unfortunately, I don’t have a datasheet for the display, so I had to reverse-engineer it myself. The display uses 8 pins and is driven with the Charlieplexing technique.I couldn’t find a suitable replacement for this LED display in my country — especially not one that supports showing temperature, time, and 5 bar indicators with minimal pin usage like the MAX7219. Because of that, I’m trying to make this setup work without spending much money, so I’m optimizing the design as much as possible. I attached a picture of the display above for reference.In my original design, I built the setup on a breadboard using the same MCU and ran it for 3–4 days without any issues. I measured the total current when all seven segments of an 8-digit display were lit, and it was around 5 mA. I suspect the added resistance of the breadboard wiring may have helped protect the MCU pins from damage.However, after transferring the design to a PCB, problems began. Initially, the display flickered after 30 minutes, and by the 3-hour mark, the MCU pin responsible for sinking current began to malfunction. Interestingly, if I powered the board and left it idle for about 15 minutes, it would operate normally for a short time. However, if I powered it for around 30 minutes and flickering began, turning the power off and then back on would temporarily restore normal operation.It's possible that the MCU I used was a counterfeit or low-quality part. To improve reliability, I’ve redesigned the setup using a more robust STM32F030K6T6, which can handle higher current levels, along with a ULN2803A to offload current sinking on the ground side. I hope this updated approach will resolve the issue.

author: raminrajabi
author_rank: Contributor
timestamp: May 09, 2025, 06:05:38 pm
content: In the schematic, I represented each LED segment using the format '1 > 2', where '1' is the anode (positive side) and '2' is the cathode (ground side). This means the segment lights up when pin 1 is high and pin 2 is low.This is the only image I could find on the component’s selection page — unfortunately, there’s no available datasheet with further details.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 09, 2025, 08:16:44 pm
content: Quote from: raminrajabi on May 09, 2025, 05:46:43 pmDoes thishaveto operate on 3.3V? Can you measure the LED VF at the drive current you need ?I see 2.7V at 22mA on the LED symbol (average (22/8)mA), that gives you a small total drop budget of600mV, for Low Side SW + high Side SW + current regulation.Even less at lower temperatures.A Darlington version of ULN2803 is going to be marginal at lower temperatures, and not have much voltage drop left for even segment illumination.There are CMOS versions, like XL62083, which has ~2-ohm DMOS output devices.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 09, 2025, 08:19:20 pm
content: Quote from: raminrajabi on May 09, 2025, 05:58:17 pmAre you sure that is not a regulator shutting down, or going unstable at elevated temperatures ?

author: DavidAlfa
author_rank: Super Contributor
timestamp: May 10, 2025, 02:26:09 am
content: The ULN2003V12 is a mosfet version, it has lower current drive capability (100mA per pin) but no darlington drop.Or just use a 8 transistors... any generic BJT will work fine there.Add an octal buffer (I.E, 74LVC244, 74LVC541) driving the digits to relief the current from the mcu pins.Quote from: PCB.Wiz on May 09, 2025, 08:16:44 pmThe ULN2803isDarlington, there're no other versions.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 10, 2025, 03:41:12 am
content: Quote from: DavidAlfa on May 10, 2025, 02:26:09 amFrom theoriginalvendor, yup.These days, you cannot be 100% certain a generic part number contains all of the original details the part code might suggest.There are '2803' pinout CMOS output parts, like the XL62083 I mentioned.Quote from: DavidAlfa on May 10, 2025, 02:26:09 amThose are marginal if trying to hit 154mA (7 x 22mA) sink current, both in current rating and in voltage dropped.

author: raminrajabi
author_rank: Contributor
timestamp: May 10, 2025, 05:51:55 am
content: I find it more straightforward to operate at 3.3V. If I switch to 5V operation, I would need to use high-side MOSFETs—eight in total—which would increase the BOM cost and complexity. I'm currently using the ULN2803AG from Toshiba, which, according to its datasheet, is a Darlington transistor array.To rule out the possibility of a voltage regulator issue—such as shutdown or instability at elevated temperatures—I checked it again. The regulator remains only slightly warm, even under load. I observed that the flickering begins when all the LEDs are turned on simultaneously, suggesting the issue might be related to current demand or load handling.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 10, 2025, 07:15:56 am
content: Quote from: raminrajabi on May 10, 2025, 05:51:55 amDo you have a scope ? Time to monitor the 5V and 3v3 regulators, with some test code that does a staircase current ramp?Quote from: raminrajabi on May 10, 2025, 05:51:55 am? You just pick a MCU that is 5V capable, there are shiploads out there.Driving a White/Blue LED display from 3.3V alone, is not trivial to manage properly. You need to become millivolt-paranoid.

author: raminrajabi
author_rank: Contributor
timestamp: May 10, 2025, 08:02:32 am
content: I tested the regulator with an oscilloscope, and it's very stable on both the 5V and 3.3V sides. I also captured a photo while probing one of the blue segment pins. During this process, the ground pin on the MCU started smoking—the infamous magic smoke was released. I thought the MCU had given up, but it's surprisingly still working.Now, I've become paranoid about every millivolt.

author: PCB.Wiz
author_rank: Super Contributor
timestamp: May 10, 2025, 08:11:28 am
content: Quote from: raminrajabi on May 10, 2025, 08:02:32 amWow,I've never seen smoke caught on camera before!Quote from: raminrajabi on May 10, 2025, 08:02:32 amYou can see there the amount of cross talk from the varying loading and not-ideal current sources.In an ideal setup, the LOW side goes to mV of GND and the upper side is constant current driven, so temperature and the number of ON segments makes no difference.One curious detail - I count 9 time slots there, for an 8-way MUX ? I would expect 1:8 low on each pin.

author: raminrajabi
author_rank: Contributor
timestamp: May 10, 2025, 08:25:16 am
content: For safety, I configure all pins as inputs (high-impedance) at the beginning of each cycle before executing the procedure. This may explain why there are 9 cycles instead of 8.

author: mtwieg
author_rank: Frequent Contributor
timestamp: May 12, 2025, 12:30:01 am
content: Quote from: PCB.Wiz on May 09, 2025, 05:47:55 amDepends on how fast you need the output to settle. The resistor values are selected to prevent full saturation of Q3/Q4, so they turn off quickly.Quote from: Doctorandus_P on May 09, 2025, 07:24:59 amDepends on the availability of extra I/O pins. For all we know, there simply aren't any extra.