AnsweredAssumed Answered

ADC Problem with EA 64kB MCU

Question asked by Robert Maier on Feb 3, 2017
Latest reply on Feb 6, 2017 by Robert Maier



I cannot get multiple ADC channel reads to work for me. If I only read one channel, the individual channel reads everything properly, but if I read multiple things go off the rails.


Here is how I initialize the ADC:

ADC_SC1 = 0;
ADC_SC1|= ADC_SC1_ADCO_MASK;              /* Continuous mode operation */   
ADC_SC2 |=ADC_SC2_REFSEL(0b01);            /* Select VDD and VSS as voltage reference source*/
ADC_SC3 |= ADC_SC3_MODE(TWELVE_BIT) | 0x30;            /* 8,10,12 bit mode operation */
ADC_APCTL1 |= 0x3C;   /* Channel selection */   

This is the subroutine to read the ADC channel:

UINT16 ADC_Read(UINT8 channel)
     if (channel == 2){
          ADC_SC1 |= 0b00000010;
     else if (channel == 3){
          ADC_SC1 |= 0b00000011;
     else if (channel == 4){
          ADC_SC1 |= 0b00000100;
     else if (channel == 5){
          ADC_SC1 |= 0b00000101;
     while(!(ADC_SC1 & ADC_SC1_COCO_MASK));     /* Wait conversion to complete */
     return ADC_R & 0x0FFF;                                   /* Return adc value */



Then I go ahead and read each channel using above subroutine:

adc_val2 =      ADC_Read(2);
adc_val3 =      ADC_Read(3);
adc_val4 =      ADC_Read(4);
adc_val5 =      ADC_Read(5);

I can comment out all but any one desired channel, and I can transmit the correct ADC value via UART, but if I use more than one channel, the read fails. It appears it is showing only the last read channel or not... Weird things happen!


Any advice?