Jump to content
43oh

TLC5940 examples


Recommended Posts

Hi Rob,

 

I've got my hands on some common anode RGB LEDs so your 1st example works with them. The next stage of my project is to be able to control each LED and cycle through all the available colours. Have you ever used the TLC5940 to do this?

Once again I'm trying to use the "Demystifying the TLC5940" book but I can't seem to get the results that I'm supposed to.

This is the code that I'm working with just now:

 

 

 

#include <msp430g2231.h>
#include <stdint.h>
#include <stdbool.h>

// How many TLC's daisy-chained
#define n 1
/***
    Ports
***/
// STATUS-LED
//#define PORT_STATUS_LED P1OUT
//#define PIN_STATUS_LED BIT0
// BLANK - to pin 23 of every TLC5940
#define PORT_BLANK P1OUT
#define PIN_BLANK BIT2
// XLAT - to pin 24 of every TLC5940
#define PORT_XLAT P1OUT
#define PIN_XLAT BIT1
// SCLK - to pin 25 of every TLC5940
#define PORT_SCLK P1OUT
#define PIN_SCLK BIT5
// MOSI - to pin 26 of first TLC5940
#define PORT_MOSI P1OUT
#define PIN_MOSI BIT7
// GSCLK - to pin 18 of every TLC5940
#define PORT_GSCLK P1OUT
#define PIN_GSCLK BIT4
// DCPRG - to pin 19 of every TLC5940
#define PORT_DCPRG P2OUT
#define PIN_DCPRG BIT7
// VPRG - to pin 27 of every TLC5940
#define PORT_VPRG P1OUT
#define PIN_VPRG BIT0
// useful macros
#define setLow(port, pin) { port &= ~pin; }
#define setHigh(port, pin) { port |= pin; }
#define pulse(port, pin) { setHigh(port, pin); setLow(port, pin); }
#define toggle(port, pin) { port ^= pin; }
#define outputState(port, pin) (port) & (1 << (pin));

// ADDED FROM DEMYSTIFYING
uint8_t dcData[16 * n] = {
// MSB	    LSB
0x3F,//1, 1, 1, 1, 1, 1, // Channel 15
0x3F,//1, 1, 1, 1, 1, 1, // Channel 14
0x3F,//1, 1, 1, 1, 1, 1, // Channel 13
0x3F,//1, 1, 1, 1, 1, 1, // Channel 12
0x3F,//1, 1, 1, 1, 1, 1, // Channel 11
0x3F,//1, 1, 1, 1, 1, 1, // Channel 10
0x3F,//1, 1, 1, 1, 1, 1, // Channel 9
0x3F,//1, 1, 1, 1, 1, 1, // Channel 8
0x3F,//1, 1, 1, 1, 1, 1, // Channel 7
0x3F,//1, 1, 1, 1, 1, 1, // Channel 6
0x3F,//1, 1, 1, 1, 1, 1, // Channel 5
0x3F,//1, 1, 1, 1, 1, 1, // Channel 4
0x3F,//1, 1, 1, 1, 1, 1, // Channel 3
0x3F,//1, 1, 1, 1, 1, 1, // Channel 2
0x3F,//1, 1, 1, 1, 1, 1, // Channel 1
0x3F,//1, 1, 1, 1, 1, 1, // Channel 0
};
uint16_t gsData[16 * n] = {
// MSB ----------------------------------->LSB
0x000,    //0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Channel 15
0x000,    //0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Channel 14
0x000,    //0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Channel 13
0x001,    //0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, // Channel 12
0x002,    //0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, // Channel 11
0x004,    //0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, // Channel 10
0x008,    //0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, // Channel 9
0x010,    //0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, // Channel 8
0x020,    //0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, // Channel 7
0x040,    //0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, // Channel 6
0x080,    //0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, // Channel 5
0x100,    //0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, // Channel 4
0x200,    //0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Channel 3
0x400,    //0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Channel 2
0x800,    //1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // Channel 1
0xFFF,    //1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // Channel 0
};
// Prototypes
void init (void);
void timerinit (void);
void TLCinit (void);
void TLC5940_ClockInDC(void);
void delay (unsigned int);

void init(void)
{
   WDTCTL = WDTPW + WDTHOLD; // disable WDT
   DCOCTL |= DCO0 + DCO1; // DCO = 15.25MHz
   BCSCTL1 |= RSEL0 + RSEL1 + RSEL2 + RSEL3; // as above
   BCSCTL2 |= DIVS_3; // divide clock by 8
   P1OUT &= ~(PIN_VPRG + PIN_BLANK + PIN_XLAT + PIN_SCLK + PIN_MOSI);
   P1DIR |= PIN_VPRG + PIN_BLANK + PIN_XLAT + PIN_SCLK + PIN_MOSI;
   P1DIR |= PIN_GSCLK; // port 1.4 configured as SMCLK out
   P1SEL |= PIN_GSCLK;
   P2SEL &= ~(BIT6 | BIT7);
   P2OUT &= ~PIN_DCPRG;
   P2DIR |= PIN_DCPRG;
}
void timerinit(void)
{
   // setup timer
   CCR0 = 0xFFF;
   TACTL = TASSEL_2 + MC_1 + ID_0; // SMCLK, up mode, 1:1
   CCTL0 = CCIE; // CCR0 interrupt enabled
}
void delay(unsigned int ms)
{
while (ms--)
   {
    __delay_cycles(1000); // set for 16Mhz change it to 1000 for 1 Mhz
   }
}

void TLC5940_SetGS_And_GS_PWM(void) // not being called in this example{
   uint8_t firstCycleFlag = 0;
    if(P1OUT|= PIN_VPRG)
    {
    setLow(PORT_VPRG, PIN_VPRG);
    firstCycleFlag = 1;
    }
   uint16_t GSCLK_Counter = 0;
   uint8_t Data_Counter = 0;
   setLow(PORT_BLANK, PIN_BLANK);
   for (; ;-)
   {
	    if(GSCLK_Counter > 4095)
	    {
		    setHigh(PORT_BLANK, PIN_BLANK);
		    pulse(PORT_XLAT, PIN_XLAT);
			    if (firstCycleFlag)
			    {
				    pulse(PORT_SCLK, PIN_SCLK);
				    firstCycleFlag = 0;
			    }
		    break;
	    }
	    else
	    {
	    if(!(Data_Counter > n * 192 - 1))
				    {
				    if(gsData[Data_Counter])
				    {
					    setHigh(PORT_MOSI, PIN_MOSI);
				    }
				    else
				    {
				    setLow(PORT_MOSI, PIN_MOSI);
				    pulse(PORT_SCLK, PIN_SCLK);
				    Data_Counter++;
				    }
			    }
	    pulse(PORT_GSCLK, PIN_GSCLK);
	    GSCLK_Counter++;
    }
   }
}

int main(void)
{
   init();
   timerinit();
   TLCinit();
   TLC5940_ClockInDC();
   __enable_interrupt();
    for (; ;-)
    {
    //TLC5940_SetGS_And_GS_PWM();
    }
}
void TLC5940_ClockInDC(void)
{
   setHigh(PORT_DCPRG, PIN_DCPRG);
   setHigh(PORT_VPRG, PIN_VPRG);
   uint8_t Counter = 0;
   //for (; ;-)
   //{
    if (Counter > n * 96 - 1)
    {
	    pulse(PORT_XLAT, PIN_XLAT);
	    //break;
    }
    else
    {
	    if (dcData[Counter]){
		    setHigh(PORT_MOSI, PIN_MOSI);}
	    else
		    {
		    setLow(PORT_MOSI, PIN_MOSI);
		    pulse(PORT_SCLK, PIN_SCLK);
		    Counter++;
		    }
    }
   //}
}
void TLCinit(void)
{
   setLow(PORT_GSCLK, PIN_GSCLK);
   setLow(PORT_SCLK, PIN_SCLK);
   setLow(PORT_DCPRG, PIN_DCPRG);
   setHigh(PORT_VPRG, PIN_VPRG);
   setLow(PORT_XLAT, PIN_XLAT);
   setHigh(PORT_BLANK, PIN_BLANK);
}

#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A0(void)
{
   // INITS
   setHigh(PORT_BLANK,PIN_BLANK);
   setHigh(PORT_XLAT,PIN_XLAT);
   setLow(PORT_XLAT,PIN_XLAT);
   setLow(PORT_BLANK,PIN_BLANK);
   uint8_t firstCycleFlag = 0;
   static uint8_t xlatNeedsPulse = 0;
   setHigh(PORT_BLANK, PIN_BLANK);
   if (P1OUT|= PIN_VPRG)
   {
   setLow(PORT_VPRG, PIN_VPRG);
   firstCycleFlag = 1;
   }
    if (xlatNeedsPulse)
    {
	    pulse(PORT_XLAT, PIN_XLAT);
	    xlatNeedsPulse = 0;
    }
    if (firstCycleFlag)
	    pulse(PORT_SCLK, PIN_SCLK);
    setLow(PORT_BLANK, PIN_BLANK);
    // Below this we have 4096 cycles to shift in the data for the next cycle
    uint8_t Data_Counter = 0;
    for (; ;-)
    {
	    if (!(Data_Counter > n * 192 - 1))
	    {
		    if (gsData[Data_Counter]){
			    setHigh(PORT_MOSI, PIN_MOSI);}
		    else
		    {
		    setLow(PORT_MOSI, PIN_MOSI);
		    pulse(PORT_SCLK, PIN_SCLK);
		    Data_Counter++;
		    }
	    }	 else {
		    xlatNeedsPulse = 1;
		    break;
	    }
    }

   _bic_SR_register_on_exit(LPM0_bits);
}

 

 

Can you see what is wrong with this?

 

Thanks

GD

Link to post
Share on other sites
  • Replies 35
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

TLC5940 code examples. 1. UART to TLC 2. Chasing light, useful for your next Knight Rider project #include #define SCLK_PIN BIT5 #define MOSI_PIN BIT7 #define GSCLK_PIN BIT4 #define BLANK_PIN B

Yes, I am using 4bit data and multiplying it by 256 when sending. To be exact, since TLC requires 12bit GS data, I am sending 3 SPI bytes in each iteration with GS data for 2 LEDs and the only thing I

Here are some 2231 examples   #include <msp430g2231.h> #include "pattern.h" #define SCLK_PIN BIT5 #define MOSI_PIN BIT7 #define GSCLK_PIN BIT4 #define BLANK_PIN BIT2 #define XLAT_PIN BIT1 #

Please use Code tags,

Hi Rob,

 

I've got my hands on some common anode RGB LEDs so your 1st example works with them. The next stage of my project is to be able to control each LED and cycle through all the available colours. Have you ever used the TLC5940 to do this?

Once again I'm trying to use the "Demystifying the TLC5940" book but I can't seem to get the results that I'm supposed to.

This is the code that I'm working with just now:

 

 

Can you see what is wrong with this?

 

Thanks

GD

Link to post
Share on other sites
  • 1 month later...

Hi RobG.

 

I was wondering if you could basically explain the operation of the example containing "pattern.h".

I am currently trying to fade an RGB LED from R>Y>G>Cy>B>M>R using the TLC5940 and the MSP430g2231 but I don't really understand what exactly your program does.

 

Any insight you can provide will help. Cheers

Link to post
Share on other sites

There are 3 things you can change:

Number of LEDs

Number of patterns (or frames)

Number of brightness levels

 

Patterns array holds brightness level for each LED for each pattern, so for example the first line means that pattern 0 will have LED#0 at level 1, LED#1 at level 3, etc. Brightness levels are set in LUT table


// 16 patterns, 16 LEDs, 16 brightness levels
const char pattern[16][16] = {
//
{ 1, 3, 5, 7, 9, 11, 13, 15, 14, 12, 10, 8, 6, 4, 2, 0 }, // pattern 0 {LED#0, LED#1, LED#2...
{ 0, 1, 3, 5, 7, 9, 11, 13, 15, 14, 12, 10, 8, 6, 4, 2 }, // pattern 1

LUT holds 12bit brightness value for each of 16 brightness levels, think of this as gamma correction table

#define NUMBER_OF_LEDS 16
u_char timerCounter = 0;
// 16 levels of brightness
const u_int lut[16] = { 0, 30, 60, 100, 200, 300, 400, 600, 800, 1000, 1200, 1500, 1800, 2100, 2400, 2550 }; // range is 0-4095 (12bit)

The 16 below is the number of patterns in the pattern array

// logic goes here
// patternIndex is used for pattern selection
// patternCounter is used for timeline
if(patternCounter < 16) {

 

Link to post
Share on other sites

That's great Rob thanks.

 

See when you are actually using the sendData function, how is it that you are able to select the brightness for that output?

What exactly does this line do?

 (data & 0x0800) ? (P1OUT |= MOSI) : (P1OUT &= ~MOSI);

My goal is to be able to fade through the colours of an RGB LED.

The way that I've been trying to do it is by creating an array[3], so array[0] represents the Red pin, array[1] represents the Green pin and array[2] represents the blue pin.

Then I tried to use for loops to fade from colour to colour, but I'm definitely doing something wrong.

This is the code that I'm trying to work with - any comments about what I'm doing wrong (or right :P) would be greatly appreciated.

#include <msp430g2231.h>
#include <stdbool.h>

// ----------- Pins -------------------------------------//
#define SCLK_PIN BIT5
#define MOSI_PIN BIT7
#define GSCLK_PIN BIT4
#define BLANK_PIN BIT2
#define XLAT_PIN BIT1
#define DCPRG_PIN BIT7 //P2
#define VPRG_PIN BIT0
// ------------------------------------------------------//

// --------------Macros ---------------------------------//
#define setHigh(n)   ( P1OUT |= n )
#define setLow(n)   ( P1OUT &= ~n )
#define pulse(n)  do{ setHigh(n); setLow(n); } while(0)
#define outputState(n) (P1OUT &= (1 << n))
typedef unsigned int u_int;
#define LEDs 2;
#define TLCs 1;
// ------------------------------------------------------//
static int count = 0;
//u_int gscale = 4095;
u_int pin[3];

//Pred Colours    |R    G    B |
//u_int R[] =        {4095,   0,   0};
//u_int G[] =        {0,   4095,   0};
//u_int B[] =        {0,   0,   4095};
//u_int Y[] =        {4095,   4095,   0};
//u_int CI[] =       {0,   4095,   4095};
//u_int M[] =        {4095,   0,   4095};
//u_int W[] =        {4095,   4095,   4095};
//u_int BL[] =       {0,   0,   0};

//An Array that stores the predefined colors
//u_int* COLOURS[] = {R,G,B};//,Y,CI,M,W,BL};


// -------------Prototypes------------------------------//
void init( void );
void shiftOut( unsigned int );
void pinWrite( unsigned int, unsigned int );
void delay(unsigned int);

// -----------------------------------------------------//

void init(void)
{
	WDTCTL = WDTPW + WDTHOLD; // disable WDT
	DCOCTL |= DCO0 + DCO1; // DCO = 15.25MHz
	BCSCTL1 |= RSEL0 + RSEL1 + RSEL2 + RSEL3; // as above
	BCSCTL2 |= DIVS_3; // divide clock by 8
	P1OUT &= ~(VPRG_PIN + BLANK_PIN + XLAT_PIN + SCLK_PIN + MOSI_PIN);
	P1DIR |= VPRG_PIN + BLANK_PIN + XLAT_PIN + SCLK_PIN + MOSI_PIN;
	P1DIR |= GSCLK_PIN; // port 1.4 configured as SMCLK out
	P1SEL |= GSCLK_PIN;
	P2SEL &= ~(BIT6 | BIT7);
	P2OUT &= ~DCPRG_PIN;
	P2DIR |= DCPRG_PIN;
	// Timer Setup //
	CCR0  = 0xFFF;
	TACTL = TASSEL_2 + MC_1;// + ID_0; // SMCLK, up mode, 1:1
	CCTL0 = CCIE; // CCR0 interrupt enabled
}


void main(void)
{
	init();

	_bis_SR_register(GIE);
			int a,b,c,d,e,f;

			for (; {

	             //- Red to Yellow
			    for( a = 0 ; a < 4096 ; a++ )
			    {
			      pin[0] = 4095;
			      pin[1] = a;
			      pin[2] = 0;
			      shiftOut( pin[0] && pin[1] && pin[2] );
			      delay(2000);
			    }
			    //- Yellow to Green
			    for( b = 4095 ; b >= 0 ; b-- )
			    {
			      pin[0] = b;
			      pin[1] = 4095;
			      pin[2] = 0;
			      shiftOut( pin[0] && pin[1] && pin[2] );
			      delay(2000);

			    }
			    //- Green to Cyan
			    for( c = 0 ; c < 4096 ; c++ )
			    {
			      pin[0] = 0;
			      pin[1] = 4095;
			      pin[2] = c;
			      shiftOut( pin[0] && pin[1] && pin[2] );
			      delay(2000);

			    }
			    //- Cyan to Blue
			    for( d = 4095 ; d >= 0 ; d-- )
			    {
			      pin[0] = 0;
			      pin[1] = d;
			      pin[2] = 4095;
			      shiftOut( pin[0] && pin[1] && pin[2] );
			      delay(2000);

			     }
			    //- Blue to Majenta
			    for( e = 0 ; e < 4096 ; e++ )
			    {
			      pin[0] = e;
			      pin[1] = 0;
			      pin[2] = 4095;
			      shiftOut( pin[0] && pin[1] && pin[2] );
			      delay(2000);

			    }
			    //- Majenta back to Red
			    for( f = 4095 ; f >= 0 ; f-- )
			    {
			      pin[0] = 4095;
			      pin[1] = 0;
			      pin[2] = f;
			      shiftOut( pin[0] && pin[1] && pin[2] );
			      delay(2000);

			    }

			  }

}

void pinWrite( unsigned int bit, unsigned int val )
{
  if (val){
    P1OUT |= bit;
  } else {
    P1OUT &= ~bit;
  }
}

void shiftOut(unsigned int val)
{
  //Set latch to low (should be already)
  setLow(XLAT_PIN);

      pinWrite(MOSI_PIN, val);                                // & gscale);
      pulse(SCLK_PIN);
      pulse(XLAT_PIN);
}

void delay(unsigned int ms)
{
 while (ms--)
    {
        __delay_cycles(1000); // set for 16Mhz change it to 1000 for 1 Mhz
    }
}



#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A0(void)
{
	setHigh(BLANK_PIN);
	setHigh(XLAT_PIN);
	setLow(XLAT_PIN);
	setLow(BLANK_PIN);
	
_bic_SR_register_on_exit(LPM0_bits);
}

My question to you is, when I'm using the shiftOut function is there any easy way to map this over to your "pattern.h" example?

 

Thanks

Link to post
Share on other sites

That piece of code toggles SPI data line

 

Here's a template you can use

 

#include <msp430g2231.h>

#define SCLK_PIN	BIT5
#define MOSI_PIN	BIT7

#define GSCLK_PIN	BIT4
#define BLANK_PIN	BIT2
#define XLAT_PIN	BIT1
#define DCPRG_PIN	BIT7 //P2
#define VPRG_PIN	BIT0

typedef unsigned char u_char;
typedef unsigned int u_int;

#define NUMBER_OF_LEDS 16

u_int leds[NUMBER_OF_LEDS] = { 0, };
u_char timerCounter = 0;

void updateTLC();
void sendData(u_int data);

void main(void) {

	WDTCTL = WDTPW + WDTHOLD; // disable WDT
	DCOCTL |= DCO0 + DCO1; // DCO = 15.25MHz
	BCSCTL1 |= RSEL0 + RSEL1 + RSEL2 + RSEL3; // as above
	BCSCTL2 |= DIVS_3; // divide clock by 8

	P1OUT &= ~(VPRG_PIN + BLANK_PIN + XLAT_PIN + SCLK_PIN + MOSI_PIN);
	P1DIR |= VPRG_PIN + BLANK_PIN + XLAT_PIN + SCLK_PIN + MOSI_PIN;

	P1DIR |= GSCLK_PIN; // port 1.4 configured as SMCLK out
	P1SEL |= GSCLK_PIN;

	P2SEL &= ~(BIT6 | BIT7);
	P2OUT &= ~DCPRG_PIN;
	P2DIR |= DCPRG_PIN;

	// setup timer
	CCR0 = 0xFFF;
	TACTL = TASSEL_2 + MC_1 + ID_0; // SMCLK, up mode, 1:1
	CCTL0 = CCIE; // CCR0 interrupt enabled

	updateTLC();
	P1OUT |= XLAT_PIN;
	P1OUT &= ~XLAT_PIN;

	_bis_SR_register(GIE);


	int loopCounter = 0;

	while (1) {
		// add your logic below
		// this loop will be executed every 16.384ms, ~61Hz
		//leds[0] = R1
		//leds[1] = G1
		//leds[2] = B1

		//this is not the best way to do it, but it's very simple to understand
		if (loopCounter < 256) {
			leds[0]++; // R
		} else if (loopCounter < 512) {
			leds[1]++; // G
		} else if (loopCounter < 768) {
			leds[0]--; // dim R
		} else if (loopCounter < 1024) {
			leds[2]++; // B
		} else if (loopCounter < 1280) {
			leds[1]--; // dim G
		} else if (loopCounter < 1536) {
			leds[0]++; // R
		} else if (loopCounter < 1792) {
			leds[2]--; // dim B
		} else if (loopCounter < 2048) {
			leds[0]--; // dim R
		} else {
			loopCounter = 0;
		}

		// do not edit below
		loopCounter++;
		// sleep
		_bis_SR_register(LPM0_bits);
	}
}

void updateTLC() {

	u_char ledCounter = NUMBER_OF_LEDS >> 1;

	while (ledCounter-- > 0) {
		u_char i = ledCounter << 1;
		sendData(leds[i + 1]);
		sendData(leds[i]);
	}
}

#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A0(void) {
	P1OUT |= BLANK_PIN;
	P1OUT |= XLAT_PIN;
	P1OUT &= ~XLAT_PIN;
	P1OUT &= ~BLANK_PIN;

	timerCounter++;
	if (timerCounter == 0x08) { // 0x08 - 2ms * 8 = 16.384ms, ~61Hz
		updateTLC();
		timerCounter = 0;
		_bic_SR_register_on_exit(LPM0_bits);
	}
}

void sendData(u_int data) {
	u_char c = 0;
	while (c < 12) {
		(data & 0x0800) ? (P1OUT |= MOSI_PIN) : (P1OUT &= ~MOSI_PIN);
		P1OUT |= SCLK_PIN;
		P1OUT &= ~SCLK_PIN;
		data <<= 1;
		c++;
	}
}
Link to post
Share on other sites

RobG, thank you for your last post!

 

When that program is compiled, on the first loop it goes through the colours smoothly and without flaw. However, when the loop begins again, for some reason all the red pins turn on at full intensity for a couple of seconds then it resumes the cycle. Any idea why that would happen?

 

Thanks

Link to post
Share on other sites
  • 2 weeks later...

Rob, thanks again for helping me with the PWM colour cycle.

 

The next stage of my project is to create a small matrix (3x3) of RGB LEDs being controlled using Rows and Columns. Although to do this I've had to use a 74HC595 shift register for the common anodes (columns) and the TLC for the cathodes (rows). The three pins I need for the inputs of the 595 are data, clock and latch. At the moment I'm using P1.3 for the Clock, P1.6 for the latch and P2.6 for the Data and this is the code I've added:

 

// 595 Inputs
#define DATA BIT6  // DS -> P2.6
#define CLOCK BIT3 // SH_CP -> 1.3
#define LATCH BIT6 // ST_CP -> 1.6
...
...
...
P1OUT &= ~(VPRG_PIN + BLANK_PIN + XLAT_PIN + SCLK_PIN + MOSI_PIN );
P1DIR |= VPRG_PIN + BLANK_PIN + XLAT_PIN + SCLK_PIN + MOSI_PIN + CLOCK + LATCH;
P1SEL &= ~CLOCK;

P1DIR |= GSCLK_PIN; // port 1.4 configured as SMCLK out
P1SEL |= GSCLK_PIN;

P2SEL &= ~(BIT6 | BIT7);      // i'm not sure what this line does?
P2SEL &= ~BIT6;               // trying to set to GPIO
P2OUT &= ~DCPRG_PIN;
P2DIR |= DCPRG_PIN + DATA;  // Set data to output

is there anything wrong with these initialisers?

 

Cheers

Link to post
Share on other sites
  • 6 months later...

hi rob.
in the very first program on page1,i wanted to know what is the need of updateTLC() function.updatTLC() may be sending the data for SPI interface.But the value of UCBOTXBUF is not changing duirng the whole program.its value is 0x006F.And as far as i know UCB0TXBUF is the user-accessible register where we can write that data which we want to send to the slave.

UCB0TXBUF = leds[(ledCounter << 1) + 1] << 4. the LHS of this equation has always 0x006F value.and RHS has always 0 value
moreover the while loop in the main is controlling the led pattern, then what is the need of updateTLC() function?..

please guide me. 

Link to post
Share on other sites

1)is the updateTLC function shifting the data from MSP430 to input shift register of TLC5940?
and check my program flow which i wrote after understanding ur program by applying breakpioints:

 

blank low, xlat low------> configure timer and timer starts-------->enabled SPI--------> updateTLC function is called due to which data is shifted into input shif register-->

 

pulse XLAT to latch data into GS register------->while(1) is executed-------> in the meanwhile timer is running  and when TAR=4096, interupt is called-----> in the ISR , WHATEVER data has been shifed is latched and blank pin made low to see the outputs

Link to post
Share on other sites

See posts #3, #5, and #7.

In short, updateTLC sends data to TLC, and when TLC is done with the current PWM cycle, we latch that data.

Also, example in post #1 uses 4bit data to control brightness, which is converted to 12bits in updateTLC.

Link to post
Share on other sites

/I have read them but I dont think they clear what i wanted to know..please answer my post # 26 and correct my post# 27...please explain in a bit more detail...please RobG....

And u said in example in post #1 uses 4bit data to control brightness, which is converted to 12bits in updateTLC.Dont u think it should convert the 4 bit data for 2 leds  to 8 bits in updateTLC becoz SPI  is 8 bit.
thanking u in anticipation...

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...