TLC5916 Driver Library

GitHub repository can be found here: TLC5916 Driver Library

In continuation from the previous post, Coded: Curiosity-Nano — Thermistor with four 7-segment display, I wanted to write the rest of the code to take advantage of the Open Load and Overtemperature and Programmable Global Current Gain (no short circuit detection on the TLC5916 flavor.)

Simplified version from before. Easier to see a byte when they are all lined up.

Let’s start with the methods in TCL5916.h:


// param1: bits to send
// param2: number of bits to send
// param3: whether to pulse latch at end
void transmit(uint8_t p, uint8_t c, bool n); 

// Ability to enable/disable output drivers
void enableOutput();
void disableOutput();

// Macro to transmit either 0xFF or 0x00
// param1: how many chips are daisy chained together
void allOn(1);
void allOff(1);

// Ability to switch between modes
void switchToSpecialMode();
void switchToNormalMode();

// While in special mode, you can either
// write (current gain) configuration,
// or you can check for error codes
void writeConfiguration(uint8_t c);
uint8_t readErrorCodeStatus();

And here is example code using the methods above.

#include <atmel_start.h>
#include "TLC5916.h"
#include <util/delay.h>

uint8_t token;

int main(void)
{
	token = 1;
	
	atmel_start_init();
	_delay_us(100000);	
	
	switchToSpecialMode();
	writeConfiguration(WCC_FULL_BRIGHT);
	switchToNormalMode();
	enableOutput();
	
	while (1) {	
		transmit(token, 8, true);
		if(token == 128) {
			token = 1;
		} else {
			token = token << 1;
		}
		_delay_us(1000000);
	}
}

And that is it. Most everyone will only use Normal Mode, but switching over to Special Mode and checking for an error code is really simple, it makes sense to add that check to the end of your initialization.

Below I have a few short videos showing the special features in action. First up is changing the current gain. I should have tested with more than one LED, but in person, it was bright enough see it when it was dim.

The LED in the bottom of the shot is being toggled between full brightness and dimmed.

The next feature is open circuit detection. Pretty easy to guess what this one does…

I did not test the over-temperature detection, mainly because I don’t have a heat gun, and the error messages are transmitted the same method. So I am assuming if the MCU can read a open circuit error, it should be able to read the other error messages.

And feedback or pull-requests are appreciated. I have seen (after the fact) a Arduino library for this chip already exists, but contains application code, violating the Open-Closed principle (https://en.wikipedia.org/wiki/Open-closed_principle). In my opinion, this library should only give one layer of abstraction to simplify hardware access. So I think I might port this over to an Arduino library and call it TLC5916 Lite Library.

Please check out my recent posts to the right and thanks for following along!

Author:

Leave a Reply