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.

Msp430l092: MULTIPLE INTERRUPT PROBLEM

Part Number: MSP430L092
Other Parts Discussed in Thread: MSP430WARE

I am dealing with msp430l092 chip. I can program it via IAR EMBEDDED software. I got example code for adc interrupt and timer interrupt. They are working well individually. When I add ADC intrrrupt into the Timer interrupt, it does not work. I mean that ADC interrupt works first time and my code stuck inside timer interrupt. I want to prepare my code for reading adc value and handling time interval. Can you give me a suggestion please ? Thanks in advance

  • Hello,

    Could you please post your code? I would like to take a look at it.

    Thank you

  • I added up two different interrupts what I need to handle timers and analog values but it does not work exactly. Nothing happens.

    /* --COPYRIGHT--,BSD_EX

     * Copyright (c) 2012, Texas Instruments Incorporated

     * All rights reserved.

     *

     * Redistribution and use in source and binary forms, with or without

     * modification, are permitted provided that the following conditions

     * are met:

     *

     * *  Redistributions of source code must retain the above copyright

     *    notice, this list of conditions and the following disclaimer.

     *

     * *  Redistributions in binary form must reproduce the above copyright

     *    notice, this list of conditions and the following disclaimer in the

     *    documentation and/or other materials provided with the distribution.

     *

     * *  Neither the name of Texas Instruments Incorporated nor the names of

     *    its contributors may be used to endorse or promote products derived

     *    from this software without specific prior written permission.

     *

     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"

     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,

     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR

     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR

     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,

     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,

     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;

     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,

     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR

     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,

     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

     *

     *******************************************************************************

     *

     *                       MSP430 CODE EXAMPLE DISCLAIMER

     *

     * MSP430 code examples are self-contained low-level programs that typically

     * demonstrate a single peripheral function or device feature in a highly

     * concise manner. For this the code may rely on the device's power-on default

     * register values and settings such as the clock configuration and care must

     * be taken when combining code from several examples to avoid potential side

     * effects. Also see www.ti.com/grace for a GUI- and www.ti.com/msp430ware

     * for an API functional library-approach to peripheral configuration.

     *

     * --/COPYRIGHT--*/

    /*   Description: Multiple ADC Channels*/

    /****************************A_POOL ADC Conversion *******************************/

    /*                                                                               */

    /*                                                                               */

    /*                          +----L092---+                                        */

    /*                          |*1      14 |                                        */

    /*                          | 2      13 |                                        */

    /*                          | 3      12 |<- Channel A0(0-256mV)                  */

    /*                          | 4      11 |                                        */

    /*                          | 5      10 |                                        */

    /* Channel A2 (0-1000mV)->   | 6       9 |                                        */

    /* Channel A1 (0-256mV)->   | 7       8 |                                        */

    /*                          +-----------+                                        */

    /*                                                                               */

    /*  D.Dang/ D.Archbold/ D.Szmulewicz                                             */

    /*  Texas Instruments Inc.                                                       */

    /*  Built with IAR Version 5.10.4                                                */

    /*********************************************************************************/

     

    #include <msp430.h>

     

    int  ChannelA0, ChannelA1, ChannelA2;

     

    int main(void)

    {

      

       WDTCTL = WDTPW + WDTHOLD;                              // Stop WDT

      

       P1DIR |= (BIT1+BIT4+BIT5);                          

      

      // ANALOG INPUT FOR CHANNEL2 1000mV

        APVDIV=A2DIV_1;

       

     // Begin Configuration of the A-POOL registers 

        APCTL = 0;                                            // Clear APCTL register

        APCNF = CMPON+DBON+CONVON+EOCBU+APREFON+CLKSEL_MCLK;  // Configure A-POOL elements, Select MCLK as A-POOL Clock Source

        APINT = 0x00;                                         // Clear ADC-DAC-REG

    /*************************/

    /* Setup Ports           */

    /*************************/

     

                

                   P1SEL0 |=  BIT5 ;               

                   P1SEL1 |=  BIT5 ;   

       

    /************************/

    /* Setup CCS            */

    /* SMCLK = LFCLK        */

    /************************/

                   CCSCTL0 = CCSKEY;                       // Unlock CCS

                   CCSCTL5 = 0;                            // Set the Dividers for SMCLK to 1

                   CCSCTL4 |= SELM_1 + SELS_1 + SELA_1;    // Select LFCLK/VLO as the source for ACLK, MCLK, and SMCLK  

                   CCSCTL0_H |= 0xFF;                      // Lock CCS

    /* Lock by writing to upper byte */

       

        while(1)

        {

         

         

     

        APIE  = EOCIE;                                        // Enable Interrupt for End of Conversion

        APINT = 0x00;                                         // Clear ADC-DAC-REG

        APCTL = OSEL+CBSTP+RUNSTOP+APNSEL_2+APPSEL_5;         // Set Channels and Start Conversion

        __bis_SR_register(LPM0_bits + GIE);                   // Enter LPM0 w/ interrupts enabled

        ChannelA2 = APINT;                                    // Get Result for A2   

       

      

         if(ChannelA2>20){

         

             P1OUT |= BIT4;

         

         

        }

       

         else{

             P1OUT &=~BIT4;

         }

        TA0CCTL0 = CCIE;                        // TA0CCR0 interrupt enabled

                   TA0CCR0 = 10;                                                    // Set value for TA0CCR0

                   TA0CTL = TASSEL_2 + MC_1 + TACLR;       // SMCLK, cont. mode

     

      __bis_SR_register(LPM0_bits + GIE);         // Enter LPM0 w/ interrupt: CPU, MCLK are disabled

                                                  // ACLK is active, SMCLK is active, and HFOSC is on

      

     __no_operation();                                     // Place breakpoint here

        }

     

    }

     

    //A_POOL Interrupt Service Routine

    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)

    #pragma vector=APOOL_VECTOR

    __interrupt void A_POOL(void)

    #elif defined(__GNUC__)

    void __attribute__ ((interrupt(APOOL_VECTOR))) A_POOL (void)

    #else

    #error Compiler not supported!

    #endif

    {

     

     

      

      

     

        APIFG = 0;                                        // Clear Interrupt Flag      

    __bic_SR_register_on_exit(LPM0_bits);                 // Exit Active to Sample next Channel

     

    }

    // Timer A0 interrupt service routine

    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)

    #pragma vector=TIMER0_A0_VECTOR

    __interrupt void Timer_A0 (void)

    #elif defined(__GNUC__)

    void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer_A0 (void)

    #else

    #error Compiler not supported!

    #endif

    {

     

               

           

            count = count + 1;

           

            if(count == 1000){

            // P1OUT ^= BIT1;

              count =0;

            }

           

           

           

        __bic_SR_register_on_exit(LPM0_bits);

     

    }

     

     

  • Hello,

    I tried building your code and the variable count is undefined, so the build fails. I have created a global variable count.

    Now here is the issue I see with the code:

    Your timer interrupt is set to take the device out of low power mode and turn the CPU back on. The timer is never disabled which means after the first time you set it, it continues to run and when the time interval is passed it tries to take the device out of LPM.

    So the first time you enter the while(1) loop, the code enables the ADC and starts a conversion, enters low power mode and waits until the ADC interrupt takes it out of low power mode. The CPU is turned on and the code continues to execute in main(). The adc value is read and GPIO is set or cleared. then the timer is enabled. It is in continuous mode. which means after timing out the timer continues to run and time out periodically. the device enters LPM mode and waits for timer interrupt. After the first timeout we exit LPM and continue to execute code in main(). We go back to the top of the while loop. The ADC is configured and started but remember this time when we enter low power mode, the timer is still running. So it is a race between the timer interrupt and the ADC interrupt to take us out of the LPM. This is causing your issue. It does not allow for the ADC to finish.

    To make the problem go away, please disable the timer after it takes you out of LPM mode, right before __no_operation().

    Please click verify answer if this answers your original question. we can continue to discuss more issues you face.

  • I appreciate for your attention.

    I can stop the timer by changing its mode instead of being disable.

    In while loop I add up   TA0CTL = TASSEL_2 + MC_0 + TACLR;   this line after enter LPM to stop timer

       

      __bis_SR_register(LPM0_bits + GIE);         // Enter LPM0 w/ interrupt: CPU, MCLK are disabled

       TA0CTL = TASSEL_2 + MC_0 + TACLR;                     

     __no_operation();                                     // Place breakpoint here

        }

    Is my approach correct?

    Thanks 

  • Absolutely, you have many workarounds for this and your way definitely stops the timer.

    Could you please click the "Verify Answer" button on the post that was most useful?
  • It works now very well. You are right. I need to disable my timer interrupt so I add stop mode code for timer (TA0CTL = TASSEL_2 + MC_0 + TACLR;) two different places. First one is the end of timer interrupt and the last one is before __no_operation(); My counter is blinking every one second normally. When the photodiode is enabled, My counter has a 200~250 ms delay. I mean that it blinks every 1250 ms. Can you give me a suggestion to prevent this delay?

    Thanks in advance
  • That is due to the fact that P1.4 has the 1s delay + the time needed for the ADC sample and convert. It seems like the sample and convert in your case in somewhere between 200-250 ms. Which means if you would like P1.4 to be set/cleared every 1s, you must re arrange your code.

    You could do,

    1. Start the timer (and set time out period to 1s)

    2. Start the ADC conversion

    3. Enter Low Power Mode

    since ADC conversion is approximately 4 times faster in your case, the interrupt for this will occur first. Exit low power mode.

    4. Read the ADC value

    5. Enter Low Power Mode again (Remember the timer is still running and it has not timed out yet, It will time out in approximately 750-700 ms)

    The timer interrupt will occur, taking us out of the LPM

    6. Set/Clear P1.4 based on the previously read ADC value

    7. Reset the timer

    Repeat

**Attention** This is a public forum