Tool/software: Code Composer Studio
I'm trying to incorporate an Interrupt Service Routine (ISR) for the pushbutton in the msp430 launchpad, so that pushing the button pauses the variation of the PWM duty cycle (and thus the red LED brightness remains constant). When the button is pushed again, the PWM variation resumes (at the same duty cycle value and “direction”, prior to the first button push). However, when I push the button nothing happens; the red LED continues changing intensity. Can anyone help me and see why the button is not functioning?
I did my implementation for PWM in timerA.c
#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 at min intensity if(TACCR1 == 0) direction = 1; //light at max intensity else if (TACCR0 == TACCR1) direction = 0; } #pragma vector = TIMER0_A1_VECTOR // Interrupt service routine for CCIFG1 and TAIFG __interrupt void Timer0_A1_routine(void) { //if both TAIFG (on) and CCR1 (off) interrupts are indicated, the net effect on the LED //is null. unsigned on, off; // (16-bit) off = TA0CTL & TAIFG; on = TA0CCTL1 & CCIFG; if (on && off){ // do nothing TA0CTL &= ~TAIFG; TA0CCTL1 &= ~CCIFG; } else if (off){ TURN_OFF_LED1; TA0CTL &= ~TAIFG; } else if (on){ TURN_ON_LED1; TA0CCTL1 &= ~CCIFG; } else{ for (;;); // Should not be possible } if (on){ // CCR1 //light at min increase duty cycle if(direction == 0) TACCR1 --; //light at max decrease duty cycle else if(direction == 1) TACCR1++; } }
This is where I'm implementing the button
#include "pushbutton.h" #include "LED.h" void InitializePushButtonPortPin (void) { P1DIR &=~BIT3; P1REN |= BIT3; P1OUT |= BIT3; P1IE |= BIT3; P1DIR &= ~BIT6; } #pragma vector = PORT1_VECTOR // Button interrupt service routine __interrupt void Button_routine(void) { TA0CCTL0 ^= CCIE; P1IFG &= ~BIT3; }
This is my main method
#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; }