Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

Tlc5947 driver board
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Tlc5947 driver board

by darbyvet1 on Mon Jun 01, 2020 11:53 pm

24channelLED_driver_exampleworks9.ino
(4.47 KiB) Downloaded 2 times
I bought this board to control 24 LEDs with an arduino UNO.Everything works fine.I am using PROGMEM and look up tables to tell the board which LEDs to light.I find now that I have all 24 LEDs connected the speed is a bit slow. The led routines run a bit slower with 24 LEds connected vs 8 LEDS. I assume part of this is due to the fact the software is accessing the look up table and then doing bitmath to light each LED. I also noticed that the pins used in the adafruit example file that I used are not the hardware SPI pins.COuld I use the hardware SPI pins on the UNO to connect to the TLC5947? I assume this would be faster than the software SPI pins in the example sketch? If so I guess I would need the SPI library and would have to configure the SPI before I use the pins.

here is the sketch

thanks

Carl
24channelLED_driver_exampleworks9.ino
(4.47 KiB) Downloaded 2 times


Code: Select all | TOGGLE FULL SIZE
/***************************************************
  This is an example for our Adafruit 24-channel PWM/LED driver

  Pick one up today in the adafruit shop!
  ------> http://www.adafruit.com/products/1429

  These drivers uses SPI to communicate, 3 pins are required to
  interface: Data, Clock and Latch. The boards are chainable

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ****************************************************/


#include "Adafruit_TLC5947.h"
#include "avr/pgmspace.h"

const PROGMEM uint8_t BitMap[43] = {   // first row of 8 LEDs
  B00000001,
  B00000010,
  B00000100,
  B00001000,
  B00010000,
  B00100000,
  B01000000,
  B10000000,
  B01000000,
  B00100000,
  B00010000,
  B00001000,
  B00000100,
  B00000010,
  B00000001,
  B00000011,
  B00000110,
  B00001100,
  B00011000,
  B00110000,
  B01100000,
  B11000000,
  B11000000,
  B01100000,
  B00110000,
  B00011000,
  B00001100,
  B00000110,
  B00000011,
  B00000111,
  B00001110,
  B00011100,
  B00111000,
  B01110000,
  B11100000,
  B01110000,
  B00111000,
  B00011100,
  B00001110,
  B00000111,
  B00000011,
  B00000001,
  B00000000,

};

const PROGMEM uint8_t BitMap2[43] = {// second row of LEDs


  B00011000,
  B00011000,
  B00100100,
  B01000010,
  B10000001,
  B10000001,
  B10000001,
  B01000010,
  B00100100,
  B00011000,
  B00011000,
  B00011000,
  B00011000,
  B00100100,
  B01000010,
  B10000001,
  B10000001,
  B01000010,
  B00100100,
  B00011000,
  B00011000,
  B00011000,
  B00011000,
  B00100100,
  B01000010,
  B10000001,
  B10000001,
  B01000010,
  B00100100,
  B00011000,
  B00011000,
  B00011000,
  B00011000,
  B00100100,
  B01000010,
  B01000010,
  B10000001,
  B10000001,
  B10000001,
  B01000010,
  B00100100,
  B00011000,
  B00011000,

};

const PROGMEM uint8_t BitMap3[43] = {// second row of LEDs
  B00011111,
  B00011111,
  B00011111,
  B00011111,
  B00011110,
  B00011110,
  B00011110,
  B00011110,
  B00010111,
  B00010111,
  B00010111,
  B00010111,
  B00010111,
  B00010111,
  B00010110,
  B00001110,
  B00001110,
  B00001110,
  B00001110,
  B00001110,
  B00001110,
  B00001110,
  B00001110,
  B00010110,
  B00010110,
  B00010110,
  B00011111,
  B00011111,
  B00011111,
  B00011111,
  B00011110,
  B00011110,
  B00011110,
  B00011110,
  B00010111,
  B00010111,
  B00010111,
  B00010111,
  B00010111,
  B00010111,
  B00010110,
  B00001110,
  B00001110,

 

 
 

};

const PROGMEM uint16_t Pulse[43 ]={
 400,
 708,
 708,
1060,
1231,
1400,
1781,
1891,
2048,
2200,
2349,
2633,
2896,
3137,
3355,
3547,
3712,
3846,
4014,
4096,
4096,
4096,
4096,
4096,
4014,
3846,
3712,
3547,
3355,
3137,
2896,
2633,
2349,
2200,
2048,
1894,
1781,
1400,
1231,
1060,
708,
708,
400,
};






#define oe  -1                      // set to -1 to not use the enable pin (its optional) (Dont know what this does)

Adafruit_TLC5947 tlc = Adafruit_TLC5947(1, 5, 4, 6);// set up 24 channel LED driver


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

  tlc.begin();
  if (oe >= 0)    pinMode(oe, OUTPUT);
  digitalWrite(oe, LOW);

}
void loop() {

  for (byte x = 0; x < 43  ; ++x) // read the bytes from the array
  {
    readbitsandturnonleds (&BitMap[x], 0,8); // first row of LEDS
    readbitsandturnonleds (&BitMap2[x], 8,8); //Second row of LEDs
    readbitsandturnonleds (&BitMap3[x],16,5);
    pulsing(&Pulse[x]);


  }
}

void readbitsandturnonleds (uint16_t source, uint8_t LED, uint8_t bits) {
  byte data = pgm_read_byte (source);
  for (byte y = 0; y < bits; ++y) // read each bit of the byte
  {
    if (data & (1 << y)) // if the bit is one then turn the LED on
    {
      setLEDPWM ((y + LED), 4095); //Turn LED on

    }
    else // if the bit is zero turn the LED off
    {
      setLEDPWM ((y + LED), 0); // Turn LED off

    }
  }
}

void pulsing (uint16_t bright)
{
  int pwm=0;
 pwm=pgm_read_word_near(bright);
  tlc.setPWM(21,(pwm-100));

  tlc.setPWM(22,pwm);
 
 tlc.setPWM(23 ,(pwm-100));
tlc.write();
}
 

void setLEDPWM (uint8_t lednum, uint16_t pwm) // sends command to LED driver board to turn LED on or off
{
  tlc.setPWM(lednum, pwm);
  tlc.write();

}
Last edited by adafruit_support_bill on Tue Jun 02, 2020 5:35 am, edited 1 time in total.
Reason: added code in-line

darbyvet1
 
Posts: 11
Joined: Mon Jun 01, 2020 11:43 pm

Re: Tlc5947 driver board

by adafruit_support_bill on Tue Jun 02, 2020 5:37 am

The led routines run a bit slower with 24 LEds connected vs 8 LEDS. I assume part of this is due to the fact the software is accessing the look up table and then doing bitmath to light each LED.

The board has no way of knowing how many LEDs are connected. It will run at the same speed regardless. Did you change any code when you changed from 8 LEDs to 24?

adafruit_support_bill
 
Posts: 77923
Joined: Sat Feb 07, 2009 10:11 am

Re: Tlc5947 driver board

by darbyvet1 on Tue Jun 02, 2020 9:44 am

I initially had just 8 LEDs connected to the board.When I added more LEDS I just repeated the "readbitsandturnonleds" function and the sequence of lighting was definitely slower than just the 8 LEDS. I expected it to slow down a bit because there is more work for the Adruino to do.When I added the final function to pulse 3 LEDs using a sine wave look up table it got even slower. What I am trying to figure out is how to mamxise the code to speed things up.I am not sure where the lag is occurring.Is it accessing the flash memory to read the look up tables, or is it the code to write to the 5974.I was also not sure where to put the tlc.write function.Do I need to put that after every channel is set or could I put it at the end of the main loop so it is only called once all 24 LEDs are set.I was considering switching to a teensy 3.2 since it is a much faster microcontroller and I noticed when I was looking at the pins I needed to use that the example sketch does not use the hardware SPI pins on the UNO.How much difference would it make to use the hardware SPI pins rather than the digital pins in the example sketch.I havre had mixed results using the Teensy with arduino coding so if I can stick with the UNO I will.

thanks for you help
Carl

darbyvet1
 
Posts: 11
Joined: Mon Jun 01, 2020 11:43 pm

Re: Tlc5947 driver board

by adafruit_support_bill on Tue Jun 02, 2020 10:09 am

Calls to tlc.setPWM() don't take much time because they are writing to local memory only.
Calls to tlc.write() take more time because they need to communicate with the board.

When you call tlc.write() it always writes out all 24 LEDs worth of information. So it does not matter how many LEDs are connected. It only matters how many times you call it.

You have this setLEDPWM function which calls tls.write() every time you write to a single LED. If you are writing to multiple LEDs, you should save the tlc.write() call until the end and only call it once.
Code: Select all | TOGGLE FULL SIZE
void setLEDPWM (uint8_t lednum, uint16_t pwm) // sends command to LED driver board to turn LED on or off
{
  tlc.setPWM(lednum, pwm);
  tlc.write();

}

adafruit_support_bill
 
Posts: 77923
Joined: Sat Feb 07, 2009 10:11 am

Re: Tlc5947 driver board

by darbyvet1 on Tue Jun 02, 2020 10:29 am

Thanks for the explanation.that makes sense and is probably at least part of the reason the code is slowing down.Do you have any suggestions on using the hardware SPI pins vs the ones in the sketch (digital 4,5,6).Would that speed things up significantly?

I really apprecaite your help

Carl

darbyvet1
 
Posts: 11
Joined: Mon Jun 01, 2020 11:43 pm

Re: Tlc5947 driver board

by adafruit_support_bill on Tue Jun 02, 2020 10:48 am

There is no formal protocol specification for SPI and there are lots of not-quite-compatible implementations out there. I believe that the TLC chips fall into that category, so the libraries needed to use software SPI to talk to them.

adafruit_support_bill
 
Posts: 77923
Joined: Sat Feb 07, 2009 10:11 am

Re: Tlc5947 driver board

by darbyvet1 on Tue Jun 02, 2020 11:06 am

Ok thanks- you have been very helpful.

Carl

darbyvet1
 
Posts: 11
Joined: Mon Jun 01, 2020 11:43 pm

Re: Tlc5947 driver board

by darbyvet1 on Tue Jun 02, 2020 9:12 pm

Just an update. The problem was my error due to where I put the tlc.write function.I changed my code so it does just one tlc.write once all 24 LEDs have been set.Now the code runs really quickly.Thanks again for the help.

Carl

darbyvet1
 
Posts: 11
Joined: Mon Jun 01, 2020 11:43 pm

Re: Tlc5947 driver board

by adafruit_support_bill on Wed Jun 03, 2020 5:38 am

Good to hear you've solved it. Thanks for the update.

adafruit_support_bill
 
Posts: 77923
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.