Weird LED PWM dimming behaviour Adafruit TLC59711

Hello all,

I am quite new to programming and electronics. At the moment I am trying to design a light alarm clock that lights up multiple LED strips on top of my wardrobe over the course of an hour throught the different ranges of color of the sunrise. The main code is already written and works with single LEDs as placeholders connected to the PMW dimmable output pins of my Arduino Uno.

To get better resolution in the beginning of the fade (so I don't have an abrupt start of the LED in the morning potentially waking me up) I opted to use the adafruit tlc59711 for its 16bit resolution. I combined it with a formula to make the fade up linear to the perception of the human eye - hence the bits of code that calculate the R Value and the log function in the main loop. I used this test sketch to test the dimming behaviour an it looks like this:

#include "Adafruit_TLC59711.h"
#include <SPI.h>

// How many boards do you have chained?
#define NUM_TLC59711 1

#define data   12
#define clock  13

Adafruit_TLC59711 tlc = Adafruit_TLC59711(NUM_TLC59711, clock, data);
//Adafruit_TLC59711 tlc = Adafruit_TLC59711(NUM_TLC59711);

const int pwmIntervals = 4000;
float R;

void setup() {
 // Serial.begin(9600);
  
 // Serial.println("TLC59711 test");

   R = (pwmIntervals * log10(2))/(log10(65535));
  
  // Uncomment this line if using UNO/AVR since 10 has to be an output
  // for hardware SPI to work
  //pinMode(10, OUTPUT);

  tlc.begin();
  tlc.write();
  }

void loop() {

unsigned int brightness=0;

for (int interval = 0; interval <= pwmIntervals; interval++) {
      // Calculate the required PWM value for this interval step

      brightness = pow (2, (interval / R)) - 1;

      // Set the LED output to the calculated brightness

     tlc.setPWM(2, brightness);
     tlc.write();
     //Serial.println(brightness);
     if (brightness >= 65500){
      break;
     }
}

for (int interval = 4000; interval >= 0; interval--) {
      // Calculate the required PWM value for this interval step

      brightness = pow (2, (interval / R)) - 1;

      // Set the LED output to the calculated brightness

     tlc.setPWM(2, brightness);
     tlc.write();
     //Serial.println(brightness);
      if (brightness==0){
        break;
     }
  }
}

This simple fade up and fade down works with a single LED on output No.2 , as long as the adafruit is connected to the arduino as shown on the adafruit website:

After this test I put one of these MOSFET driver boards on PWM Output No. 2 for driving a 30V 30W LED (the LED and the driving Voltage is not yet connected. Only the PWM voltage is connected to the driver):

It has a PWM input that accepts everything from 3.3 to 20V as a PWM voltage. It has a little LED that indicates the duty cycle and it dimms up and down as expected.

So far so good.

When I now build the complete circuit (exemplary for one LED strip) it looks like this (I apologize for errors this is the first schematic I ever drew - I can redraw it if anything is unclear):

The main power source is a 30V 4A power supply. It is connected to the input of the driver module. When I drive the arduino with USB power (not like in the diagram) it works okay (I get some little flickering in the dimming process but I don't know if that will also be the case when the LED dimms over the course of several minutes so this problem doesn't concern me, yet). The LED on the driver dimms in sync with the main LED that it is driving.

To make it more compact I want to power the Arduino with the same power supply and as you can see in the diagram I use a DC-DC Buck converter to power the Arduino and the adafruit with 12V - and then nothing works. The PWM is stuck at 100% duty cycle (to my eye at least the LED is at full blast).

What I have tried:

  • putting everything (apart from the AC source) on a common ground rail
  • sharing the V+ from the Adafruit with the Vin on the Arduino
  • "isolating" the adafruit by giving it its own DC-DC converter from the same AC-DC source
  • Using DC barrel jack on the arduino
  • using capacitors (100microfarad and also 10 microfarad) at the LED input, the adafruit power input and the driver DC input
  • letting the arduino generate a PWM sweep on pin 3 directly to the driver - this works

What I noticed while experimenting (with the adafruit generating the PWM again):

  • When I let the Arduino generate a 1 second switching 100-0-100-0 duty cycle the LED on the driver stays on, then starts to become a little dimmer, then stays on (instead of on-off-on-off)
  • this problem only occurs when the arduino is NOT powered through the USB port
  • this leads me to believe, that it has something to to with the reference voltage of the adafruit driver.

I went on a search an stumbled upon forum entries discussion ground bounce and decoupling capacitors but I couldn't quite figure out how to adapt these infos to my situation.

Does anyone have an idea what the problem could be? Sorry if I missed any information this is my first post.

Adjust the buck converter to 5V. Power the Uno with that through its 5V pin and the TLC module also. Remove the 10K from the clock and data lines. Add 10K pull-ups between the TLC module's outputs and 5V.

Post a link to the led strips. I have never come across 30V led strips.

Hi Paul,

thanks for the quick reply - I really appreciate that! :blush: I will try that first thing in the morning and will keep you posted.

Do I get this right: By powering through the 5V port on the Arduino you mean the 5V pin that is normally used as an output, right? I read about that it can be used as an power input but only if the voltage is lower than the supplied voltage at the barrel plug or USB (which would be 0V in that case). Maybe I misread that part or misinterpreted the wording of the source. I just did not want to fry my arduino that's why I didn't try it before.

As for the 30V LED you are right - there are no 30v strips. I ordered 24V strips and they will arrive tomorrow but had a 30V LED module from yuji LED laying around (I couldn't find I formation since they discontinued that product long ago) see the picture attached:

It can be used as a power output, if done with consideration and understanding. But it is generally safer to use it as a power input, if you have a 5V source available. The Uno is, after all, a 5V device. It's on-board regulator has no heatsink and can easily overheat. I don't think that is a significant danger in your circuit, but if you have a buck converter that can easily be adjusted to produce 5V, why risk it? Buck converters are more efficient and much less likely to overheat compared to the linear regulator built into Uno. Plus they can usually accept a high input voltage which would definitely damage the Uno's built-in regulator.

You would not connect anything to the barrel socket if you are powering the Uno using the 5V pin.

Powering a 24V led strip with a 30V PSU will damage it.

The use of 10K pull-ups on the TLC module are important. These outputs can only sink current, they cannot source it, which is what the MOSFET modules generally need. The pull-up resistors should provide that current source.

Hi Paul,

I ordered a seperate 24V Supply for strips - thanks for the heads up!

I wired everything accordingly. The 5V on the arduino works - thanks for the clarification. I still get behaviour I do not understand completely. Here is the first wiring without the 30V PSU connected to the driver:

I can see that the LED on the driver indicates the exact values I programmed the TLC chip to provide - but of course inverted. I measure 5V at 100% duty cycle (a brightness value of 0 in my code) and 0V at 0% duty cycle (a brightness of 65535 in my code) at the indicated points - so just as expected. But when I connect the driver DC input to ground the PWM at the driver stays always on. So the LED is at 100% again. The wiring looks like that in this case:


Why is that?

Then I wired differently and moved the GND of the PWM input of the driver to the ground rail and connected the PWM input to the PWM output before the Resistor like that:

Now the PWM seems to do its job but it measures only 2V at the PWM input of the Driver (given an (inverted) 100% duty cycle and 0V at an (inverted) 0% duty cycle) - is this because of voltage drop produced by the switching components in the driver or is my wiring wrong? Anyways my dimming logic doesn't work anymore and I have to find a way of inverting it :smile: I think the gamma-corrected brightness curve doesn't really work inverted.

I also noticed - and read on another post - that the TLC chip sometimes inserts blanking but because it is now inverted this now shows as a bright flash in the dimming. I think I will try to construct a not-gate with a PNP transistor like mentioned in this post:

https://forums.adafruit.com/viewtopic.php?f=19&t=95187&p=478044

But am I in the clear for the main construction in my circuit? Thank you so much for the help! Up until this point I was really at a dead end :melting_face:

I'm struggling to understand your diagram well enough to answer your questions. The style of your diagram is part schematic and part block diagram, so parts of it seem ambiguous to me. Can you draw a complete schematic? In a schematic, every pin of every component is labelled so there is no ambiguity.

I studied your MOSFET modules from the link you gave in your first post. No internal schematic is given for them, but I noticed 2 important things from the images.

  1. The main components are a pair of n-channel MOSFETs. I strongly suspect that means that the DC+ and OUT+ are directly connected on the module. The DC- and OUT- are connected via those 2 MOSFETs.
  2. There is no opto-isolator on the module, so the only way it can work correctly is if the PWM ground and DC- are connected. I can't tell whether they are connected on the module, but if not, it would be important to connected them externally.

Here is a schematic. I also inlcluded the exact points I took the voltage measurements:

I also tested the continuity between the driver's PWM ground and the DC-. There is continuity so they are connected within the driver. I noticed, that I measure 0-2 V (0-100% duty cycle) at the driver and 3-5V (0-100% duty cycle) across the pull up resistor. Does that mean the circuit works as intended? I also measure 0-30V at the driver`s output at 100-0% duty cycle respectively so it seems like it does what it is supposed to do :thinking:

I'm not 100% sure why you read those voltages, but I think it could be something to do with the indicator led (and one of the resistors) on the MOSFET modules pulling the voltage down at the PWM pin.

If I'm right, using that 10K as a weak pull-up may not be good enough, because the MOSFET module's input is quite low impedance, due to the indicator led + resistor on it. MOSFET gates themselves are normally/naturally high impedance, but the led indicator is making the MOSFET module's overall impedance low.

Try this: Disconnect the PWM input of the MOSFET module and measure the voltages again at the same places you did before. If you then get 0-5V on the wire that was previously connected to the PWM output (and the corresponding 5-0V across the 10K, of course) then I think that confirms my theory.

So I integrated the inverter an this is the schmematic:

I am finally measuring 0-5V across the driver PWM input and driver GND and 0-30V across Out+ and Out-. It also corresponds correctly to 0-100% (0-65535 code value) without being inverted.

BUT: The code values from 0-65535 do not correspond linearily to the PWM Voltage 0-5V. That is odd because when connecting a single low power LED to the TLC board it reacts that way. The PWM Voltage shoots up in the first 0-1000 code values and corresponds to 0-2.5V and the remaining 2.5V happen in the code values raning from 1000-65535. Does that have to do with the current limiting resistor that is integrated in the TLC board? It is used to be able to drive single LEDs without having to add a current limiting resistor. The problem is that I am now again back to my resolution problem despite having 16bits of PWM dimming :melting_face:

I also noticed, that when PWM=0V the Output is 0V. But as soon as PWM>0 the 0-30V output jumps to 14V or something volts - basically the minimum driving Voltage of the LED module...

EDIT: It's roughtly 14V - I cannot measure exactly with my multimeter

I will try that - sorry I posted right as you were typing. Well I could try that but now my circuit is quite different. But could the resistor values be the cause for the non-linearities in the system?

I'm not sure your mods to the circuit will work. There is nothing to switch the PNP transistor off (it's base needs to be close to 5V to switch off fully, and there is nothing to ensure that).

I'm assuming you are using a PNP transistor, and not a PNP phototransistor, even though that's the symbol you have used!

I was going to suggest a 74hc04. It's an inverting buffer chip. Connect 10K pull-up between the TLC output and 5V as before. Connect the TLC output to an input on the 74hc04 and connect the corresponding output to the MOSFET module's PWM input. Don't forget a 0.1uF bypass cap for the 74hc04.

74hc04 chip contains 6 independent buffers, so if this works, you won't need a 74hc chip per MOSFET module.

If you haven't got 74hc04 to hand, have you got any other 7400 chips about? Even 74hc00 would work I think.

1 Like

Yes I also read about using this kind of inverter chip. Also yes, I am using a PNP transistor and not a phototransistor - I must have selected the wrong kind in the schematics software.

I have a 74HC595 chip here - but I never worked with those kind of ICs before. In the meantime I tried matching different resistors at the base and the collector and measuring the linearity between code value, PWM voltage and LED voltage. I get the most linear response at 1k at the base and 100R between collector and ground. But i get a lot of non-linearities throughout the range between code values 200-500 where the voltages stagnates and then takes of later again.

How would I get the base to be close to 5V? This is the best combination of resistors I measured. The x-axis is code-value (measured from 50-65535 in steps of 1000 until code value 8000 and the in steps of 8000 until 655535):

image

I'm not sure if will be possible with your pnp transistors, with any value of resistor.

74hc595 is too complex, what I really meant was any basic 7400-series chip which is a simple logic chip with a number of logic gates with inverting outputs, such as 74hc00, 74hc04, 74hc14...

1 Like

So I tried around and you were right - there is a pullup resistor missing between the Base and the PWM output of the TLC chip. Otherwise it would of course not be pulled to 5V. I added a 10k pullup just as I had it when the TLC Pin was directly connected to the driver board PWM pin. I further played around with the combination of resistor values and noticed, that a very low resistance between collector and ground scales the PWM Values near perfectly between 0-5V. I made this diagram consisting of sampling points all across the code value range (it also includes EV values (from a light meter). +1 EV equals a doubling of measured light output:

image
*left scale is 0-5V for PWM *right scale is for LED voltage and EV-Values

When I scale the x-axis logarithmically you can see the non-linearities in the lower portion of the dimming range. But to be honest I think this could be because of the LED only being able to be dimmed to a certain point. Up until code value 100 the LED voltage shoots up and then settles into linearity (in the middle there is this unusual bump where the PWM and LED Voltage do not change that much):

image

BUT: I took measurements of the rising sun and actually this dimming profile (starting slow - stagnating a little bit - then driving full force) matches the sunrise pretty closely :smile:

So for my particular project I will leave it like that and connect the other other LED like this as well (TLC-Pin pulled up into base of PNP transistor and that driving the MOSFET driver's PWM input). Thank you so so much for your help I learned a lot because you pointed me in the right direction. And even thought the circuit might not be technically optimal I can finish the project and know where to start looking when encountering a road block :+1:

I will also look into the 7400 series chips :ok_hand:

I hope you (as we say in Germany) slide smoothly into the new year!

All the best,
Jannes

1 Like

And this was the last puzzle piece - I used a 74HC14 with its Schmitt trigger. I guess the PWM signal was very noisy when it passed through my PNP inverter. Now with the 74HC14 the PWM voltage is so granular in the lower code regions that I cannot even measure it with my multimeter but I can see the very fine dimming steps in the LED. This is so great! I guess I was a bit hesitant with the 74 series chips as this is my first electronics projects but it arrived today and it was basically plug'n'play. So if anyone stumbles across this thread this was the final solution to my dimming problem :wink:

My guess would be that any inverter made from a single transistor won't achieve the needed "slew rates". A PNP can only actively pull the signal up to 5V, and relies on a resistor to passively pull the signal down to ground. Similarly, a single NPN transistor inverter could only actively pull the signal down and would have to rely on a resistor to passively pull the signal up to 5V.

If the device receiving that signal has a very high input impedance, then it's not a problem. But in this case, that device is the gate of a MOSFET. 2x MOSFETs in fact. The gates of MOSFETs are like small capacitors. At higher frequencies, their impedance will naturally drop, because those capacitors have to be charged and discharged rapidly, and perhaps the passive pull-down doesn't allow the MOSFET gates to discharge quickly enough, resulting in a PWM signal that looks more like a saw-tooth wave than the ideal square wave shape.

Using a 7400-series inverting gate solves that problem, I suspect. The gate's output pin has both an n-channel and a p-channel mosfet, so it can actively pull the signal high or low, and no passive resistor pull-up/pull-down is needed. So the output signal is a nice clean square wave.

1 Like

That makes a lot of sense thanks for the explanation :+1:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.