SLVU240B May 2008 – August 2018 MSP430F2131 , TPS62260
A complete listing of the firmware used in the EVM is contained below:
/******************************************************************************/
/* RGB-LED Demo using MSP430F2131 and TPS62260 from Texas Instruments */
/* */
/* Description: */
/* Timer_A3 is used to generate 3 PWM signals. Timer overflow generates an */
/* interrupt and in its interrupt service routine the PWM outputs are */
/* reseted. Output Units will set the PWM outputs. */
/* Software starts in a demo mode that automatically changes the PWM */
/* settings. As soon as the incremental encoder is operated the automatic */
/* mode stops and the adjustment of the colour can be done manually. */
/*----------------------------------------------------------------------------*/
/* Texas Instruments Deutschland GmbH */
/* Christian Hernitscheck, November 2007 */
/******************************************************************************/
#include "msp430x21x1.h"
#define LED_TabLength 252*4
const unsigned int LED1[]={65385,65385,65385,65385,65385,65385,65385,65385,
65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,
65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,
65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,57866,52635,47404,
42173,36943,34327,31712,29096,26481,23866,21250,19942,18635,17327,16019,14712,
13404,12096,10789, 9481, 8173, 7519, 6865, 6212, 5558, 4904, 4577, 4250, 3923,
3596, 3269, 2942, 2615, 2288, 1962, 1635, 1308, 981, 654, 327, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 327, 654, 981, 1308, 1635, 1962, 2288, 2615,
2942, 3269, 3596, 3923, 4250, 4577, 4904, 5558, 6212, 6865, 7519, 8173, 9481,
10789,12096,13404,14712,16019,17327,18635,19942,21250,23866,26481,29096,31712,
34327,36943,39558,42173,44789,47404,52635,57866,65385,65385,65385,65385,65385,
65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,
65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,
65385,65385,65385,65385,65385,65385,65385,65385,65385,65385,65385}; //blue LED
const unsigned int LED2[]={ 150, 295, 622, 949, 1276, 1603, 1930, 2256,
2583, 2910, 3237, 3564, 3891, 4218, 4545, 4872, 5526, 6180, 6833, 7487, 8141,
9449,10757,12064,13372,14680,15987,17295,18603,19910,21218,23834,26449,29064,
31680,34295,36911,39526,42141,44757,47372,52603,57834,65353,65353,65353,65353,
65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,
65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,
65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,
65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,
65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,
65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,65353,
65353,65353,65353,57834,52603,47372,42141,36911,34295,31680,29064,26449,23834,
21218,19910,18603,17295,15987,14680,13372,12064,10757, 9449, 8141, 7487, 6833,
6180, 5526, 4872, 4545, 4218, 3891, 3564, 3237, 2910, 2583, 2256, 1930, 1603,
1276, 949, 622, 295, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150}; //green LED
const unsigned int LED3[]={ 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150,
150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 311,
638, 965, 1292, 1619, 1946, 2272, 2599, 2926, 3253, 3580, 3907, 4234, 4561,
4888, 5542, 6196, 6849, 7503, 8157, 9465,10773,12080,13388,14696,16003,17311,
18619,19926,21234,23850,26465,29080,31696,34311,36927,39542,42157,44773,47388,
52619,57850,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,
65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,
65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,
65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,
65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,
65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,65369,
65369,65369,65369,65369,65369,65369,65369,65369,65369,57850,52619,47388,42157,
36927,34311,31696,29080,26465,23850,21234,19926,18619,17311,16003,14696,13388,
12080,10773, 9465, 8157, 7503, 6849, 6196, 5542, 4888, 4561, 4234, 3907, 3580,
3253, 2926, 2599, 2272, 1946, 1619, 1292, 965, 638, 311, 150}; //red LED
unsigned int LEDptr;
unsigned char BAold;
void Inc_Decoder(unsigned char BAnew);
void Delay(void);
//------------------------------------------------------------------------------
// Main Program
void main(void)
{ unsigned int i,temp;
WDTCTL=WDTPW+WDTHOLD; // disable Watchdog
BCSCTL1= CALBC1_8MHZ; //--- System Clock Settings ----------------------
DCOCTL = CALDCO_8MHZ; // use calibrated 8MHz settings
//---- PWM Timer Initialization ------------------
TACTL = TASSEL_2+ID_0+MC_0+TACLR+TAIE; // Timer clock = SMCLK = 8MHz
TACCTL0 = CM_0+CCIS_2+OUTMOD_1; // All Output Units will set PWM outputs if
TACCTL1 = CM_0+CCIS_2+OUTMOD_1; // TACCRx=TAR. Resetting PWM outputs is done
TACCTL2 = CM_0+CCIS_2+OUTMOD_1; // by software.
LEDptr=0;
TACCR0=LED1[LEDptr>>2]; // LEDptr is shifted right twice,
TACCR1=LED2[LEDptr>>2]; // this means divided by 4
TACCR2=LED3[LEDptr>>2];
//--- Port Initialization ----------------------------------
P1SEL = 0x0E; // P1.1, P1.2, P1.3 are used as PWM Timer Outputs
P1OUT = 0x00; // P1.0 is output (Enable for TPS62260)
P1DIR = 0xFF; // P1.4, P1.5, P1.6, P1.7 are not used => digital outputs
P2OUT = 0x04; // P2.0 and P2.1 are not used => digital outputs
P2DIR|= 0xE4; // P2.3, P2.4 are digital inputs => incremental encoder
// P2.5, P2.6, P2.7 are not used => digital inputs
BAold=0x01; //--- initialize decoder for incremental encoder -----------
Delay(); // Delay loop
TACTL |= MC_2; // start Timer_A (continuous mode)
__enable_interrupt(); // enables maskable interrupts
temp=P2IN&0x18;
//--- Main Loops ---------------------------------------------------------------
while ((P2IN&0x18)==temp) //--- change settings automatically till
{ Delay(); // incremental encoder is operated
LEDptr=LEDptr+1;
if (LEDptr>=LED_TabLength)
LEDptr=0;
}
while(1) //--- change settings manually (incremental encoder)
{ Inc_Decoder(0x03&(P2IN>>3)); // check incremental decoder
for(i=0;i<=1000;i++); // delay loop (used for debouncing)
}
}
//------------------------------------------------------------------------------
// Delay Loop
void Delay(void)
{ unsigned int i,j;
for(i=0;i<=10000;i++) // delay loop
for(j=0;j<=3;j++);
}
//------------------------------------------------------------------------------
// Incremental Encoder Subroutine:
void Inc_Decoder(unsigned char BAnew)
{
if (BAnew==0x02)
{ if (BAold==0x00)
{ LEDptr=LEDptr-1; // decrement pointer if new state is 'b' and
if (LEDptr>=LED_TabLength) // old state was 'a'
LEDptr=LED_TabLength;
}
}
if (BAnew==0x00)
{ if (BAold==0x02)
{ LEDptr=LEDptr+1; // increment pointer if new state is 'a' and
if (LEDptr>=LED_TabLength) // old state was 'b'
LEDptr=0;
}
}
BAold=BAnew; // store new state
}
//------------------------------------------------------------------------------
// Timer_A Interrupt Service Routine:
#pragma vector=TIMERA1_VECTOR
__interrupt void ISR_TimerA(void)
{ P1OUT |= 0x01; // activate LEDs
//--- update PWM duty cycle settings using colour table
TACCR0=LED1[LEDptr>>2]; // LEDptr is shifted right twice,
TACCR1=LED2[LEDptr>>2]; // this means divided by 4
TACCR2=LED3[LEDptr>>2];
//--- PWM signal generation
TACTL &= ~TAIFG;
TACCTL0 &= ~OUTMOD_7; // OUTMOD_0 => PWM output=L
TACCTL0 |= OUTMOD_1; // OUTMOD_1 => set PWM output TA0 as soon as TACCR0=TAR
TACCTL1 &= ~OUTMOD_7; // OUTMOD_0 => PWM output=L
TACCTL1 |= OUTMOD_1; // OUTMOD_1 => set PWM output TA1 as soon as TACCR1=TAR
TACCTL2 &= ~OUTMOD_7; // OUTMOD_0 => PWM output=L
TACCTL2 |= OUTMOD_1; // OUTMOD_1 => set PWM otuput TA2 as soon as TACCR2=TAR
// TAR = Timer_A counter
}