I added 1.225V external reference to MSP430F2013 pin 5. I using ADC channel A3, P1.6 pin 8. If I test SD16 with external reference it is works fine, when I modified code for external reference - the first reading is good then 0xffff . What could be wrong ?
void main(void)
{
volatile unsigned int i; // Use volatile to prevent removal
WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT = 0;
P1DIR |= 0xB7; // Set P1.0 to output direction
if(1) // external ref
{
P1SEL |= 0x08; // ext 1.2V ref,
SD16CTL = SD16SSEL_1 ; // SMCLK+
}
if(0) // internal ref
{
SD16CTL = SD16REFON + SD16SSEL_1; // 1.2V ref, SMCLK
}
SD16INCTL0 = SD16INCH_3; // A3+/-
SD16CCTL0 = SD16UNI + SD16IE + SD16OSR_1024;//+ SD16VMIDON; // 256OSR, unipolar, interrupt enable+
SD16AE = SD16AE3; // P1.7 A3+, A3- = VSS
SD16CCTL0 |= SD16SC; // Set bit to start conversion+
for (i = 0; i < 0x3600; i++); // Delay for 1.2V ref startup
_BIS_SR(LPM0_bits + GIE);
}
#pragma vector = SD16_VECTOR
__interrupt void SD16ISR(void)
{
static unsigned long int reading_mvolts;
static unsigned int reading_counts;
reading_counts = SD16MEM0;
reading_mvolts = ((1225 * reading_counts)) /65536;
if (reading_counts < RANGE1_COUNTS)
{
P1OUT &= ~0x01;
}
else
{
P1OUT = 0x01;
}
}