Hi
I am trying to use the comparator B and timer A0 interrupts on the msp430f5529 .The code is written in Energia and imported into CCS:
#include <msp430.h> int count =0; int x=5; int time1=0; int time2=0; void setup() { volatile unsigned int i; Serial.begin(9600); WDTCTL = WDTPW + WDTHOLD; // Stop WDT P1DIR |= BIT0; // P1.0/LED output direction P4DIR |=BIT7; // Setup ComparatorB CBCTL0 |= CBIPEN + CBIPSEL_0; // Enable V+, input channel CB0 CBCTL1 |= CBPWRMD_0; // ULTRA LOW power mode CBCTL2 |= CBRSEL; // VREF is applied to -terminal CBCTL2 |= CBRS_3|CBREFL_3; // R-ladder off; bandgap ref voltage (1.2V) // supplied ref amplifier to get Vcref=2.5V (CBREFL_3) CBCTL3 = BIT0; // Input Buffer Disable @P6.0/CB0 __delay_cycles(75); // delay for the reference to settle CBINT &= ~(CBIFG | CBIIFG); // Clear any errant interrupts CBINT |= CBIE; // Enable CompB Interrupt on rising edge of CBIFG (CBIES=0) CBCTL1 |= CBON + CBIES; // Turn On ComparatorB TA0CTL = TASSEL_1| MC_2 | TACLR |TAIE;//Enable Timer interrupt in Continuous mode enableWatchDog(); __bis_SR_register(LPM3_bits|GIE); // Enter LPM3 with inetrrupts enabled } // Comp_B ISR - LED Toggle #pragma vector=COMP_B_VECTOR __interrupt void Comp_B_ISR (void) { CBCTL1 ^= CBIES; // Toggles interrupt edge CBINT &= ~(CBIFG | CBIIFG); // Clear Interrupt flag P1OUT ^= 0x01; // Toggle P1.0 } //Timer A1 ISR #pragma vector=TIMER0_A1_VECTOR __interrupt void TIMER0_A1_ISR(void) { if( CBOUT ==1) { count =1; P4OUT ^=BIT7; delay(1000); } else{P4OUT ^=BIT7; delay(1000); count =0;} } void loop() {enableWatchDog(); Serial.println("HELLO"); Serial.println(count); sleepcount(x); delay(1000); __bis_SR_register(GIE); } int sleepcount(int y) {enableWatchDog(); time1=millis(); if (count == 1) {sleepSeconds(x); x=x+1;} else {delay(x*1000); x=x-1; if(x==0){x=10;} else{}} time2=millis(); Serial.println(time2-time1); }
I get the following output:
When voltage applied is less than or more 2.5 V Green and Red led toggle alternatively.(GREEN ON RED OFF and vice versa) .
According to the code I am following once the processor enters the comparator interrupt for V>2.5 V it should toggle RED LED and stay in that state until V<2.5 V
The problem seems to be that the Comparator interrupt somehow resets all of its flags .
Also the Serial print statement gives value 0 for (time2-time1) and if I do not enable the Watch Dog before entering into LPM3 it does not even print "HELLO".