Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
electric_domi
 
Posts: 9
Joined: Wed Feb 22, 2023 4:12 pm

Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by electric_domi »

Hi Guys,

I'm trying to create a very simple RGB-rainbow-like sequence with the Adafruit 12-Channel 16-bit PWM LED Driver controlled via SPI from a Arduino Pro Mini via SPI. In the final setup the Adafruit should control 4 RGB LED Strips with a common 12V connection, which will have their own power supply then:
[1]
[1]
Adafruit_TLC59711_with_MOSFET_controlled_LED_Strips.PNG (307.11 KiB) Viewed 310 times


For easier debugging, I replaced the LED strips with red, green and blue single LEDs (on only 2 of 4 channels):
[2]
[2]
Adafruit_TLC59711_with_debug_single_LEDs.jpeg (158.26 KiB) Viewed 310 times
After a lot of testing, it seems that the sample code from Adafruit is somehow not working as intended (alltough I can not really imagine that). I'm no programmer by any means so that's why I have a hard time figuring out what the problem really is.

My Setup:
My simple setup consists out of the Arduino, the TLC59711 breakout board and 6 LEDs for currently two channels assembled as shown in my quick and dirty schematic.

My Code
The code shown here is the example code that comes with the Adafruit Breakout Board. The code compiles without any problems.

Code: Select all

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

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

#define data   11
#define clock  13

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

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

  rainbow(5); // the function I want to work with
  
}

void loop() 
{
  colorWipe(65535, 0, 0, 100); // "Red" //"wipe" means to me "turn off" but in this case red gets turned on.
  delay(200);
  colorWipe(0, 65535, 0, 100); // "Green" 
  delay(200);
  colorWipe(0, 0, 65535, 100); // "Blue" 
  delay(200);
 }


// Fill the dots one after the other with a color
void colorWipe(uint16_t r, uint16_t g, uint16_t b, uint8_t wait) {
  for(uint16_t i=0; i<8*NUM_TLC59711; i++) {
      tlc.setLED(i, r, g, b);
      tlc.write();
      delay(wait);
  }
}
 
// Rainbow all LEDs at the same time, same color
void rainbow(uint8_t wait) {
  uint32_t i, j;

  for(j=0; j<65535; j+=10) {
    for(i=0; i<4*NUM_TLC59711; i++) {
      Wheel(i, (i+j) & 65535);
    }
    tlc.write();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint32_t i, j;

  for(j=0; j<65535; j+=10) { // 1 cycle of all colors on wheel
    for(i=0; i < 4*NUM_TLC59711; i++) {
      Wheel(i, ((i * 65535 / (4*NUM_TLC59711)) + j) & 65535);
    }
    tlc.write();
    delay(wait);
  }
}

// Input a value 0 to 4095 to get a color value.
// The colours are a transition r - g - b - back to r.
void Wheel(uint8_t ledn, uint16_t WheelPos) {
  if(WheelPos < 21845) {
    tlc.setLED(ledn, 3*WheelPos, 65535 - 3*WheelPos, 0);
  } else if(WheelPos < 43690) {
    WheelPos -= 21845;
    tlc.setLED(ledn, 65535 - 3*WheelPos, 0, 3*WheelPos);
  } else {
    WheelPos -= 43690;
    tlc.setLED(ledn, 0, 3*WheelPos, 65535 - 3*WheelPos);
  }
}

//All RGB Channels on full colour
//Cycles trough all brightness settings from 0 up to 127
void increaseBrightness(){
  for(uint16_t i=0; i<8*NUM_TLC59711; i++) {
      tlc.setLED(i, 65535, 65535, 65535);
  }
  for(int i = 0; i < 128; i++){
    tlc.simpleSetBrightness(i);
    tlc.write();
    delay(1000);
  }
}
My Problem: Flickering LEDs
The main issue I have with that "rainbow" function is, that I get a lot of LED flickering when executing it. You can find a video of it here: https://youtu.be/WvfPnrw17g4. Ignore the MOSFETs in the Background, they are disabled. The video shows the functional schematic from the second picture [2]. There is no smooth transition between the colors but more the fear of getting an epileptic seizure. The Power supply is not the problem, it can deliver enough current. If I turn on the LEDs statically e.g. with the function "colorWipe" then there's no flickering. I have the same issue with the LED Strips, where I control them via individual MOSFET.

What I want
A smooth rainbow-like color fade throughout all 4 LED strips. Like CH0 should e.g. start with red, CH1 with orange, CH2 with green and CH3 with blue. This should fade then with all the colors in between from CH0 to CH3 in a endless loop:
[3]
[3]
rgb_fade.png (465.15 KiB) Viewed 310 times


Since I tried so many different things (single LEDs vs Strips, MOSFETs, even BJ Transistors) and since I get this flickering every time with this "rainbow" (with "rainbowCycle" as well) function, I think that the code somehow is the crux of the matter. Has anyone of you an idea? If you need more Information please ask! And sorry if I forgot something to mention. Thanks in advance!

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by adafruit_support_mike »

That flicker pattern looks like RGB values out of range for the LED controller.

Try printing the RGB values using Serial.print() as you send them to the TLC59711, and look for values that correspond to the flickering.

User avatar
electric_domi
 
Posts: 9
Joined: Wed Feb 22, 2023 4:12 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by electric_domi »

Sorry for the late reply. I'll try that and update my post here when I did so. Thank's for the input.

User avatar
electric_domi
 
Posts: 9
Joined: Wed Feb 22, 2023 4:12 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by electric_domi »

I still have no clue what is going on. I checked the connections and tried different supply variants for the arduino and the tlc breakoutboard suggested by adafruit. Nothing changed. LED flickering is still there. Has anyone an idea on how to use e.g. a different code so I can get my RGB fading to work?

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by adafruit_support_mike »

Try setting PWM values manually for the first few LEDs. Do you still see flickering when the values are less than 255?

User avatar
electric_domi
 
Posts: 9
Joined: Wed Feb 22, 2023 4:12 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by electric_domi »

I did some testing and this is what I found:

1.) I tried to set one LED via the "setPWM" function at a time. The function in the .ccp file looks like this:

Code: Select all

/*!
 *  @brief  Set PWM value on selected channel
 *  @param  chan
 *          one from 12 channel (per driver) so there is 12 * number of drivers
 *  @param  pwm
 *          pwm value
 */
void Adafruit_TLC59711::setPWM(uint16_t chan, uint16_t pwm) {
  if (chan > 12 * numdrivers)
    return;
  pwmbuffer[chan] = pwm;
}
I created a small loop where I swept the PWM value (basically the brightness) for the individual LEDs (one at a time only).
While I did this for all 12 channels, I noticed, that when I sweep CH0 (R) and CH1 (G) the blue LED on CH11 flickers periodically and always at the same point.
A similar thing happens when I sweep the LED on CH3 (R) and CH4 (G), then CH8 flickers. Sweep CH6 (R) and CH7 (G) --> CH5 flickers, sweep CH9 (R) and CH10 (G) --> CH2 flickers.

On the scope it looks like this, e.g. everytime the blue LED on CH8 "fires". Blue Scope Channel = blue LED on CH8, Red Scope Channel = red LED on CH3:
Scope Picture of LED CH3 vs. CH8
Scope Picture of LED CH3 vs. CH8
8DA25878-CB4C-4354-92E8-E55E286ED3AB.jpeg (560.8 KiB) Viewed 228 times
Here you can also see a video: https://youtube.com/shorts/iHCeV9LOdhE?feature=share

This only happens, when I sweep the PWM value in a loop. If I set the PWM value manually to any value, it does not flicker at all.

Here's my code when the flickering appears:

Code: Select all

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

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

#define data   11
#define clock  13

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

int main() {
  Serial.begin(9600);
  
  //Serial.println("TLC59711 test");
  
  // 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();

  uint16_t count_val = 0;
  uint16_t limit = 65535;
 for(uint16_t count_val = 1; count_val <= 65535; count_val = count_val+100)
 {
 
  tlc.setPWM(6, count_val);

  tlc.write();
 }

return 0;
}
This is the source of the sample code: https://github.com/adafruit/Adafruit_TLC59711

A very similar behaviour appears when I run that "rainbow" function I described in the past.

The circuit is built up like Adafruit described it on their website. That means I only connected one LED directly to each channel, supplied by 12V. Like so but with individual red, green and blue LEDs:
Adafruit Image via https://learn.adafruit.com/tlc5947-tlc59711-pwm-led-driver-breakout/power-and-leds
Adafruit Image via https://learn.adafruit.com/tlc5947-tlc59711-pwm-led-driver-breakout/power-and-leds
leds-1024.jpg (47.02 KiB) Viewed 228 times

I do not get what is wrong with the code and why this is not working.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by adafruit_support_mike »

Hrm.. strange.

What does a trace of the TLC59711's Vin show at the same time?

User avatar
electric_domi
 
Posts: 9
Joined: Wed Feb 22, 2023 4:12 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by electric_domi »

The supply voltage (5V via an LDO) is not affected by that (red Scope-Channel = V_supply @5.19V and blue Scope-Channel = blue LED on TLC59711 Channel 5) and also not on the 12V LDO Input Voltage. There's also no visible effect on bigger "zoom levels" for the red Scope-Channel on either supplies):
Blue LED on TLC59711 CH5 vs. V_supply
Blue LED on TLC59711 CH5 vs. V_supply
0041ED46-D4BA-4906-B28B-E7B641F5FC62.jpeg (865.6 KiB) Viewed 220 times
Supply circuit:
Supply circuit
Supply circuit
34BC345B-3020-4AE3-8043-5370B01A70C0_1_201_a.jpeg (105.13 KiB) Viewed 220 times

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by adafruit_support_mike »

Thanks. That means something is going on inside the TLC59711.

Send a note containing a link to this page and your order number to [email protected]. The folks there will get you a replacement.

User avatar
electric_domi
 
Posts: 9
Joined: Wed Feb 22, 2023 4:12 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by electric_domi »

This is what I thought in the beginning as well. I tested two boards, both had the same error and both boards have a strange silk text mistake on them as you can see:
IMG_2981 (2).jpg
IMG_2981 (2).jpg (398.89 KiB) Viewed 216 times
I ordered the third board now from a different vendor. Maybe Amazon is selling broken sh**.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by adafruit_support_mike »

Hmm.. I'll have to check that out.

We don't sell through Amazon at all, but some of our resellers do. However, there are also people who use our name and board designs without our permission.

User avatar
electric_domi
 
Posts: 9
Joined: Wed Feb 22, 2023 4:12 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by electric_domi »

This is the link to the (german) amazon product page I bought it from: https://www.amazon.de/dp/B00SLYAYU8?psc ... ct_details

Maybe you can check that. I don't think that genuine adafruit product should have silk errors. I'll receive my new board today or tomorrow, then I'll check if this one is okay or not. I'll let you know.

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by adafruit_support_mike »

I checked, and we did have a run of boards with those typos. It happens sometimes. ;-)

That just confirms the replacement you're getting. Let us know if it works for you!

User avatar
electric_domi
 
Posts: 9
Joined: Wed Feb 22, 2023 4:12 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by electric_domi »

I tested the same code now with the third TLC59711 Adafruit board. Still the same error. I really have no idea what the problem is. Measuring with the oszi also gives me no hint. What should I do? :-(

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Flickering LEDs - Incorrect C-Code (with Adafruit 12-Channel 16-bit PWM LED Driver)

Post by adafruit_support_mike »

Okay, two boards showing the same anomaly suggests the effect of something around the boards.

Try moving the breakout to a new breadboard, replacing the jumpers, swapping LEDs, using a new power supply, and so forth. Rebuild the circuit one piece at a time and test as much as you can each step of the way. Sometimes it takes a lot of random fiddling to locate the first clues to a low-level problem.

Under those conditions, diagnosing the problem has to come second to simply making the problem change repeatably.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”