Go Down

Topic: TLC5947 and Arduino Zero (Read 452 times) previous topic - next topic

adri_lag

Hello,

I am using the Adafruit TLC5947 LED driver board connected to an Arduino Zero, because I need to control several LEDs and I need more power than the UNO (or Nano) can provide. I have tested the system with a Arduino Nano and everything works as expected, but if I replace the Nano for the Zero, I can appreciate a flash when the program starts and finishes to send data to the TLC driver.

Here you can see the code:
Code: [Select]

// TLC5947 library
#include "Adafruit_TLC5947.h"

// TLC5947 setup
#define NUM_TLC5947 1
#define data_TLC   3
#define clock_TLC   4
#define latch_TLC   5
#define oe  -1  // set to -1 to not use the enable pin (its optional)
Adafruit_TLC5947 tlc = Adafruit_TLC5947(NUM_TLC5947, clock_TLC, data_TLC, latch_TLC);

// delays
unsigned long previousMillis = 0;
const long interval = 1000;

// variation values - changing each second (determined by the "interval" constant)
int variation_value = 0;

// intensity function
void to_intensity() {
 SerialUSB.println(variation_value);
 if (variation_value) {
    // set the PWM for the different channels
    tlc.setPWM(0, 2000);
    tlc.setPWM(4, 2000);
    tlc.setPWM(8, 2000);
    tlc.setPWM(3, 2000);
    tlc.setPWM(16, 2000);
    tlc.setPWM(20, 2000);

    // write the TLC
    tlc.write();
  }
  //tlc.write();
}

void setup () {
  SerialUSB.begin(9600);
  // TLC setup
  tlc.begin();
  if (oe >= 0) {
    pinMode(oe, OUTPUT);
    digitalWrite(oe, LOW);
  }
}

void loop () {
  // storing the miliseconds
  unsigned long currentMillis = millis();
  // setting the values for the TLC continuously
  to_intensity();
  // every second
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    // change the variation value from 0 to 1 or viceversa
    if (variation_value == 0) {
      variation_value = 1;
    }
    else {
      variation_value = 0;
    }
  }
}


Basically, what is happening in this code is that the "variation_value" parameter changes its value from 0 to 1 every second, so the Arduino uses the tlc.write() function only when this parameter is equal to 1. This code is a simplification of another code, and the idea is to collect sensor data when the "variation_value" equals 0 (otherwise, interference is observed). Using the Arduino Zero, it is possible to see a flash every time the program starts and finishes using the tlc.write() function (when the "variation_value" changes from 0 to 1 or viceversa). If the function tlc.write() is called every loop, without the "variation_value" condition, everything works as expected and there is no flash. Also, when replacing the Arduino Zero for the Arduino Nano, the routine works better and the flash is practically imperceptible with exactly the same configuration.

I think that this issue is something related with the timing in the write() function of the Adafruit library, but I don't know how to solve it.

Any guess?

Thank you very much for your time.

Official Adafruit TLC5947 library: https://github.com/adafruit/Adafruit_TLC5947
Datasheet of TLC5947: http://www.ti.com/lit/ds/symlink/tlc5947.pdf

Wawa

#1
May 24, 2018, 11:20 pm Last Edit: May 25, 2018, 04:54 am by Wawa
That TLC5947 board expects 5volt logic on it's inputs (has onboard 5volt regulator).
Min logic HIGH must be 0.7*5 = 3.5volt (TLC datasheet).
The Zero is AFAIK a 3.3volt processor, and can't deliver that.
Leo..

Grumpy_Mike

 It the Adafruit product page says
Quote
Then send 3-5V logic SPI data on DIN (data in), CLK (clock) and LAT (latch)
Quote
I think that this issue is something related with the timing in the write() function of the Adafruit library, but I don't know how to solve it.
There is no write function in the Adafruit libiary, it is all SPI calls.

Sorry this is not a soloution but I can't understand what you are trying to do.

Go Up