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.
I am using the ADC12 on an MSP430F2619 to sample, convert, and display an analog input signal.
When I test the ADC12 using a stable external voltage source (verified stable by a digital multimeter), I get wildly varying codes, with much more variability than the +-5 bits the datasheet claims for total unadjusted error. For example, here is a sequence of codes I read with the debugger with a constant voltage input:
2451, 2458, 2464, 2447, 2444, 2427, 2452, 2462, 2466, 2371, 2449, 2455, 2462
I know from the multimeter that none of the voltages are actually changing. I am using an MSP-TS430PM64 target board and USB programmer, with all my signals routed through jumper wires.
My question is whether there is anything in my code that would suggest software problem, or if this is a hardware issue. What suggests to me that it isn't a hardware problem is that even with a constant voltage I can't get the ADC to convert properly.
Here is my ADC initialization:
void ConfigADC(void)
{
ADC12CTL0 = ADC12ON+SHT0_3+MSC; // Turn on ADC12, sample and hold = 32 cycles, enable multiple conversions
ADC12CTL1 = SHP+CONSEQ_2; // SAMPCON from timer, conversion sequence repeat single channel
ADC12IE = 0x01; // Enable interrupts on channel 1
ADC12MCTL0 = INCH_0 + SREF_2; // Mem0 sample channel 1, use external reference
P6SEL |= 0x01; // Set P6.1 to ADC input
}
Here are my timer and ADC interrupts, in this code I'm trying to take the median value to smooth the conversion, but the raw data is too variable for this to work.
// Timer_A2 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
ADC12CTL0 |= ENC + ADC12SC; // Enable ADC and start conversion
CCR0 += 4000; // Add time to CCR0
}
#pragma vector=ADC12_VECTOR
__interrupt void ADC12ISR (void)
{
static unsigned int index = 0;
static unsigned int i=0;
static unsigned int temp=0;
static unsigned int codematrix [Num_of_Results];
ADCcode = ADC12MEM0;
codematrix[index] = ADCcode;
i = index;
while(i>0){
if(codematrix[i]>codematrix[i-1]){
temp = codematrix[i-1];
codematrix[i-1]=codematrix[i];
codematrix[i] = temp;
i --;
} else{
i = 0;
}
}
index = (index+1)%Num_of_Results; // Increment results index, modulo; Set Breakpoint1 here
if (index == 0){
ADC12CTL0 &= ~ENC;
ADCcode = codematrix[median_result];
if(ADCcode != oldcode){
oldcode = ADCcode;
pow = 10 *(slope * ADCcode + intercept);
dispFloat(pow);
}
ADCcodesum = 0;
}
}
Thanks, any help you can provide would be greatly appreciated!
Doug,
When you measure with the DMM, are you actively using the ADC12 to convert?
Gustavo
I had been. When I disconnected the DMM and just read the ADC I continued getting variation within a range of about 10 codes, with an occasional outlier of 20-30 codes away. Is this about what I should expect?
As a side note, when I measure the voltage on the input pin with no voltage source connected, it reads ~1.5 V. I'm not sure what it should read when it's floating.
**Attention** This is a public forum