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.

Read Vcc using ADC10 MSP430G2553 - wrong readings.

Other Parts Discussed in Thread: MSP430G2553

Hello:

I have a problem when converting Vcc voltage using launchpad msp430g2553 channel 11 ADC10 mux.

My reading is not stable even if Vcc is. Most times the conversion reads 3.2v which is ok, but other times it reads e.g. 2.19v which is NOT ok. When I the USB cable to power lauchpad the problem is not noticeable but when I use my 3.2v regulator it shows. Bessides reading Vcc I also read a voltage of an external voltage that is always ok. This is a sample of my readings:

3.210165

2.195976   ß--- wrong read

3.20157

3.20157

3.197273

3.192975

2.47101    ß--- wrong read

3.188678

3.184381

3.184381

3.180083

3.180083

3.175786

3.171488

3.167191

3.162894

2.195976  ß--- wrong read

This is my code:

 

ADC10CTL0 |= REF2_5V + SREF_1 + REFON; 

  //for(n=0;n<100;n++);

  ADC10CTL1 |= INCH_11;                   // VCC channel

  for(n=0;n<20;n++);         ///90 uS wait

  times=17;

  while (times--) {

      ADC10CTL0 |= ADC10SHT_2 + ADC10ON + ADC10IE;

      for(n=0;n<10;n++);

      ADC10CTL0 |= ENC + ADC10SC;

       __bis_SR_register(LPM3_bits + GIE);                           // Enter LPM3, enable interrupts

      __no_operation();

       ADC10CTL0 &= ~(ENC);

      //ADC10CTL0 &= ~(ADC10ON);   

     // ADC10CTL0 &= ~(REFON);                                        // ADC10 disabled

        tempValue += ADCResult;

  }

  sendData.VCCValue = tempValue>>4;

  ADC10CTL1 = 0x0000;

  ADC10AE0 |= 0x10;                              // P1.5 ADC10 option select analog enable

  ADC10CTL1 |= INCH_4;

  // Read Vstorage get circuit ready

  P2OUT |= 0x10

   ADC10CTL0 = ADC10SHT_2 + ADC10ON + ADC10IE;

  ADC10CTL0 |= ENC + ADC10SC;

  __bis_SR_register(LPM3_bits + GIE);                   // Enter LPM3, enable interrupts

  __no_operation();

  //Read Vstorage circuit down

  P2OUT &= ~0x10

  ADC10CTL0 &= ~(ENC);

  ADC10CTL0 &= ~(ADC10ON);                                  

  ADC10CTL0 &= ~(REFON);                          // ADC10 disabled

  ADC10CTL1 = 0x0000;

 

My second read in channel 4 is always ok. The problems is only when I read Vcc. Vcc is very stable during reading. I’m running out of ideas. Anyone has any clue to what is happening?

  • Well, none of the readings you listed can possible come form the ADC10, as the ADC10 can only give values from 0 to 1023. So where do you get these values from / how do you calculate them?

    After enabling the reference, you need to wait for it to settle. A for loop is not a proper way to do any delay. Since it doesn’t change the system state, the compiler may complete discard it or replace it by a simple assignment (in case the loop variable is read after the loop) Use a timer or the __delay_cycles intrinsic instead.
    Your while loop accumulates 17 values. But then you shift the result by 4 bit, giving you a result that is 6.25% higher than the (likely intended) average. You should use times=16 or use while(--times) or use times=16 and a do{}while(--times);

**Attention** This is a public forum