Other Parts Discussed in Thread: MSP430F5509
Hi I am a newbie in using MSP430F5509 and I have a problem in reading the ADC input value.
Here is my code.
#include "msp430.h"
unsigned int ADC_Result;
int main()
{
volatile unsigned int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P6SEL |= BIT0;
// Configure ADC
ADC10CTL0 |= ADC10SHT_2 + ADC10ON; // ADC10ON, S&H=16 ADC clks
ADC10CTL1 |= ADC10SHP; // ADCCLK = MODOSC; sampling timer
ADC10CTL2 |= ADC10RES; // 10-bit conversion results
ADC10MCTL0 |= ADC10INCH_0; // A0 ADC input select; Vref=AVCC
ADC10IE |= ADC10IE0; // Enable ADC conv complete interrupt
ADC10CTL0 |= ADC10ENC;
P1DIR |= BIT0; // Set P1.0/LED to output direction
P1OUT&= ~BIT0;
while (1)
{
ADC10CTL0 |= ADC10ENC + ADC10SC; // Sampling and conversion start
__bis_SR_register(LPM0_bits + GIE); // LPM0, ADC10_ISR will force exit
__no_operation(); // For debug only
if (ADC_Result < 255)
P1OUT &= ~BIT0; // Clear P1.0 LED off
else
P1OUT |= BIT0; // Set P1.0 LED on
}
}
// ADC10 interrupt service routine
#pragma vector=ADC10_VECTOR
__interrupt void ADC10_ISR(void)
{
switch(__even_in_range(ADC10IV,12))
{
case 0: break; // No interrupt
case 2: break; // conversion result overflow
case 4: break; // conversion time overflow
case 6: break; // ADC10HI
case 8: break; // ADC10LO
case 10: break; // ADC10IN
case 12: ADC_Result = ADC10MEM0;
__bic_SR_register_on_exit(LPM0_bits);
break; // Clear LPM0_bits from 0(SR)
default: break;
}
}
Upon debugging the contents of ADC_Result, I am getting a value of "613" although Analog input 0 is directly connected to the GND.
Thank you very much in advance for your help.