Sign in

username:

password:



Not a member?

Search msp430



Search tips

Subscribe to msp430





Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | MSP430 | tlc5940 programming problems.

The purpose of this group is to foster exchange of information on the Texas Instruments MSP430 family of microcontrollers and related tools. Everyone welcome, all levels of familiarity/expertise.

tlc5940 programming problems. - bob_shaftenkluger - Aug 26 15:07:34 2009

Hi.
I have been trying to get a msp430f2012 to control some leds connected to a tlc5940. I have come up with the following code, which seems like it is almost working. The leds light up, and they flicker so I guess the pwm is sort of working. I think the problem is that I am not clocking in the data correctly.
Here is the code, I hope someone here can help me fix it!
Thanks.

//////////////////////////////////////////////
//pinouts bobolobobob
// tlc5940 f2012
//
// gsclck= p1.0 / P1OUT ^= 0x01
// xlat = p1.1 / P1OUT ^= 0x02
// blank = p1.2 / P1OUT |= 0x04
// sclck = p1.5 / sclck
// sin = p1.6 / sdo
//////////////////////////////////////////////

#include
volatile unsigned int pants; //for testing stuff
volatile unsigned int inputcount; //counter for input array index. not yet used, included for future
volatile unsigned int outputcount; //counter for outputarry index
volatile unsigned int inputarray[16]; //input array, not yet used
volatile unsigned int outputarray[16]; //output array buffer thingy
volatile unsigned int converted; //converted to 12bit from whatever
volatile unsigned int gscnt;
volatile unsigned int firstcyc;
void smeg(void)
{
if (gscnt != 8191)// give blank pulse after every 4096 .
{
gscnt = gscnt +1;
//start clcok here

}
else
{
TACTL = TASSEL_2 + ID_3 + MC_0; //stop gsclk
// P1OUT ^= 0x04; // test
P1OUT |= 0x04; // blank on
//xlat high
P1OUT |= 0x02; //xlat on
P1OUT &= ~0x02;// xlat off

////////////////////////////////////////
//193rd clock pulse, less than optimal...
if (firstcyc != 0)
{
///pulse p1.5
P1DIR |= 0x1F;
P1OUT |= 0x10; //sclk on
P1OUT &= ~0x10;// sclk off
P1DIR |= 0x07;
firstcyc =0;
}

//////////////////////////////////////

//xlat low
P1OUT &= ~0x04;//blank off
gscnt = 0;// reset counter
///start next transfer
TACTL = TASSEL_2 + ID_3 + MC_1; //restart gsclk
outputcount = 0; // reset output counter
USICTL0 &= ~USISWRST; // USI released for operation
USICNT = USI16B | 12; //seems rather vulgar way of setting 16bit, but including at top doesnt work
}
}
void transmit(void)
{

converted = outputarray[outputcount] * 16;
USISR = converted;

///////////////////////////
//attempt at making look nicer. Working i think????.
if (outputcount != 15)// deliberatly too high to give nice stable trace on scope.
{
outputcount = outputcount +1;
USICNT = USI16B | 12; //seems rather vulgar way of setting 16bit, but including at top doesnt work
}
else{
//outputcount = 0;
USICTL0 |= USISWRST; // USI locked?

//P1OUT |= 0x02; //xlat on
//P1OUT &= ~0x02;// xlat off

////
//start gs clock here? NNNNNNNNNNOOOOOOOOOOOOOOOOOOO!!!!!!!!!!!!!!!!!!!!
//TACTL = TASSEL_2 + ID_3 + MC_1; // SMCLK, upmode (this starts clock?)
}
///////////////////////////

}
void main(void)
{
BCSCTL1 = CALBC1_16MHZ; // Calibrated range for DCO
DCOCTL = CALDCO_16MHZ; // Calibrated tap and modulation
volatile unsigned int i;

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
//P1OUT = 0x10; // P1.4 set, else reset
P1DIR |= 0x07; // P1.0 P1.1 P1.2 output
//P1DIR |= 0x1f; // P1.0 P1.1 P1.2 output
//P1REN |= 0x10; // P1.4 pullup
//P1DIR = 0x01; // P1.0 output, else input
USICTL0 |= USIPE7 + USIPE6 + USIPE5 + USIMST + USIOE; // Port, SPI master
//USICTL0 |= USIPE6 + USIPE5 + USIMST + USIGE + USIOE; // Port, SPI master, added usige, to correct gap between bits,

doesnt seem to work
//USICNT |= USI16B;
// USICTL1 |= USICKPH + USIIE;
USICTL1 |= USIIE; // Counter interrupt, flag remains set
USICKCTL = USIDIV_4 + USISSEL_2;// +USICKPL; // /64 SMCLK for 250khz

firstcyc =1;
//////////// test data, because the input stage isnt progrAammed yet.
outputarray [0]=0;
outputarray [1]=4095;
outputarray [2]=4095;
outputarray [3]=0;
outputarray [4]=4095;
outputarray [5]=0;
outputarray [6]=4095;
outputarray [7]=0;
outputarray [8]=4095;
outputarray [9]=0;
outputarray [10]=4095;
outputarray [11]=0;
outputarray [12]=4095;
outputarray [13]=0;
outputarray [14]=4095;
outputarray [15]=0;

////////////////////////////////////////////////////////////////////////

CCTL0 = CCIE; // CCR0 interrupt enabled
CCR0 = 4;
TACTL = TASSEL_2 + ID_1 + MC_1; // SMCLK, upmode (moved.......)
USICTL0 &= ~USISWRST; // USI released for operation

//P1DIR |= 0x04; // Reset Slave
//P1DIR &= ~0x04;

_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
//// USI interrupt service routine
#pragma vector=USI_VECTOR
__interrupt void universal_serial_interface(void)
{

transmit();

//USICNT = USI16B | 12; //seems rather vulgar way of setting 16bit, but including at top doesnt work
}
// Timer A0 interrupt service routine
///////////////////////////////////////////////////////////
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= 0x01; // Toggle P1.0
//P1OUT |= 0x01; // toggle gsclock
//P1OUT &= ~0x01;//
// gscnt = gscnt +1;

smeg();

}
------------------------------------



(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )


Specfic questions Re: tlc5940 programming problems. - bob_shaftenkluger - Aug 27 21:36:11 2009

I guess no-one could be bothered to decypher my terrible code..
If somebody could tell me what the USIGE, USICKPH, and USICKPL bits should be set to, it would help me very much. I tried the settings that my interpretation of the datasheets suggested, the ones that looked right on my scope, and various other combinations, no luck. It may well be that I am misunderstanding the datasheets, as what I would expect to see often does not correspond to what the scope says. (Of course, this could be due to the fact that my scope was due to be calibrated in 1993, and behaves in many bizare ways)
I am also confused about the 193rd clock pulse that may or may not be needed. slvc106, shows that the extra clock pulse is only needed for the first cycle, however the datasheet for the tlc5940 shows a 193rd pulse for each cycle.

------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of msp430 -- send a blank email to msp430-subscribe@yahoogroups.com )