SLVU240B May   2008  – August 2018 MSP430F2131 , TPS62260

 

  1.   Read This First
    1.     About This Manual
    2.     How to Use This Manual
    3.     Information About Cautions and Warnings
    4.     Related Documentation From Texas Instruments
    5.     If You Need Assistance
    6.     Trademarks
  2. 1Introduction
    1. 1.1 Requirements
      1. 1.1.1 Power Supply Requirements
      2. 1.1.2 Printed Circuit Board Assemblies (PCBs)
  3. 2Setup
    1. 2.1 Input/Output Connector Descriptions
      1. 2.1.1 J1, J2, and J3 – Power Supply Connectors
      2. 2.1.2 JP1 – Wireless Interface Connector
      3. 2.1.3 JP2 – JTAG Interface Connector
    2. 2.2 Hardware Setup
  4. 3Supported Colors and Operation Modes
    1. 3.1 Color Range
    2. 3.2 Auto-Scroll Mode
    3. 3.3 Manual Control Mode
  5. 4Design Description
    1. 4.1 Hardware Design
      1. 4.1.1 LED Power Stages
      2. 4.1.2 Output Filter Design
      3. 4.1.3 MODE and EN Pins
      4. 4.1.4 MSP430 MCU Design
    2. 4.2 LED Color Table
    3. 4.3 Firmware Design
      1. 4.3.1 Firmware C-Code Listing
  6. 5Schematic and Bill of Materials
    1. 5.1 Schematics
    2. 5.2 Bill of Materials
  7. 6Board Layout
    1. 6.1 Photographs of Top and Bottom
    2. 6.2 Layout
    3. 6.3 Thermal Images
  8. AReprogramming
    1. A.1 Additional Software and Hardware Needed
    2. A.2 IAR Embedded Workbench KickStart Software Installation
    3. A.3 Hardware Installation
    4. A.4 Using IAR Embedded Workbench to Download Code on MSP430 MCUs
  9.   Revision History

Firmware Design

This section details the function of the default software loaded onto the MSP430F2131. Because the color scheme is set through integer values given in three LED color arrays, no software change is needed for changing the color scheme. Changing the values in the LEDx[ ] arrays changes the colors.

#include "msp430x21x1.h"

All peripheral control registers and control bits of the MSP430F2131 are defined in the header file msp430x21x1.h.

#define LED_TabLength 252*4

Here the length of the arrays LED1[ ], LED2[ ], and LED3[ ] is defined. It is used to detect the overflow of the LEDptr. Care should be taken that all three arrays LED1[ ], LED2[ ], and LED3[ ] have the length that is defined here.

const unsigned int LED1[]={65385,65385,65385, ¼,65385,65385}; //blue LED const unsigned int LED2[]={ 150, 295, 622, ¼, 150, 150}; //green LED const unsigned int LED3[]={ 150, 150, 150, ¼, 311, 150}; //red LED

The three arrays are used for the PWM duty cycle adjustment. For each LED (red, green, and blue) there is an own array. But there is only one pointer (LEDptr) that is used to find the PWM settings for each of the arrays. The values of the array should be within the range 100 to 65535.

unsigned int LEDptr;

This is the variable used as the pointer for the three arrays LED1[ ], LED2[ ], and LED3[ ].

unsigned char BAold;

This variable is used for the detection of a change of the incremental encoder.

void main(void) { unsigned int i,temp; WDTCTL=WDTPW+WDTHOLD; // disable Watchdog The Watchdog is not used in this program. So it is disabled. BCSCTL1= CALBC1_8MHZ; //--- System Clock Settings ---------------------- DCOCTL = CALDCO_8MHZ; // use calibrated 8MHz settings

The Watchdog is not used in this program. By setting the control bit WDTHOLD in control register WDTCTL the Watchdog is disabled.

BCSCTL1= CALBC1_8MHZ; //--- System Clock Settings ---------------------- DCOCTL = CALDCO_8MHZ; // use calibrated 8MHz settings

There are calibration values available in the flash memory of the MSP430 MCU. These two commands move the calibration value for 8-MHz DCO output frequency into the clock system control registers.

//---- 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.

The Timer_A module is initialized here. It uses the calibrated 8-MHz DCO clock signal. A timer overflow generates an interrupt. The three capture and compare blocks CCR0, CCR1, and CCR2 are used in compare mode. The output unit of each CCR block is used to generate a PWM signal. The output units are automatically setting the PWM output, while the resetting of the output signal is done by software as soon as a timer overflow (Timer_A interrupt) happens.

LEDptr=0; TACCR0=LED1[LEDptr>>2]; // LEDptr is shifted right twice, TACCR1=LED2[LEDptr>>2]; // this means divided by 4 TACCR2=LED3[LEDptr>>2];

LEDptr is cleared. This means the first values of the arrays LED1[], LED2[], and LED3[] are used at the beginning. When LEDptr is used for the array, it is divided by 4 (shifting LEDptr two times right is the same as divided by 4). This is done to avoid issues with the bouncing of the incremental encoder.

//--- 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 outputs

Initialization of the digital I/Os. P1.1, P1.2, and P1.3 are used as Timer_A PWM output (module function). All pins that are not used are defined as digital outputs.

BAold=0x01; //--- initialize decoder for incremental encoder -----------

Initialization of the variable used for incremental encoder detection.

Delay(); // Delay loop TACTL |= MC_2; // start Timer_A (continuous mode)

After a short delay loop the Timer_A is started. The Timer_A is used in continuous mode, this means it counts from 0 to 65535. If the counter is 65535 and the timer gets another clock the counter value is set to 0 and an overflow interrupt is generated.

__enable_interrupt(); // enables maskable interrupts

All maskable interrupts are enabled. Now the interrupt service routines are called if there is an interrupt event.

temp=P2IN&0x18; //--- Main Loops --------------------------------------------------------------- while ((P2IN&0x18)==temp) //--- change settings automatically till

This is the first operating mode of the application. It stays in this loop as long as pins P2.3 and P2.4 do not change (this means as long as the incremental encoder S1 was not used).

{ Delay(); // incremental encoder is operated LEDptr=LEDptr+1; if (LEDptr>=LED_TabLength) LEDptr=0; }

The first operating mode of the application automatically changes the LEDptr. This is done by using a simple delay loop and afterwards the LEDptr is incremented. After incrementing the LEDptr it is checked if the maximum table length is reached. If this is the case the LEDptr is reset.

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) }

When the incremental encoder S1 is turned, this loop is executed. This is an entire loop. Here the incremental encoder is checked. Afterwards, there is a short delay loop that is used for debouncing of the incremental encoder.

} //------------------------------------------------------------------------------ // Delay Loop void Delay(void) { unsigned int i,j; for(i=0;i<=10000;i++) // delay loop for(j=0;j<=3;j++); }

This is the delay loop that is mainly used for the automatic mode. It defines the time the single settings of the arrays are used before the next one is moved to the Timer_A control registers.

//------------------------------------------------------------------------------ // 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 }

The incremental encoder generates a gray code. From the four different states the program is testing for only two states. The two states are P2.3='0', P2.4='0' and P2.3='1', P2.4='0'. Incrementing/decrementing of LEDptr is only done if the state that was read during the previous execution of the Inc_Decoder() function (this was stored in BAold) is different.

//------------------------------------------------------------------------------ // Timer_A Interrupt Service Routine: #pragma vector=TIMERA1_VECTOR __interrupt void ISR_TimerA(void) { P1OUT |= 0x01; // activate LEDs

This is the Timer_A interrupt service routine. It is called as soon as there is a Timer_A overflow. The first instruction is setting the P1.0 pin. This enables the DC/DC converters.

//--- update PWM duty cycle settings using color table TACCR0=LED1[LEDptr>>2]; // LEDptr is shifted right twice, TACCR1=LED2[LEDptr>>2]; // this means divided by 4 TACCR2=LED3[LEDptr>>2];

The settings for the PWM duty cycles are read from the three LED arrays. This is done in the interrupt service routine to ensure that it is synchronized with the timer. If this would be done in the main loop, the LED would flicker in case of a change.

The PWM signal is generated from the Timer Capture and Compare Block, that is, a digital comparator compares the Control Register (TACCRx) with the actual timer value. Are both values identical, the PWM output is set. The reset of the PWM output has to be done by software. This is done with an interrupt when there is a timer overflow and its Interrupt Service Routine updates the TACCRs register if necessary.

If this is done in the main loop, the update could happen asynchronous to the timer. Then it could happen that for one PWM cycle the PWM signal becomes inverted and the LED flickers.

//--- 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 output TA2 as soon as TACCR2=TAR // TAR = Timer_A counter }

Finally the Timer_A interrupt flag is cleared and all output signals are reset. The Timer CCR blocks are used to set the TAx output signals. Resetting the TAx outputs has to be done by software. That is done here.