This library creates the interface to operate the TLC5940. This device manages 16 PWM outputs.
Embed:
(wiki syntax)
Show/hide line numbers
tlc5940.cpp
00001 /* 00002 * tlc5940 - Interface to operate TI's IC TLC5940 00003 * Copyright (C) 2010 German Bassi. 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License as published by 00007 * the Free Software Foundation; either version 2 of the License, or 00008 * (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00018 */ 00019 00020 #include "tlc5940.h" 00021 #include "mbed.h" 00022 00023 tlc5940::tlc5940 (int num_ics, int DC_data[]) : 00024 num_ic(num_ics), VPROG(p21), SIN(p22), SCLK(p23), XLAT(p24), 00025 BLANK(p25), DCPROG(p27), GSCLK(p26), SOUT(p28), XERR(p29) { 00026 first_cycle_flag = false; 00027 00028 // Pins in startup state 00029 GSCLK = 0; 00030 SCLK = 0; 00031 VPROG = 1; 00032 XLAT = 0; 00033 BLANK = 1; 00034 DCPROG = 0; 00035 wait(0.01); 00036 00037 // DC input cycle starts 00038 DCPROG = 1; 00039 VPROG = 1; 00040 00041 for (int counter=0; counter < (num_ic*96); counter++) { 00042 SIN = DC_data[counter]; 00043 SCLK = 1; 00044 wait_us(5); 00045 SCLK = 0; 00046 wait_us(5); 00047 } 00048 XLAT = 1; 00049 wait_us(5); 00050 XLAT = 0; 00051 wait_us(5); 00052 DCPROG = 0; 00053 // DC input cycle ends 00054 } 00055 00056 void tlc5940::send_data (int data[]) { 00057 // Grayscale data input + Grayscale PWM 00058 data_counter = 0; 00059 GSCLK_counter = 0; 00060 00061 if (VPROG == 1) { 00062 VPROG = 0; 00063 first_cycle_flag = true; 00064 } 00065 00066 // Send the new data 00067 BLANK = 0; 00068 for (GSCLK_counter = 0; GSCLK_counter <= 4095; GSCLK_counter++) { 00069 if (data_counter < num_ic*192) { 00070 // Every new led consists of 12 bits 00071 aux_ind = data_counter % 12; 00072 if ( aux_ind == 0 ) aux_value = data[data_counter/12]; 00073 // Send the last bit 00074 SIN = (aux_value >> aux_ind) & 0x01; 00075 00076 SCLK = 1; 00077 GSCLK = 1; 00078 SCLK = 0; 00079 GSCLK = 0; 00080 00081 data_counter++; 00082 } else { 00083 GSCLK = 1; 00084 GSCLK = 0; 00085 } 00086 } 00087 BLANK = 1; 00088 00089 XLAT = 1; 00090 XLAT = 0; 00091 00092 if (first_cycle_flag) { 00093 SCLK = 1; 00094 SCLK = 0; 00095 first_cycle_flag = false; 00096 } 00097 }
Generated on Thu Jul 14 2022 21:35:46 by 1.7.2