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.

ADC in MSP430F5438

Hi,

I have used the following code for Analog to Digital Conversion(ADC) using internal voltage reference.

#include <msp430.h>
int main(void)
{  
volatile unsigned int i;  
WDTCTL = WDTPW + WDTHOLD;                   // Stop watchdog timer
P6SEL |= 0x01;                            // Enable A/D channel A0  
ADC12CTL0 = ADC12ON+ADC12SHT02+ADC12REFON+ADC12REF2_5V;                                            
// Turn on ADC12, Sampling time,On Reference Generator and set to 2.5V
ADC12IE = 0x01;                           //Enable IFG
ADC12CTL1 = ADC12SHP;                     // Use sampling timer
ADC12MCTL0 = ADC12SREF_1;                 // Vr+=Vref+ and Vr-=AVss  
for ( i=0; i<0x30; i++);                  // Delay for reference start-up  
ADC12CTL0 |= ADC12ENC;                    // Enable conversions
while (1)
{    ADC12CTL0 |= ADC12SC;                   // Start conversion    
while (!(ADC12IFG & BIT0));
    __no_operation();                       // SET BREAKPOINT HERE  
}
}

When I simulate this code by giving analog input to A0/P6.0, I donot get conversion result in the ADC12MEM0 register.

Can anyone help me in this regard ??

Thank you in advance

  • Do you have the 5438 or the 5438A? The 5438A has a REF module which overrides the reference settings of the ADC12 module by default. You'll need to clear the REFMSTR bit in the REF module to enable them or configure the reference in the REF module.

    Durgesh Sritharan said:
    for ( i=0; i<0x30; i++);                  // Delay for reference start-up  

    You should use __delay_cycles instead. an empty for loop is no reliable delay - the compiler may discard it completely (using volatile on a local variable makes no sense, as it is auto-storage and the compiler knows that it has no side effects)

**Attention** This is a public forum