Eliminate LED fast flickering from PWM breakout board and Teensy 3.6

Status
Not open for further replies.

nicnut

Well-known member
Hi,

This is a follow up to a previous post:

https://forum.pjrc.com/threads/56834-Best-way-to-expand-the-number-of-Digital-Outputs-on-Teensy-3-6

I am trying to get more digital outputs from a teensy 3.6 for some RGB LED button switches I’m using. So I am using a PWM breakout board. Right now I hooked up 4 of the switches and the LEDs are flickering really fast. It’s kind of annoying and I would like to eliminate this so that they look more solid.

Here is a link to the button switches I’m using:

https://www.masterelectronics.com/e-switch/lp6oa1asrgb-48219535.html

Here is the PWM breakout board I’m using. I’m sure some of you have used it as it seems pretty popular:

https://www.adafruit.com/product/1429

Wiring:

I am using Vin to power the breakout board. I am using the Teensy digital pins 30, 29 and 28 for Data, Clock and Latch. From the breakout board I tried powering the LEDs with just one wire from the board (V+), then I tried using 4 of these wires, thinking it would make the LEDs flicker less, but that didn’t work.

Any ideas on how to eliminate this flickering?

Also, i accidentally used Analog outs once and the LEDs looked way brighter, which was way more prefferable. Is there a way to make these things brighter as well? Or maybe that is part of the problem, in that if they are brighter I won’t see the flickering.

I am not using any resistors or capacitors. I tried putting a big capacitor between Vin and Ground on the breadboard coming from the Teensy and it didn’t do anything.

I added an extra tlc.write(); at the end of the code because a friend suggested that it would help. It actually did minimize the flickering a little bit, but it’s still there.

Also, I tried adding a delay between the 2 lines of tlc.write();

So like this:

tlc.write();
delay(200);
tlc.write();

And it really helped but didn't totally eliminate the flickering. I think what I am seeing is the actual modulations of the pulse width. I don't want any delays in my final code however.


Also, just for your information, I will be ultimately be using this as a MIDI controller and these LEDs will need to be changing colors all the time. I think that's possible if I code it correctly, but if that’s not correct with this PWM breakout board method please let me know.


Below is the code I am using for my testing/prototyping now.

Thank You. Nick

Code:
#include "Adafruit_TLC5947.h"

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

#define data   30        // digital pins on the Teensy
#define clock   29
#define latch   28
#define oe  -1  // set to -1 to not use the enable pin (its optional)

Adafruit_TLC5947 tlc = Adafruit_TLC5947(NUM_TLC5974, clock, data, latch);

void setup() {
  Serial.begin(9600);

  Serial.println("TLC5974 test");
  tlc.begin();
  if (oe >= 0) {
    pinMode(oe, OUTPUT);
    digitalWrite(oe, LOW);
  }
}

void loop() {

  // how you set LED colors for individual LEDs

  
  tlc.setLED(0, 255, 0, 0);    // (LED number, R value, G value, B value)
  tlc.setLED(1, 226, 255, 3);
  tlc.setLED(2, 255, 255, 255);
  tlc.setLED(3, 0, 0, 255);
  tlc.write();
  tlc.write();
   
}
 
Last edited:
I think there may be an issue with the constructor: Adafruit_TLC5947 tlc = Adafruit_TLC5947(NUM_TLC5974, clock, data, latch);

Okay '1' is right - but the "#define NUM_TLC5974 1" label has transposed digits '74' not '47'

It says it is an SPI interface : adafruit.com/tlc5947-tlc59711-pwm-led-driver-breakout?view=all#overview
> That would suggest that:
>> MOSI0 ALT on pin 28 might be DO or data
>> SCK0 ALT pin 27 SCK0 would be clock

Maybe their driver doesn't look for true SPI hardware with the indicated pins working at all ??? - and for non ALT SPI it would use the indicated pins 11=MOSI=data and 13=SCK0=clock

Perhaps the links indicated suggest it works on these non-standard pins - but a double check might help.

In reading the above perhaps it says -2 for latch is ignore - maybe that is in the examples? But not clear on that:
TLC5947 Library Reference:
Adafruit_TLC5947(uint8_t n, uint8_t c, uint8_t d, uint8_t l)
Call the constructor to create an instance of the TLC5947 PWM breakout driver.
n = Number of Drivers (>1 if the drivers are chained)
c = Clock pin
d = Data pin
l = Latch pin

Perhaps the non use of a latch pin it why they flicker?
 
Also , it might be a problem to update the LEDs some thousand times per second.
For a quick test, you could a delay(1000); to your loop.
 
Hey Frank B.

Thanks for the reply! Wow, I'm impressed that you saw the transposed 4 and 7 in: Adafruit_TLC5947 tlc = Adafruit_TLC5947(NUM_TLC5947, clock, data, latch);

I would have never seen that. I fixed that.


I tried using pin 27 for clock, and I added the latch pin on pin 31. None of these things worked. I'm sad. I don't know what else I can try.

I did try the delay(1000); and that did minimize the flickering, but I don't think I can have a delay in my code, because I can't have the code stop running for that amount of time.

I guess I could add a current millisec counter or something, but I will need these colors updating way faster than that so I can't see how that will work.

The only other idea I have is to swap out the Adafruit board and try another one. Maybe I damaged it trying all these different wiring configurations out. It's a long shot, but I don't have any other ideas. If anyone has used these boards with a Teensy PLEASE let me know what you did and what worked.

Thanks, Nick
 
Update:

Ultimately what I am creating is a midi controller. I incorporated the code from this PWM breakout board and LED control into my existing MIDI controller code.

Before I uploaded I selected USB type: MIDI.

I am able to use midi control change output to control the color of the LEDs. I can control them separately and they don't seem to affect each other.

I think I know why this worked. I have the color control in an if statement. If the Teensy gets a certain message the color changes, other wise nothing happens. So if I send one message it changes the color and doesn't do anything else. In the previous code i had the color was in a loop and constantly being sent to the PWM board.

Now, the only problem I have is that these LEDs are not bright enough.
I had the wires connected wrong recently, like latch and data or something was mixed up, and the LEDs were beautiful and bright. I wish I could figure out how to get these things brighter.

Any ideas are greatly appreciated.

Thank You.

Nick
 
As I read the adaFruit notes it said current is limited to 15 mA by a common SMD resistor. There are pin holes so that resistor could be replaced and there were notes about selecting the right resistor for the desired current. No idea beyond that what those LEDs are made to handle.

Something like this
Code:
#define FPS 10 // Decide how often the LEDS should be updated in frames per sec. 
uint32 Value;
elapsedMillis nextUpdate;
setup(){
  // …
  Value=1000/FPS;
  nextUpdate = 0;
}

loop() {
if ( nextUpdate > Value ) {
  nextUpdate -= Value;
  // update LEDs
  }

// do other code without delay
}
 
@defragster

Yes this makes a lot of sense! If I can replace that resistor with a smaller value I believe the LEDs will be brighter. OK I'll try and figure out how to do that. Thanks for pointing that out, I would never have thought about that.
 
Hope it helps. Try to get the code working consistently before editing the board. They may be dim but they should work reliably if the board if good. Then make best attempt to find safe current value that won't toast the LEDs. And as noted on the Adafruit page - make sure the current supply is up to the task of putting that current out to all the LEDs and not start anything. That would actually be a good place to START - is all power from USB through Teensy or a suitable supply properly wired to the ADAf board?
 
@defragster

Yes that's a good point. Right now nothing is connected to my Teensy except that board and 4 LED/button switches. The board is powered from the Vin connection on the Teensy.

It's funny you should say this, because I've had the Teensy just randomly power down a few times. I'll unplug it and plug it back in a few times till it connects to my computer again. I've never had a Teensy go offline on me, they are incredibly reliable, so it raises a red flag for me.

But I think my code is good and the LEDs are not flickering, so that's good.
 
Hey Frank B.

Thanks for the reply! Wow, I'm impressed that you saw the transposed 4 and 7 in: Adafruit_TLC5947 tlc = Adafruit_TLC5947(NUM_TLC5947, clock, data, latch);

I would have never seen that. I fixed that.
The honour is due to Sir defragster.
 
Status
Not open for further replies.
Back
Top