PWM issues on vehicle LED

I am attempting to control brightness of vehicle LED lights using PWM. This is on a custom pcb with an atmega328p, which analogWrites a 122Hz PWM signal to an AND gate, which then passes along to a high-side switch (TPS22810) that powers the lights. Fully on, one of these lights operates at 14V, 0.5A. The issue is that the lights unexpectedly flicker off at repeatable threshold points in the program, and I'm hoping someone can shed some light.

Am I missing a simple hardware or software adjustment I can make on my end? Or is it very likely that there's some capacitance or inductance internal to the lights' electronics (that I'm not privy to) that is causing this behavior?

The simplest code I've developed to reproduce my issues is this, where pin 1 is a potentiometer I control. You'll see I'm trying to have the light either at full brightness or at a range of low brightnesses, depending on the potentiometer.

void loop() {
  
  newMin = analogRead(1);

  if (newMin >= 1004) {
    minBrightness = 255;
  }
  else {
    minBrightness = map(newMin, 0, 1004, 0, 25); 
  }
  analogWrite(3, minBrightness);
}

Anecdotes:

  • This code results in a flicker off every time I increase the potentiometer from less than 1004 to greater than 1004. So for example, brightness starts at 0 then increases steadily, then drops out for a split second, then resumes at full brightness. The light decreases in brightness as expected, however, without flickering.

  • Changing the "25" to 40 produces the opposite behavior. It increases to full brightness correctly, but then does the flicker on the decrease.

  • Changing the "25" to 46 seems to get rid of the problem when the engine is off. However the problem comes back when the engine is on.

  • Everything works as expected in bench testing with "normal" (non-vehicle) LEDs.

Ho ho ho! :rofl:

For what purpose is the AND gate?

Perhaps you can explain to us what sort of automotive light these are? Oh, they are LEDs! Might they be using LEDs with a switchmode driver? Apparently this is becoming common as I watch YouTube videos in which brake and tail lights flicker and flash.

Not sure what that code snippet is supposed to prove.

Hi,
Sorry, miss read the first post.
But why are you only mapping 0 to 1004?

A schematic of your pot and output driver circuit would help.

What makes you think your PWM is 122Hz, I think you will find pin 3 is 490Hz.

This is on a custom pcb with an atmega328p,

Can you post a jpg export of your PCB pattern?
Did you protoboard your project before going to PCB?

Tom... :grinning: :+1: :coffee: :australia:

Try some hysteresis.

void loop() {
  newMin = analogRead(A1);

  if (newMin > 1000) {
    digitalWrite(3, HIGH);
  }
  else if (newMin < 980) {
    minBrightness = map(newMin, 0, 980, 0, 26); // = 0-25!
  }
  analogWrite(3, minBrightness);
}

Leo..

@Paul_B, glad you caught that unintentional pun! The AND gate exists because I wanted the functionality of switching up to 4 independent loads (I have 4 TPS22810's) but also wanted the option to put the switches in parallel and synchronized for a larger load. So the single PWM signal from the uC combined with the AND gate helps me do that. The code snippet was meant to further show that the weird behavior is occurring at the edge between the if case and the else case, and see if anyone saw anything "wrong" with the code. Lastly, I am not sure how the OEM drives the LEDs. The manufacturer did not respond to my request for details unfortunately.

@TomGeorge, the 0-1004 mapping exists since the if statement guarantees that the else statement will never see anything larger than 1004. The PWM is 122Hz because I'm running the atmega328 at 8MHz and have adjusted timer2 so that pin 3 produces 122Hz PWM signal (the lights were much less happy at 245Hz and 490Hz). I've attached a picture of the schematic but apologize if it's not drawn in the most helpful format. I did protoboard the project and used evaluation boards for AND gate and switches, but in hindsight made the mistake of assuming the vehicle lights would behave as nicely as all the LED benchtop loads I tested.

@Wawa , thanks for the excellent tip, I will try this as soon as I can and would be so happily surprised if this fixes things. Why do you think the hysteresis might behave nicer?

Hi,
Thanks for the circuit.
Although "search a word" schematics are not good for trouble shooting.

Where is the analog signal coming from and why clamp at 1004?
I see that you are setting a minimum brightness, which is adjustable.

Have you got Serial.print statements in your code to monitor variable values, especially the output analogWrite?

How much current does your project consume, including the LEDs?
Have you monitored the voltage on the 14V supply when the problem occurs.?
What IC are you using for your AND gates?
What is Q1 and what is it for?

Tom... :grinning: :+1: :coffee: :australia:
PS. The code in post#1 , is that the test code that also produces the fault?

Hi,
I have drawn up a basic schematic of your project;


The four digital inputs of the AND gates, where are they connected?
If at the moment open circuit, then that can be a source of your problem.
I assumed for the benefit of the circuit 74LS08 quad AND Gate IC.
Where about in your diagram does the battery and gnd connect?
Where is your 5V supply coming from?

Open circuit gates can assume any state, 0 or 1 and change state at anytime.
I would suggest if they are open, that you pull them to 5V so the AND function can pass the signal through.

Can you please post a jpg EXPORT of your PCB?

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

Switching ground of a chip can lead to unexpected (damaging) results.
Ground current could find a way through the EN pin of the TPS22810.
Leo..

Hi,

I'm not sure why its there, hope @anon32917233 can help.
In it present config it is conducting when there is 5V supply.

Tom.. :grinning: :+1: :australia:

@TomGeorge , Sounds like I should've involved some external help sooner in this project :frowning:

The 1004 was my cutoff choice of saying "If you turn the pot to the last 2% of its range, you get full brightness. Anything in the first 98% gets mapped linearly to a lower brightness range". This suppressed range is a result to avoid other, more severe flicker that previously occurred at higher duty cycles. I have attributed this to the light's electronics because my benchtop power supply would shift into current control mode as the PWM swept through the higher duty cycles.

I do have the Serial.prints in my troubleshooting but had not looked at them with the board attached to the car. However, I did recently hook the oscilloscope up and verified that when the issue occurs, the 14V power supply, the 5V supply, the digital input of the AND gates, and ground all are as expected when the issue occurs. It is only the TSP22810's output that I have detected as being faulty so far. I, not being an expert, didn't put great testpoints on the pcb, but I also need to scope the PWM from the atmega as well as what's coming out of the AND gate.

The AND gate is a MC14081B.

My apologies, I cutoff an additional connector in my screenshot at the bottom that the 14V, 5V, and GND connect to.

The 5V supply is from the car's 5V supply to some sensors that get switched on when the car is turned on.

The digital inputs to the AND gates are from the 14V wires that normally go to power the LEDs but I am re-diverting them to my board and use voltage dividers to bring them down to 5V before going to the AND gate. So if the driver has set these lights to be "on" from inside the car, the inputs go high and are high when the issue occurs.

My board's electronics consume ~15mA. The driver+passenger LED's consume ~1A, so 1.015A total. (Although as mentioned above, I have reason to believe the LED's consume more at certain duty cycle ranges.)

Q1 is an NPN BJT (SMMBT3904LT1G). When the car is turned on, the 5V switches the board on to operate. In a prior iteration, I believe VOUT of TPS22810 was going high (lights always on) even with the car off when gnd and VIN were connected. Maybe this was because I don't have a pulldown resistor on the AND gate's output? The gnd switching at vehicle turn-on/off has seemed to work great and minimize components, but I was not aware of potential damage that @Wawa mentioned.

Here are pcb photos. Again, sorry they're probably not the most professionally formatted (or designed).

I want to believe this is all due to some weird LED driver electronics that my board is sending the PWM power to, but maybe there are some flaws on my end to adjust as well... I appreciate your help Tom.


Hi,
On you PCB I can see your min and max pot gnd connections. however I find it difficult to find the +5V connection the the other end of the pot.
The two 5V ends are connected but go to the junction of two resistors on the top layer.
That junction "seems" to go through a via to the bottom layer, then to a copper area, it connects to a 6pin socket, the pin being marked GND on the top layer.

Have you measured the voltage at the two connections of the pots that should have 5V across them.

What limit was your power supply set at?
Does it have a volt meter and ammeter?

You must be aware that the TSP is an intelligent output device, and if it overheats it shuts down, if the supply volts goes down as in a current limit or lack of supply current, then it will shut off.

Please monitor your power supply voltages when these faults occur, measure them at the PCB.
Are you sure that the inputs to the AND gate are at 5V through the divider?

What makes your PCB hard to follow is no Silkscreen overlay to identify components, have you got one and can you post its image please?

Still confused where your 5V comes from, how accurate is your schematic to the PCB?

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

Hi, here is a better pcb layout with component designations from the schematic. The 5V is confusing because I accidentally left that connector out of the schematic screenshot. 5V is coming in through the left-most pin of J5 and comprises the copper pour in the top-left of the board.

I will get more answers to your questions after NYE festivities but the 5V supply, 14V supply, and 5V to the AND gates are all stable when the output of the TSP goes low unexpectedly. I don't think it's a thermal issue because I've ran ~8A of non-vehicle LEDs (2A per TSP) for extended periods of time to stress-test the board, getting chip temps up to ~180F according to my infrared gun, and everything performed as expected. I still need to check if the PWM into the TSP is as expected (and not flatlining) when the output faults on the vehicle LEDs. Happy New Year!

Hi,
Thanks for that.
Spreads some light.
Still 5V to pots worries me.

Happy New Year mate.

Tom... :grinning: :+1: :coffee: :australia:

Hi @TomGeorge I'm back! ( but I'm not sure why the Forum has changed my earlier post usernames to anon.) What about the 5V to the pots worries you?

I did a series of benchtop testing with a spare vehicle headlamp that has the LEDs in question. There are some interesting results, but I'm still at a loss as to what conclusion to draw about any flaws in my design vs the mystery electronics inside the headlamp causing issues. The test involves going from 100% duty cycle immediately down to a lower (but non-zero) x% duty cycle PWM:

  • When I use one power supply (TekPower TP-3005D-3) as the 14V AND 5V source and x > ~5%, the light behaves as expected and goes from full brightness to much lower brightness without issue. When x < 5%, the light goes completely off for a split second and then comes back on at the desired dim brightness. It seems that the lower x is, it takes slightly more time for the light to come back on.

  • When I use a different power supply (eTopxizu 360-12) as the 14V AND 5V source (put buck converter on one of the 14V lines to get 5V), it seems the exact same behavior occurs. When x > ~5%, the light behaves as expected and goes from full brightness to much lower brightness without issue. When x < 5%, the light goes completely off for a split second and then comes back on the desired dim brightness. It seems that the lower x is, it takes slightly more time for the light to come back on.

  • Now for the test that doesn't make sense to me... When I use one power supply as the 14V source and the other power supply as the 5V source (doesn't matter which supply provides which voltage) with common/negative terminals connected, the behavior dramatically improves. The lights only flicker off when x <1 or 2%, and even then it frequently works as expected.

What does this imply? That there's some capacitance or inductance inside the headlamp that needs to "charge up" before the lights can turn emit light? Are there any other tests you'd recommend I do? I could destroy the headlamp casing to try to get to the circuit boards inside and investigate those but not my favorite option.

Hi,

Can you post a picture of your LED headlamp, does it have any electronics in it?

Have you checked the voltage across the outside terminals of each of the pots?
Have you monitored the 12V supply when you get this fading problem?

Tom.... :grinning: :+1: :coffee: :australia:

Yes, I just confirmed the 5V voltage into the pots, the voltage signal coming out of the pots, and the 12V supply into the whole system is stable when the flicker-off occurs.

In the picture you'll see 3 lights. The big one on the right (with circular LED elements) is the one I care about. The one on the left is a 3rd party accessory light you'll see some people add to their cars. The little one in the middle is one I've used on custom electric skateboards I've built. This issue only occurs on the right one. There's certainly electronics inside it, but dissembling involves either sawing the thing apart or heating it up to soften the sealant around the edges.

HI,

And that electronics will be striving to produce a CONSTANT even light no matter what the vehicle power supply is doing.
PWM is not one of the things it is meant to respond too, the LED electronics may involve a SMPS.
Supplying it with a very low duty cycle, is like supplying it with very short current spikes, the driver circuitry I would say doesn't like it.

Tom... :grinning: :+1: :coffee: :australia:

I agree, but it’s still confusing to me why the ability to switch from high to very low duty cycle noticeably improves when I use two different voltage sources for the 12V and 5V :thinking:

Viz. #3! :thinking: