This library creates the interface to operate the TLC5940. This device manages 16 PWM outputs.
Revision 0:64ea4d75027c, committed 2010-11-27
- Comitter:
- Fiuba
- Date:
- Sat Nov 27 00:28:33 2010 +0000
- Child:
- 1:e8c8347fa919
- Commit message:
- Initial commit
Changed in this revision
tlc5940.cpp | Show annotated file Show diff for this revision Revisions of this file |
tlc5940.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlc5940.cpp Sat Nov 27 00:28:33 2010 +0000 @@ -0,0 +1,84 @@ +#include "tlc5940.h" +#include "mbed.h" + +/** Create a tlc5940 interface object connected to some specifics pins + * + * @param DC_data[] Dot Correction values for initialization + */ +tlc5940::tlc5940 (int DC_data[]) : VPROG(p21), SIN(p22), SCLK(p23), XLAT(p24), BLANK(p25), DCPROG(p27), GSCLK(p26), SOUT(p28), XERR(p29) { + first_cycle_flag = false; + + // Pins in startup state + GSCLK = 0; + SCLK = 0; + VPROG = 1; + XLAT = 0; + BLANK = 1; + DCPROG = 0; + wait(0.01); + + // DC input cycle starts + DCPROG = 1; + VPROG = 1; + + for (int counter=0; counter < (2*96); counter++) { + SIN = DC_data[counter]; + SCLK = 1; + wait_us(5); + SCLK = 0; + wait_us(5); + } + XLAT = 1; + wait_us(5); + XLAT = 0; + wait_us(5); + DCPROG = 0; + // DC input cycle ends +} + +/** Send the specified set of grayscale values + * + * @param data[] Array of 12-bit Grayscale values for transmission + */ +void tlc5940::send_data (int data[]) { + // Grayscale data input + Grayscale PWM + data_counter = 0; + GSCLK_counter = 0; + + if (VPROG == 1) { + VPROG = 0; + first_cycle_flag = true; + } + + // Send the new data + BLANK = 0; + for (GSCLK_counter = 0; GSCLK_counter <= 4095; GSCLK_counter++) { + if (data_counter < 2*192) { + // Every new led consists of 12 bits + aux_ind = data_counter % 12; + if ( aux_ind == 0 ) aux_value = data[data_counter/12]; + // Send the last bit + SIN = (aux_value >> aux_ind) & 0x01; + + SCLK = 1; + GSCLK = 1; + SCLK = 0; + GSCLK = 0; + + data_counter++; + } else { + GSCLK = 1; + GSCLK = 0; + } + } + BLANK = 1; + + XLAT = 1; + XLAT = 0; + + if (first_cycle_flag) { + SCLK = 1; + SCLK = 0; + first_cycle_flag = false; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tlc5940.h Sat Nov 27 00:28:33 2010 +0000 @@ -0,0 +1,28 @@ +#ifndef MBED_TLC5940_H +#define MBED_TLC5940_H + +#include "mbed.h" + +class tlc5940 { +private: + bool first_cycle_flag; + int GSCLK_counter, data_counter; + int aux_value, aux_ind; + + DigitalOut VPROG; + DigitalOut SIN; + DigitalOut SCLK; + DigitalOut XLAT; + DigitalOut BLANK; + DigitalOut DCPROG; + DigitalOut GSCLK; + + DigitalIn SOUT; + DigitalIn XERR; + +public: + tlc5940 (int DC_data[]); + void send_data (int data[]); +}; + +#endif \ No newline at end of file