Quantcast
Channel: MSP430 Technical Forums
Viewing all articles
Browse latest Browse all 2077

While(1) not Executing with Timer Interrupt

$
0
0

Hey all,

I've run into a peculiar problem where my main loop doesn't execute. I know my interrupt routine is executing because I can uncomment the led toggle and I can see it blink. From what I've researched thus far, I believe the issue might be that the ISR is starving the main loop from ever executing. If that is the case, I'm not sure what the solution would be. 

 

The reason I have my main loop set up this way is because I am going to need different functions executing at different intervals.

 

I'm still fairly new to MSP430 development, so any help will be appreciated!

#include <msp430g2553.h>

#define MS_TIME 1000

volatile unsigned int s_cnt = 0;
unsigned int last_cnt = 0;

int main(void) {
  WDTCTL = WDTPW + WDTHOLD;            // Stop WDT
  
  P1DIR |= BIT0 + BIT6; 	       // P1.0 and P1.6 are the red+green LEDs	
  P1OUT &= ~(BIT0 + BIT6); 	       // Both LEDs off
  
  TA0CCTL0 = CCIE;                     // Enable Timer A0 interrupts
  TA0CCR0 = 22;                        // Count limit
  TA0CTL = TASSEL_1 + MC_1;            // Timer A0 with ACLK, count UP
  
  _BIS_SR(LPM0_bits + GIE);            // Enable interrupts

  while(1) {
    if (last_cnt != s_cnt) {
      last_cnt = s_cnt;
      if (last_cnt == MS_TIME) {
        P1OUT ^= BIT6;                 // Toggle green LED
        s_cnt = 0;
      }
    }
  }
}

#pragma vector=TIMER0_A0_VECTOR        // Timer0 A0 interrupt service routine
  __interrupt void Timer0_A0 (void) {
  s_cnt++;
  //P1OUT ^= BIT6;
}

Viewing all articles
Browse latest Browse all 2077

Trending Articles