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.

MSP430G2553: continuous ADC10 sampling (with interrupt)

Part Number: MSP430G2553
Other Parts Discussed in Thread: MSP-FET
#include <msp430g2553.h>

/**
 * main.c
 * Use ADC module to read the value of the MCU's internal temperature sensor
 * and dump those values into an array.
 */

volatile unsigned counter = 0;
volatile unsigned temparr[20];

void main(void)
{
    WDTCTL = WDTPW + WDTHOLD;                                           // Stop WDT

    ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON + ADC10IE + MSC;  // Set ADC module
    ADC10CTL1 = CONSEQ_2 + INCH_10 + ADC10DIV_7;                        // Set ADC module
    ADC10DTC0 = ADC10CT;                                                // Set ADC module

    ADC10CTL0 |= ENC + ADC10SC;

    __enable_interrupt();

}

#pragma vector=ADC10_VECTOR
__interrupt void ADC10_IRS(void)
{
    //while (ADC10CTL1 & BUSY);                                           // Give time to the ADC to settle

    if (counter < 20) {
        temparr[counter] = ADC10MEM;
        counter++;
    }

    else {
        counter = 0;
        ADC10CTL0 &= ~(ENC + ADC10SC);
    }
}

I wrote a small program to continuously sample the internal temperature sensor of the MSP430G2553 based on the ADC10 interrupt. My code, however, does not do that. It triggers the interrupt (only) once, it populates the first index of the array,  and then it stops. What am I missing? Thanks.

  • > while (ADC10CTL1 & BUSY); // Give time to the ADC to settle

    With CONSEQ=2 or 3, the ADC is always busy. Even in the other modes, this loop serves no purpose. I recommend you remove it.
  • Thank you Bruce. Unfortunately, removing the "while" loop did not solve my problem. The first index of the array gets populated with the first sample (the interrupt gets triggered once) but the interrupt does not get "hit" a second time. Same thing happens with or without the while loop.

  • I recommend to have a look to the example code "msp430g2x33_adc10_temp.c" here:
    www.ti.com/.../getliterature.tsp

    you need a loop in your main code to get the result from the temp sensor repeatedly.

    Best regards
    Lukas
  • When I removed the while() loop it ran fine (G2553, G2 Launchpad, CCS 8.1, -O[default]). So you and I are doing something different outside the code here.
  • Hi Lukas. Thank you for the suggestion. I have looked at all the ADC10 examples - under the ti resource explorer. Though most ADC examples seem to be geared towards the G2x33 family, I assumed they would work the same for the G2553. Part of my problem (I think) is that In my mind, the use of interrupts eliminates the need for a loop (therefore the need to trap the CPU indefinitely). Because of the ADC10 control registers setup (continuous sampling) and the enabling of the ADC10 interrupt, the ISR would get triggered after the ADC10MEM would be populated with the conversion continuously until the ENC bit would be set to 0. Am I understanding the workflow correctly?

  • Hi Bruce. I'm using the MSP-FET debugger connected directly to an MSP430G2553 (no launchpad). If you add an expression-watch on that temparr variable, does it get populated correctly for you?
  • I know this is probably going to sound insane: I have ran the same program a few times. All of the sudden my code started to work. Can it be a debugger problem? I know that MSP-FET has been giving people a harder time (after the last update). Well, now it works! No loops, nothing! Thank you much for running this on your G2553 Launchpad.

  • So I'm closing the thread since the issue is resolved.

**Attention** This is a public forum