TLC5940(16Channel led driver grayscale pwm control) SPI control

point(概要)

TLC5940(16CH LED Driver)をSPI機能を使用して制御します。 Grayscale data の送信と、LEDへのPWM出力もSPI機能を使用するため、mbedとTLC5940の接続は最小限で済ますことができます。

SPI は 12bit data,30MHzでの送信設定としています。

schematic(回路図)

/media/uploads/suupen/schematic_design__spi_drivesample.pdf

sample program

http://mbed.org/users/suupen/programs/SPI_TLC5940/lqnmnq

#include "mbed.h"

// TLC5940 control pin setting
SPI spi(p5, p6, p7);    //SIN (p6), SCLK,GSCLK(p7)

DigitalOut XLAT(p20);
DigitalOut BLANK(p19);

// debug LED
DigitalOut myled1(LED1);
DigitalOut myled3(LED3);

/*********************************
* gray data set
*********************************/
void grayDataSet(int* p){
    static int lightWait = 0;
    static int D_gray = 0;

    #define Z_kasan (1)
    static int kasan = Z_kasan;
    
    lightWait++;
    if(lightWait == 1){
        lightWait = 0;
        D_gray += kasan;
            
        if(D_gray > 4095){
           D_gray = 4095;
           kasan = -Z_kasan;
           myled1 = 1;
        }
        else if(D_gray <= 0){
           D_gray = 0;
           kasan = Z_kasan;
           myled1 = 0;
        }
    }
        
    for(int i = 0; i < 16; i++){
        *(p + i) = D_gray;
    }
}


/**********************************
* SPI Initalize (for TLC5960 control)
**********************************/
void tlc5940SpiInitalize(void){
    spi.format(12,0);
    spi.frequency(30000000);
}

/*********************************
* TLC5940 Gray Data clear
*********************************/
void tlc5940GrayDataClear(void){
        for(int i = 0; i < 24; i++){
            int whoami = spi.write(0);
        }
        
        XLAT = 1;
        XLAT = 0;
}

/**********************************
* TLC5940 Gray Data Display & next data send
***********************************/
void tlc5940GrayDataDisplayAndSend(int* p){
    BLANK = 1;
    BLANK = 0;

    for(int i = 0; i < 326; i++){
        spi.write(0);
    }
    
    for(int i = 0; i < 16; i++){
        spi.write(*(p + i));
    }
    
    XLAT = 1;
    XLAT = 0;
}

/************************************
* main
************************************/
int main() {


    int D_grayData[16];     // gray data = 0 to 4095   [0]:OUT0, [1]:OUT1, ...,[14]:OUT14, [15]:OUT15


    // SPI initalize
    tlc5940SpiInitalize();    

    tlc5940GrayDataClear();
    

    while(1) {
    
        grayDataSet(D_grayData);
        
        tlc5940GrayDataDisplayAndSend(D_grayData);
    }
}


3 comments on TLC5940(16Channel led driver grayscale pwm control) SPI control:

21 Nov 2011

Does this work when cascading 6 Tlc5940?

22 Nov 2011

Ferry rietveidさんへ

TLC5940のcascadingに対応したプログラムを作成しました。

このプログラムは動作確認をしていません。

Hello Ferry rietveid,

I created a program that supports the cascading TLC5940.

This program is not tested.

http://mbed.org/users/suupen/programs/SPI_TLC5940_cascad/m12859

Import programSPI_TLC5940_cascad

このプログラムはTLC5940のcascadに対応しています。 cascadする数は1から20の間でZ_cascadに設定してください cascad number, please be set between 1 and 20 Z_cascad. Display data D_grayData [Z_cascad] [16] Please set to.

31 Jan 2015

I think there is something wrong in your schematic. Don't the LEDs need to be against supply (instead of GND)?

Please log in to post comments.