the wonderful world of multiplexingfedericomuelas.com/sva/physical_computing_class/5... ·...

5
The Wonderful World of M ultiplexing PART II of II Exercise Link: http://federicomuelas.com/sva/multiplexing/ TLC5940 16 channel LED driver Today we are learning how to work with the top notch TLC5940 16 channel LED driver. With this IC you’ll be able to control regular and RGB LEDs to create your monocolor, multicolor and full- color LED displays. Think of Signboards, cool fading LED displays, or simple display backlighting. Not only you can work with LED but anything that use PWM as its controlling system; Servos, Regular motors, even large incandescent lights (using the proper Darlington array of course). AN ENDLESS WORLD OF POSSIBILITIES! The TLC5940 has; -16 channels -12 bit grayscale PWM control, that’s 4,096 steps!! -serial data interface (easy to control with Arduino) -It work up to 30 Mhz Data Transfer Rate, 30,000,000 cycles per second!. This are the RECOMMENDED OPERATING CONDITIONS (so you can make sure you don’t burn your stuff) VCC (Voltage Supply)- from 3 to 5,5 volts DC VO (Voltage applied to output (OUT0–OUT15))- up to 17 volts DC. Remember this chip is a constant-current sink LED driver. What means that it internally connects the output to ground using PWM, that why it can take a different voltage than the one we are providing on VCC. Drive Capability (Constant-Current Sink) - if powered with less than 3,5 volts in VCC 60 mA. If voltage on VCC is between 3,5 and 5 V then 120 mA, since we are powering it with the Arduino we will get 120mA PIN MAP Pin name What it does? XERR This is a safety pin on the chip that let’s you know if chip is overheating or if one of the LEDs is broken (to much power!). You can connect this pin to one digital I/O on the Arduino for troubleshooting (or just an LED) SOUT Serial data out from the TLC5940. Unless you wish to try to read the error bits you do not need

Upload: trantram

Post on 02-Jul-2018

215 views

Category:

Documents


0 download

TRANSCRIPT

The Wonderful World of Multiplexing PART II of II

Exercise Link: http://federicomuelas.com/sva/multiplexing/

TLC5940 16 channel LED driver

Today we are learning how to work with the top notch TLC5940 16 channel LED driver. With this IC you’ll be able to control regular and RGB LEDs to create your monocolor, multicolor and full-color LED displays. Think of Signboards, cool fading LED displays, or simple display backlighting. Not only you can work with LED but anything that use PWM as its controlling system; Servos, Regular motors, even large incandescent lights (using the proper Darlington array of course).

AN ENDLESS WORLD OF POSSIBILITIES!

The TLC5940 has;

-16 channels -12 bit grayscale PWM control, that’s 4,096 steps!! -serial data interface (easy to control with Arduino) -It work up to 30 Mhz Data Transfer Rate, 30,000,000 cycles per second!.

This are the RECOMMENDED OPERATING CONDITIONS (so you can make sure you don’t burn your stuff) VCC (Voltage Supply)- from 3 to 5,5 volts DC

VO (Voltage applied to output (OUT0–OUT15))- up to 17 volts DC. Remember this chip is a constant-current sink LED driver. What means that it internally connects the output to ground using PWM, that why it can take a different voltage than the one we are providing on VCC.

Drive Capability (Constant-Current Sink) - if powered with less than 3,5 volts in VCC 60 mA. If voltage on VCC is between 3,5 and 5 V then 120 mA, since we are powering it with the Arduino we will get 120mA

PIN MAP

Pin name What it does? XERR

This is a safety pin on the chip that let’s you know if chip is overheating or if one of the LEDs is broken (to much power!). You can connect this pin to one digital I/O on the Arduino for troubleshooting (or just an LED)

SOUT

Serial data out from the TLC5940. Unless you wish to try to read the error bits you do not need

this to come to the Arduino. If you have more than one TLC5940 this is the line you daisy chain to the SIN of the next package.

XLAT

LATCH; you will need this to latch data after shifting.

SCLK

SHIFT: you will need this to shift data.

SIN

SERIAL IN: serial in to TLC5940, this is the output from the Arduino

GSCLK

CLOCK: this is the clock for the PWM

BLANK

This marks the end of a PWM cycle in addition to blanking the output

This chip works similar to the 74HC595 1 bit chip we used last class, but instead of registering one single bit per output (on/off) it registers 12 bit to set the pin in one of the 4,096 possible steps. After all data is clocked in, a high-level pulse of XLAT signal latches the serial data to the internal registers

Let’s now connect the TLC5940 to the arduino and a bunch of LEDs

In the real world it should look something like this

Now that the hardware is done let’s download the library from http://code.google.com/p/tlc5940arduino/ And install it on <Arduino Folder>/hardware/libraries/ These are the core functions for the tlc5940arduino library:

• Tlc.init(int initialValue (0-4095)) - Call this is to setup the timers before using any other Tlc functions. initialValue defaults to zero (all channels off).

• Tlc.clear() - Turns off all channels (Needs Tlc.update()) • Tlc.set(uint8_t channel (0-(NUM_TLCS * 16 - 1)), int value (0-4095)) - sets the grayscale data for

channel. (Needs Tlc.update()), example “Tlc.set(1, 4095);” • Tlc.setAll(int value(0-4095)) - sets all channels to value. (Needs Tlc.update()) • uint16_t Tlc.get(uint8_t channel) - returns the grayscale data for channel (see set). • Tlc.update() - Sends the changes from any Tlc.clear's, Tlc.set's, or Tlc.setAll's.

See the extended functions with detail description and examples at http://alex.kathack.com/codes/tlc5940arduino/html_r014/group__ExtendedFunctions.html

The Knight Rider And then let’s have some more fun and honoring David Hasselhoff we will recreate the Knight Rider LED effect

#include "Tlc5940.h" void setup() { Tlc.init(); }

/* NUM_TLCS is defined in "tlc_config.h" in the library folder. After editing tlc_config.h for your setup, delete the Tlc5940.o file to save the changes. */

void loop() { int direction = 1; for (int channel = 0; channel < NUM_TLCS * 16; channel += direction) {

/* Tlc.clear() sets all the grayscale values to zero, but does not send them to the TLCs. To actually send the data, call Tlc.update() */

Tlc.clear(); /* Tlc.set(channel (0-15), value (0-4095)) sets the grayscale value for one channel. value goes from off (0) to always on (4095). Like Tlc.clear(), this function only sets up the data, Tlc.update() will send the data. */

if (channel == 0) { direction = 1; } else { Tlc.set(channel - 1, 1000); } Tlc.set(channel, 4095); if (channel != NUM_TLCS * 16 - 1) { Tlc.set(channel + 1, 1000); } else { direction = -1; }

/* Tlc.update() sends the data to the TLCs. This is when the LEDs will actually change. */

Tlc.update(); delay(75); } }

Daisy chaining TLC5940s It is quite easy to daisy chain several TLC5940 by using the Tlc5940 library.

Firstly provide the second chip with all the controlling and data signals from the Arduino as shown below.

and secondly open the “tlc_config.h” file located on the Arduino Library folder (/Applications/Arduino.app/Contents/Resources/Java/libraries) and change the number of TLC connected in your circuit as shown here.

Now, run the “The Knight Rider” code again

SURPRISE!!