Part Number: MSP430G2553
Tool/software: Code Composer Studio
I'm trying to use PWM on my msp430 launchpand to increase/ decrease the intensity of the red LED, but for some reason my code is not making the LED change intensity. I want to use my timeA.c change the PWM signal. The only thing I can see that might be causing the problem is the difference in values for TACCR0 and TACCR1. Right now TACCR1 is greater than TACCR0 when it should be the other way around. Can someone help to fix this problem
Here is my timerA.c file
#include "LED.h"
#include "timerA.h"
void ConfigureTimerA(void)
{
TA0CTL = (MC0 | TACLR);
TA0CTL |= (TASSEL_2 |ID_2 | MC_1);
//assign value to Time A0; capture/compare register0
TA0CCR0 = 499;
TA0CCR1 = 0;
//enable capture
TA0CCTL0 |= CCIE;
TA0CCTL1 |= CCIE;
TA0CTL |= TAIE;
}
unsigned int direction = 0;
#pragma vector = TIMER0_A0_VECTOR
// Interrupt service routine for CCIFG0
__interrupt void Timer0_A0_routine(void)
{
//light min
if(TACCR1 == 0)
direction = 0;
//light max
else if (TACCR0 == TACCR1)
direction = 1;
//light at min increase duty cycle
if(direction == 0)
TACCR1 --;
//light at max decrease duty cycle
else if(direction == 1)
TACCR1++;
}
#pragma vector = TIMER0_A1_VECTOR
// Interrupt service routine for CCIFG1 and TAIFG
__interrupt void Timer0_A1_routine(void)
{
switch (TAIV){
case TA0IV_NONE:
break;
case TA0IV_TACCR1: // CCIFG1 interrupt
TURN_OFF_LED1;
break;
case TA0IV_TAIFG: // TAIFG interrupt
TURN_ON_LED1;
break;
default: for (;;); // Should not be possible
}
}
Here is my main file
#include <msp430.h>
#include "LED.h"
#include "pushbutton.h"
#include "timerA.h"
// Global variable
char LEDBit = LED1;
// Function prototypes
void ConfigureClockModule(void);
void main(void)
{
// Stop the watchdog timer, and configure the clock module.
WDTCTL = WDTPW + WDTHOLD;
ConfigureClockModule();
// Initialize port pins associated with the LEDs, and then turn off LEDs.
InitializeLEDPortPins();
// Configure timer A to generate the required interrupt.
ConfigureTimerA();
_enable_interrupts();
// Infinite loop
while (1) {
}
}
void TimeDelay(unsigned int delay, unsigned int resolution){
unsigned i;
TA0CTL = (MC_0 |TACLR);
TA0CCR0 = resolution;
TA0CTL = (TASSEL_2|ID_2|MC_1);
for(i=0; i<delay; i++){
while(!(TA0CTL & TAIFG));
TA0CTL &= !TAIFG;
//
TA0CTL =(MC_0 |TACLR);
}
}
void ConfigureClockModule(void)
{
// Configure Digitally Controlled Oscillator (DCO) using factory calibrations.
DCOCTL = CALDCO_1MHZ;
BCSCTL1 = CALBC1_1MHZ;
}