USING TLC5940 TO GENERATE VARIABLE FREQUENCY PWM SIGNALS USING ARDUINO

TLC5940

· The Texas Instruments TLC5940, http://www.ti.com/product/tlc5940, is a 16 Channel LED Driver which can be used to run up to 16 LEDs, at set PWM values.

· The chips can be cascaded together, normally up to 16, which give up to 196 channels. There is an option to cascade more than that as well, but that has not been tried and tested internally yet. More on that below.

· All channels are synced.

· The chip can deliver up to 120mA per channel.

· The chip runs as a sink.

· Runs at 5V, and can drive LEDs up to 17V.

· Current is controlled via a resistor between pin 20 and Ground. The current is given by the following formula:

I = 39.06 / R

Where I is current in amps, and R is resistance in Ohms. So for example, a resistance of 2k means a current of roughly 20mA flows through all the LEDs.

Configuration: R = 4k7, which gives I = 8.3mA. That means a 680 Ohm load resistor would use 47mW.

· The chip allows for ‘Dot Correction’. This is adjusting of the current flow for different brightness in LEDs. This feature is not used in this example.

· The chip requires a microcontroller to control it.

· There is an Arduino library called ‘TLC5940’ that shall be used to control the chip and generate the required signals.

· Instead of connected LEDs, we shall be connecting resistors between 5V and the outputs, and the PWM signal shall be generated across them.

· Since this works as a sink, the required output always works in inverse mode. This is explored further in the software section.

· All channels are synced on the falling edge.

Arduino Links:

Playground:

http://www.arduino.cc/playground/Learning/TLC5940

Library Download, Hardware details and documentation:

http://code.google.com/p/tlc5940arduino/

Library Documentation in detail:

http://students.washington.edu/acleone/codes/tlc5940arduino/html_r014/

 

Hardware connection:

 

The TLC5940 has the following pins:

· XERR : open collector, wire or-ed output that lets you know a TLC5940is over heated or has a burnt out LED. We can ignore this as it will always be on unless you have current using elements on all of the outputs.

· 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.

· DCPRG: this selects the source of the current limiter register, you could just tie it high.

· XLAT: you will need this to latch data after shifting.

· SCLK: you will need this to shift data.

· SIN: serial in to TLC5940, this is the output from the Arduino.

· VPRG: you need this to select either the current limit registers or the duty cycle registers for writing.

· GSCLK: this is the clock for the PWM. We will reprogram TIMER2 in the Arduino to make this signal. That will cost us the native PWM on that timer, digital 11 on a mega8, 11 and 3 on a mega168.

· BLANK: this marks the end of a PWM cycle in addition to blanking the output. We will reprogram TIMER1 to generate this signal. That will cost us the native PWMs on digital 9 and digital 10. (Tie a real, physical pull-up resistor on this line to keep things blanked while your Arduino boots. Depending on your hardware, it is possible that the TLC5940 would come up in a configuration that would dissipate too much power.)

· OUT0 – OUT15: They serve as outputs, where LEDs or load resistors can be connected.

clip_image002

We do not need to worry about these pins as Arduino shall be handling most of the connections. For our application, we won’t be requiring XERR.

Everything else is connected as follows:

· Pin 17 (SOUT) – Connected to the SIN of the next pin if there is more than one. Otherwise, this can be left open.

· Pin 18 (GSCLK) – Arduino Uno Pin 3, Mega Pin 9

· Pin 19 (DCPRG) – 5V

· Pin 20 (IREF) -> Current control resistor to ground, E.g 2k or 4K7.

· Pin 21 (Vcc) – 5V

· Pin 22 (GND) – GND

· Pin 23 (Blank) – Arduino Uno pin 10, Mega Pin 12

· Pin 24 (XLAT) – Arduino Uno Pin 9, Mega Pin 11

· Pin 25 (SCLK) – Arduino Uno Pin 13, Mega Pin 52

· Pin 26 (SIN) – Arduino Uno Pin 7, Mega Pin 51

· Pin 27 (VPRG) – Ground

Here is a typical example of the connection:

clip_image004

(Image from http://students.washington.edu/acleone/codes/tlc5940arduino/img/breadboard-arduino-tlc5940_close.png)

 

Software Usage:

As is obvious, if connecting with the TLC5940, the user will lose functionality from the pins that are connected to the TLC5940. Depending on the requirements, a UNO or a MEGA board can be used.

All PWM functionality should be used from the TLC5940, and not mixed and matched between that and the Arduino.

The library can be downloaded from the links above, and should be placed under the Arduino IDE xx.xx\ Libraries \ folder.

First course of action is to try the ‘BASIC USE’ example from EXAMPLES\TLC5940.

Here is a set of instructions to be used:

#include

Include the library

 

Tlc.init();

This is used to initialize the TLC5940 chip(s). The Tlc object is declared in the library and is used to execute commands. This should be called in the ‘void setup ()’ method.

Tlc.clear();

This is used to turn off all the outputs. This will be used in the loop () method.

Tlc.set(channel number, set value);

This is used to set the PWM value on the channel number.

Channel number varies from 0 – 15 for TLC # 1, 16 – 31 for TLC # 2, and so on.

The current library has been configured to work for 2 TLCs, and is normally configured for 1 TLC by default.

Set value is an integer between 0 – 4095. Sending in a 4095 means a 0% PWM, a 0 means a 100% PWM, and anything in between gives the other values.

In my application, the map function is used to set that value, for example:

set1 = map(pwm1, 0, 100, 4095, 0);

Tlc.setAll(set value);

This sets the PWM value on all the channels.

Tlc.update();

This is required to send the updated values from the above commands (clear, set, setAll) to the TLC5940 chip.

Here is an example code that sends 10%, 20%, 30% and 40% out to channels 2, 1, 30 and 31.

#include “Tlc5940.h”

int pwm1,pwm2,pwm3,pwm4;

int set1,set2,set3,set4;

void setup(){

Tlc.init();

}

void loop(){

Tlc.clear();

pwm1 = 10; // PWM set to be 10%;

pwm2 = 20; // PWM = 20%

pwm3 = 30; //

pwm4 = 40; //

set1 = map(pwm1, 0, 100, 4095, 0);

set2 = map(pwm2, 0, 100, 4095, 0);

set3 = map(pwm3, 0, 100, 4095, 0);

set4 = map(pwm4, 0, 100, 4095, 0);

Tlc.set(2,set1);

Tlc.set(1,set2);

Tlc.set(30,set3);

Tlc.set(31,set4);

Tlc.update();

delay(1000);

}

Configuration

 

The default number of TLCs connected is 1, and the default frequency it operates at is 973Hz.

These values can be adjusted by adjusting the Tlc_config.h file in the library. More instructions on this are provided in the links above.

Three values can be adjusted to get around this in the Tlc_config.h file:

NUM_TLCS

It is given in the code as:

#define NUM_TLCS 1 // Number of daisy chained TLCs

This value can be changed from 1 up to 16.

For more than 16, the value TLC_CHANNEL_TYPE needs to be changed. More on that at http://students.washington.edu/acleone/codes/tlc5940arduino/html_r014/tlc__config_8h.html.

TLC_PWM_PERIOD

It is given in the code as:

#define TLC_PWM_PERIOD 8192

This value is given by the formula:

clip_image005

Where fosc is 16MHz for the Arduino. So a value of 8192 gives a frequency of 977Hz (approx).

Using this formula, this value can be programmed to give the two other frequencies commonly used, i.e. 244Hz and 1.95 kHz.

For these, the value is 32768 and 4096 respectively.

TLC_GSCLK_PERIOD

It is given in the code as:

#define TLC_GSCLK_PERIOD 3

This value is given by the formula:

clip_image006

The default value of 3 corresponds to a default value of 8192 for TLC_PWM_Period, and a frequency of 977 Hz.

For frequencies 244Hz and 1.95kHz, the values are 15 and 1 respectively.

 

 

Libraries

 

The default number of TLCs connected is 1, and the default frequency it operates at is 973Hz.

These values can be adjusted by adjusting the Tlc_config.h file in the library. More instructions on this are provided in the links above.

The problem is, if more than one configurations are used, having a single library may mean that it could be hard to keep track on what goes on every time.

Solution for this is to create different libraries for different values.

The way to do this is to create the required Tlc_config.h file, and rename it to say Tlc244_config.h.

Then rename TLC5940.h to TLC5940_244.h, and TLC5940.cpp to TLC5940_244.cpp.

After that, go through the source code of those two files, and replace all references for the new name.

Then rename the folder so that it reflects the name of the class.

TLC5940_244 and TLC5940_2kHz are the two libraries created to be used, and can be called by the following function:

#include // OR:

#include

Using either of the above two instead of the normal call to the library will mean that the required functionality will be achieved. It should be remembered that before changing anything in the already provided library, a copy should be made in case the new library does not perform as expected.

So far I have not uploaded the libraries any where yet, as I’d rather the original contributor own them, as he provided with the main brains behind it, but I can send the libraries across by email if required.

Sami Mughalhttps://www.oxgadgets.com
Can be found somewhere between designing new tech as an electronics engineer or testing new tech as a technology enthusiast. Lives mostly on Twitter, and would love to have a word with you there as @smacula.

Related Articles

Bang & Olufsen Launches the New Beolit 20

The Danish audio brand, Bang & Olufsen has launched the 2020 upgrade of the powerful and portable Beolit Bluetooth speaker, its heritage...

LA music industry experts launch premium headphone brand in the UK

Ausounds has released a range of premium audio products to take the UK by storm. The audio products have been designed by...

The New Xiaomi Mi 10T Pro and Xiaomi Mi 10T Lite Now Available To Pre-order At Vodafone UK

The new flagship series by Xiaomi, including the Mi 10T Pro and Mi 10T Lite, are now available to pre-order at the...

2 COMMENTS

  1. Halo Sir,
    We are freshers of doing Project. we started our project with Induino board, Even though we see tutorial programs we find difficult with coding part. please any suggest us. my mail id is newtalantons@gmail.com

    Input =>
    Waveform : Square wave
    Frequency : 0hz to 100hz
    Voltage : 1v

    Output =>
    Message to be displayed according various input and it need to be sent through sms using gsm module.

    Concept =>
    Consicutive variation in frequency need to be monitered by the processor and display the msg

    for ex;

    0hz to 1hz -> PROCESS STARTED (displayed and sms)
    1hz -> PROGRESSING (displayed and sms)
    1.5 t0 10 hz -> GROUP A (displayed only)
    10.1 to 20hz -> GROUP B (displayed only) —> 7 hz -> LEADER 1 (displayed and sms)
    20.1 to 30hz -> GROUP C (displayed only) –> 13hz -> LEADER 2 (displayed and sms)
    30.1 to 60hz -> GROUP D (displayed only)
    > 60 hz -> GROUP E (displayed only)Controller used =>
    Atmega 328 – Induino evaluation board

    GSM Modem =>
    SM900 GSM/GPRS shield for Arudino- IComsat v1.0

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Stay Connected

1,964FansLike
4,568FollowersFollow
- Advertisement -

Latest Articles

Bang & Olufsen Launches the New Beolit 20

The Danish audio brand, Bang & Olufsen has launched the 2020 upgrade of the powerful and portable Beolit Bluetooth speaker, its heritage...

LA music industry experts launch premium headphone brand in the UK

Ausounds has released a range of premium audio products to take the UK by storm. The audio products have been designed by...

The New Xiaomi Mi 10T Pro and Xiaomi Mi 10T Lite Now Available To Pre-order At Vodafone UK

The new flagship series by Xiaomi, including the Mi 10T Pro and Mi 10T Lite, are now available to pre-order at the...

How to Find and Fix Wireless Dead Zones

Have you ever wondered why you can stream HD video perfectly in one room but if you go only one room over...

Introducing Active Noise Cancellation To LG Tone Free Lineup With Uvnano Case

LG Electronics has introduced its most advanced true wireless earbuds yet, expanding the LG TONE Free lineup. LG HBS-FN7  offers all the...
%d bloggers like this: