This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

msp430f5529: Interrupt Programming in ADC

Part Number: MSP430F5529
Other Parts Discussed in Thread: MSP430F5529

Hello everyone,

I am doing  ADC programming in msp430f5529. But I have some doubt in the Program which I pasted below.

Whenever an interrupt is generated the CPU comes out of the Low Power Mode 0 and jumps to the ISR, in ISR CPU is in active state so why we have use this instruction " __bic_SR_register_on_exit(LPM0_bits)"

as  because the CPU is present in active state only.

#include <msp430.h>

//unsigned int value=0;

int main(void)

{

  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT

  ADC12CTL0 = ADC12SHT02 + ADC12ON;         // Sampling time, ADC12 on

  ADC12CTL1 = ADC12SHP;                     // Use sampling timer

  ADC12IE = 0x01;                           // Enable interrupt

  ADC12CTL0 |= ADC12ENC;

 P6SEL |= 0x01;                            // P6.0 ADC option select

  P1DIR |= 0x01;                            // P1.0 output

  while (1)

  {

    ADC12CTL0 |= ADC12SC;                   // Start sampling/conversion

    __bis_SR_register(LPM0_bits + GIE);     // LPM0, ADC12_ISR will force exit

    __no_operation();                       // For debugger

  }

}

#pragma vector = ADC12_VECTOR

__interrupt void ADC12_ISR(void)

{

                                   // Vector  6:  ADC12IFG0

   int value=ADC12MEM0;

    if (ADC12MEM0 >= 2048)                 // ADC12MEM = A0 > 0.5AVcc?

      P1OUT |= BIT0;                        // P1.0 = 1

    else

      P1OUT &= ~BIT0;                       // P1.0 = 0

   __bic_SR_register_on_exit(LPM0_bits);   // Exit active CPU

  }

#include <msp430.h>//unsigned int value=0;int main(void){  WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT  ADC12CTL0 = ADC12SHT02 + ADC12ON;         // Sampling time, ADC12 on  ADC12CTL1 = ADC12SHP;                     // Use sampling timer  ADC12IE = 0x01;                           // Enable interrupt  ADC12CTL0 |= ADC12ENC; P6SEL |= 0x01;                            // P6.0 ADC option select  P1DIR |= 0x01;                            // P1.0 output
  while (1)  {    ADC12CTL0 |= ADC12SC;                   // Start sampling/conversion
    __bis_SR_register(LPM0_bits + GIE);     // LPM0, ADC12_ISR will force exit    __no_operation();                       // For debugger  }
}

#pragma vector = ADC12_VECTOR__interrupt void ADC12_ISR(void){                                   // Vector  6:  ADC12IFG0
   int value=ADC12MEM0;    if (ADC12MEM0 >= 2048)                 // ADC12MEM = A0 > 0.5AVcc?      P1OUT |= BIT0;                        // P1.0 = 1    else      P1OUT &= ~BIT0;                       // P1.0 = 0
   __bic_SR_register_on_exit(LPM0_bits);   // Exit active CPU
  }

  • "_on_exit" means that this function does not modify the actual status register, but the value of the previous status register that was automatically saved on the stack. After the interrupt handler returns, the CPU restores the status register from that value, so if you want the CPU to run after the interrupt handler has returned, you have to modify that value.

**Attention** This is a public forum