Teensy 3.6 is very slow for some reason...

Status
Not open for further replies.
The first block looks about right - the second is not right.

As included in the 3rd code block that looks about right. These statements may be causing trouble? Unless their example shows doing that the pins should be set properly by either the creation of the "tlc" or the SPI.begin():
pinMode(latch, OUTPUT);
digitalWrite(latch, LOW);
pinMode(clock, OUTPUT);
digitalWrite(clock, LOW);
pinMode(data, OUTPUT);
digitalWrite(data, LOW);

Does this mean there are FIVE units? :: #define NUM_TLC5974 5

If so starting with a single unit might change initial results.
 
Code:
    /*
    SPI.setCS(10);
    SPI.setMOSI(11);
    SPI.setSCK(13);*/
Try removing the comments to actually use the code
 
One quick hack you can do to increase the performance is start with the Adafruit library, and change all the digitalWrite calls inside the write() function to digitalWriteFast. This cuts the SPI transfer time down by over 50% (according to my measurement) which may be fast enough to do what you want to do.

Looking more at the library that I posted earlier... https://github.com/ramonaoptics/TLC5947 ... it has compilation issues deeper than just the example code, and I don't feel like fixing it. But his code has the right idea, the LED data needs to be "packed" into exactly 12 bits per LED to work with hardware SPI.
 
@wcalvert, Thanks I will try the digitalWriteFast() thing. I would like to figure out the hardware SPI thing too. I just got a new Teensy and I'm going to start over with this and just try and figure it out (my other Teensy has a lot of things connected to it).

I have hope in this thread:

https://forum.pjrc.com/threads/42214-Need-help-on-using-SPI-library

and I'm going to try and recreate that.

@thebigg: I'm pretty sure I included that bit of code. If I had it commented out that would be the craziest mistake. But I tried a lot of variations, commenting things out, added things, trying different pins, etc. Thanks for pointing that out.
 
Hi everyone,

I finally, after tons of hours, am able to use the hardware SPI to control the LEDs using the TLC5947 board. Wow, that took awhile.

I want to thank everyone for their input, advice and help. I really think this is one of the best forums for advice out there. And I am sure I will have more questions to ask soon.

I am posting the example code that worked for me, which I copied from another post on this forum. The only thing I changed was what pins to use.

Thank you again

Code:
#include <Adafruit_TLC5947.h>
#include <SPI.h>

const int slaveSelectPin = 10;
#define clock 13 // 10 
#define data 11
#define oe  15  //  12
#define latch  10 // 11
#define NUM_TLC5974 2

unsigned long frame;
Adafruit_TLC5947 tlc = Adafruit_TLC5947(NUM_TLC5974, clock, data, latch,  oe);
unsigned long tick, dur;

void setup() { 


  pinMode(latch, OUTPUT);
  digitalWrite(latch, LOW);
  pinMode(clock, OUTPUT);
  digitalWrite(clock, LOW);
  pinMode(data, OUTPUT);
  digitalWrite(data, LOW);

  
    SPI.setCS(10);
    SPI.setMOSI(11);
    SPI.setSCK(13);
  SPI.begin();
  //tlc.begin();

  
 // Serial.begin(38400);
 // delay(1000);
 // Serial.println("TLC5974_SPI test");
}

void loop() {
  //////
  tick = micros();
  colorWipe(0, 0, 100); // "Red" (depending on your LED wiring);
  Serial.print((micros() - tick));
  Serial.print("  red used");
  Serial.println("  us");
  delay(1500);
  //////
  tick = micros();
  colorWipe(0, 100, 0); // "Green" (depending on your LED wiring);
  Serial.print((micros() - tick));
  Serial.print("  green used");
  Serial.println("  us");
  delay(1500);
  //////
  tick = micros();
  colorWipe(100, 0, 0); // "Blue" (depending on your LED wiring);
  Serial.print((micros() - tick));
  Serial.print("  blue used");
  Serial.println("  us");
  delay(1500);
  //////
  tick = micros();
  colorWipe(5, 5, 5); // "Blue" (depending on your LED wiring);
  Serial.print((micros() - tick));
  Serial.print("  white used");
  Serial.println(" us");
}

void colorWipe(uint16_t r, uint16_t g, uint16_t b) {
  for (uint16_t i = 0; i < 8 * NUM_TLC5974; i++) {
    tlc.setLED(i, r, g, b);
  }
  SPIwrite();
}


void SPIwrite() {
#define TSPEED 1000000 //1Mhz
  unsigned int chan1 = 0;
  unsigned int chan2 = 0;
  byte address1 = 0;
  byte address2 = 0;
  byte address3 = 0;
  SPISettings TLC5947(TSPEED , MSBFIRST, SPI_MODE0);
  // packing each 2 channel (12bit*2) to 3 byte (8bit*3) for transfering
  SPI.beginTransaction(TLC5947);
  // digitalWriteFast(latch, HIGH);
  digitalWriteFast(latch, LOW);
  for (unsigned int ledpos = 24  * NUM_TLC5974 ; ledpos > 0; ledpos = ledpos - 2) {
    chan1 = tlc.getCHAN(ledpos - 1);
    chan2 = tlc.getCHAN(ledpos - 2);
    address1 = (byte)(chan1 >> 4) ;
    address2 = (byte)((chan1 << 4) & (B11110000)) + (byte)((chan2 >> 8) & (B00001111));
    address3 = (byte)chan2;
    /* address1 = B00000000;
      address2 = B00000000;
      address3 = B00000000;*/
    SPI.transfer(address1);
    SPI.transfer(address2);
    SPI.transfer(address3);
  }

  SPI.endTransaction();
  //  digitalWriteFast(latch, LOW);
  digitalWriteFast(latch, HIGH);
  digitalWriteFast(latch, LOW);
  digitalWriteFast(clock, LOW);
}
 
Status
Not open for further replies.
Back
Top