TLC5916 Configuration Code Setting

TLC5916 Writing Config Code

TLC5916 Writing Config Code

The TLC5916 data sheet clearly shows that you write the configuration code (which controls the LED current) by shifting seven bits in, then raising LE during the 8th SCK pulse while simultaneously shifting the 8th bit.

That makes no sense whatsoever: you couldn’t use standard SPI hardware in a chained configuration, because you’d have to blip LE while shifting.

In fact, the chip doesn’t work that way. You set the config code in Special Mode just like you set the LED driver bits in Normal Mode: shift ‘em all in, then blip LE to latch ‘em into the parallel holding register.

Here’s the code to make it happen…

DisableSPI();                               // manual SPI control

 digitalWrite(PIN_DISABLE_DISPLAY,HIGH);    // initial condition
 digitalWrite(PIN_LATCH_DO,LOW);

 PulsePin(PIN_SCK);                         // 1
 digitalWrite(PIN_DISABLE_DISPLAY,LOW);
 PulsePin(PIN_SCK);                         // 2
 digitalWrite(PIN_DISABLE_DISPLAY,HIGH);
 PulsePin(PIN_SCK);                         // 3
 digitalWrite(PIN_LATCH_DO,HIGH);           //   sets Special Mode
 PulsePin(PIN_SCK);                         // 4
 digitalWrite(PIN_LATCH_DO,LOW);
 PulsePin(PIN_SCK);                         // 5

//-- Send brightness level

 EnableSPI();                               // turn on SPI hardware

 SendRecSPI(Brightness);
 SendRecSPI(Brightness);
 SendRecSPI(Brightness);
 SendRecSPI(Brightness);
 SendRecSPI(Brightness);

 PulsePin(PIN_LATCH_DO);                    // latch new shift reg contents into drivers

//-- put LED drivers back in Normal Mode

 DisableSPI();

 digitalWrite(PIN_DISABLE_DISPLAY,HIGH);     // initial condition
 digitalWrite(PIN_LATCH_DO,LOW);

 PulsePin(PIN_SCK);                          // 1
 digitalWrite(PIN_DISABLE_DISPLAY,LOW);
 PulsePin(PIN_SCK);                          // 2
 digitalWrite(PIN_DISABLE_DISPLAY,HIGH);
 PulsePin(PIN_SCK);                          // 3
 digitalWrite(PIN_LATCH_DO,LOW);             //   sets Normal Mode
 PulsePin(PIN_SCK);                          // 4
 digitalWrite(PIN_LATCH_DO,LOW);
 PulsePin(PIN_SCK);                          // 5

 digitalWrite(PIN_DISABLE_DISPLAY,LOW);      // turn the LEDs on again

The SendRecSPI() function does exactly what you’d expect:

byte SendRecSPI(byte Dbyte) {                // send one byte, get another in exchange

 SPDR = Dbyte;                      // assume it's OK to send a new byte

 while (! (SPSR & (1 << SPIF))) {   // wait for shift to finish
  continue;
 }

 return SPDR;                       // SPIF will be cleared
}

I don’t know. Maybe the chip also works the way they show in the datasheet, but I doubt it’s worth finding out.

About these ads
  1. #1 by m stadtler on 27-February-2010 - 15:50

    Is it required that you set the current if you use a limiting resistor?

    • #2 by Ed on 27-February-2010 - 16:31

      The TLC5916 current-setting resistor determines the LED current range for all eight outputs: you do not have a traditional current-limiting resistor for each LED.

      That’s pretty much the whole reason you use one of these chips: you get program control over the LED current within a range that doesn’t exceed the LED maximum current specification.

      It’s not the right hammer for the job when you need different currents in each LED or you don’t need program control over the LED current.

      • #3 by mike stadtler on 3-March-2010 - 12:00

        Unfortunately I already bought the “hammer” and board or 2 to go with it.

        Is the current setting code required if I just want full on?

        • #4 by Ed on 3-March-2010 - 12:20

          According to page 17 of the datasheet, it’s full throttle at power up: current = (1.25 / Rext) x 15.

          If you’re planning to add resistors in the segments to vary their current, that probably won’t work well. The driver wants to control the current, so the voltage across the LED varies to make the answer come out right. Whatever you’re figuring for the effective LED voltage will be wrong and the current will be different than you expect, which will make a mess of the relative brightness values.

  2. #5 by Steven on 23-November-2012 - 12:18

    Thanks very much for this info! I’m working on an museum exhibit on temperature vs pressure, and I’d like to use the TLC5916 to drive some 2″ 7-seg displays (8v per segment). Any way you could share your code on driving the 7-seg displays? I’m having trouble with the protocol.

    Thanks in advance for any help you can provide!

    • #6 by Ed on 23-November-2012 - 13:01

      code on driving the 7-seg displays

      The whole Totally Featureless Clock appeared over the course of three Circuit Cellar issues (February / April / June 2010), with the code in the ZIP file for April: Issue 237 ZIP file. The SetLEDBrightness() function shows how to get into and out of the Special Current Adjust Mode.

      You should almost certainly use the Official SPI library, rather than my hacked-together version, to actually send the bits…

      • #7 by Steven on 12-December-2012 - 11:40

        Thanks very much for your help Ed! I was able to get it working (easily) using the ShiftOut arduino function, and will likely use the SPI library for final implementation.

        • #8 by Ed on 12-December-2012 - 13:04

          Excellent!

          In the unlikely event I ever get out that way, I must drop in to see what you’re doing!

          • #9 by Steven on 12-December-2012 - 13:50

            Definitely. Hopefully we’ll have a pro doing the tech stuff by then…