Other Parts Discussed in Thread: LMT86
Tool/software: Code Composer Studio
Hello all,
I'm trying to read two channels (one after another) in single channel mode (I don't need to convert all of them at once). Problem is, it seems that only one channel is read (the one that starts first), and if I insert 3V3 on it, the reading is around 2045. Say, if I start conversion on channel A0 first, only A0 will work until the end.
I'm configuring the ADC this way:
void configADC(void)
{
// Configure ADC A0 pin
P1SEL0 |= BIT0;
P1SEL1 |= BIT0;
// Configure ADC10
ADCCTL0 &= ~ADCENC; // Disable ADC
ADCCTL0 = ADCSHT_2 | ADCON; // ADCON, S&H=16 ADC clks
ADCCTL1 = ADCSHP | ADCCONSEQ_0; // ADCCLK = MODOSC; sampling timer
ADCCTL2 = ADCRES; // 10-bit conversion results
ADCIE = ADCIE0; // Enable ADC conv complete interrupt
}
And I'm trying to read it this way:
#define A3 true
#define A0 false
uint16_t g_adcResult
uint16_t analogRead(bool channel)
{
if(channel)
ADCMCTL0 = ADCINCH_3 | ADCSREF_0; // A3 ADC input select = OA output Vref = DVCC
else
ADCMCTL0 = ADCINCH_0 | ADCSREF_0; // A0 ADC input select Vref = DVCC
ADCCTL0 |= ADCENC | ADCSC; // Sampling and conversion start
__bis_SR_register(LPM0_bits); // Enter LPM0, ADC_ISR will force exit
return g_adcResult;
}
void main(void)
{
uint16_t adcTempTerm = 0;
//some code...
adcTempTerm = analogRead(A0) + analogRead(A3);
}
The ADC ISR:
#pragma vector=ADC_VECTOR
__interrupt void ADC_ISR(void)
{
switch(__even_in_range(ADCIV, ADCIV_ADCIFG))
{
case ADCIV_NONE:
break;
case ADCIV_ADCOVIFG:
break;
case ADCIV_ADCTOVIFG:
break;
case ADCIV_ADCHIIFG:
break;
case ADCIV_ADCLOIFG:
break;
case ADCIV_ADCINIFG:
break;
case ADCIV_ADCIFG:
g_adcResult = ADCMEM0;
__bic_SR_register_on_exit(LPM0_bits);
break;
default:
break;
}
}
I'm facing difficulties trying to search information regarding how to properly setup single conversions. Is there a way to achieve what I'm trying to do? Please note that my current program has only 48 bytes of memory left.