I'm using ADC12 in single-channel-single-conversion mode on an MSP430F5419 (non-A). I have two analog inputs:
ch1 has no signal input for 0 counts
ch2 has a small input for 1290 counts
If I continuously read ch1 ch2, all conversions are correct. If I alternate between channels, ch1 ch2 eventually shows a 0 conversion result (or near 0), then returns to normal. I'm at a loss. I've scoped ch1 ch2 adc input looking for low-value fluctuations...none found. Any help is much appreciated!
Code
//------ Internal ADC Setup --------------------------------------------------------------
ADC12CTL0 = ADC12ON + ADC12REFON; // Turn on ADC and reference
ADC12CTL1 = ADC12SSEL_1; // Select ACLK (1 MHz) as ADC clk source
ADC12CTL2 = ADC12PDIV + ADC12RES_2; // PreDivide-by-4 ADC clk, 12 bit conversions
ADC12MCTL0 = ADC12SREF_1 + ADC12INCH_0; // Select ADC reference 1.5V internal, ch0
//------ ADC state machine -------------------------------------------------------------
switch (adc_sm)
{
//------ Start sample channel -------------------------------------------------------
case 0:
ADC12CTL0 |= ADC12SC + ADC12ENC; // Sample channel
ticks = SYS_TICKS; // Get system tick count
adc_sm = 1; // Select next state
break;
//------ Check sampling complete ----------------------------------------------------
case 1:
if (CheckTicks(ticks, TPS * 0.1) == true) // If 100ms sample period expired
{
ADC12CTL0 &= ~ADC12SC; // Start conversion
adc_sm = 2; // Select next state
}
break;
//------ Check conversion complete --------------------------------------------------
case 2:
if ((ADC12CTL1 & ADC12BUSY) == false)
{
ai_ch[ch].value = ADC12MEM0; // Save conversion
ch = ch ^ 1; // Get next channel
ADC12CTL0 &= ~ADC12ENC; // Disable ADC
ADC12MCTL0 &= 0xF0; // Clear ADC channel select
ADC12MCTL0 |= ch; // Select new ADC channel
adc_sm = 0; // Select sample channel state
}
break;
default:
adc_sm = 0;
break;
}