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.

CC2530 ADC Battery measuring TIMAC 1.4.0 or Zstack

Other Parts Discussed in Thread: CC2530

Hi all,

I'm measuring two battery voltage with cc2530 ADC. I'm using P0.0 and P0.1. Both with a resistor divide because batteries are 7.2V.

In my code I put this configuration in HalAdcInit() function:

P0SEL |= BV(0);  //  periferic
P0SEL |= BV(1);  // periferic

APCFG |= BV(0); // Enable P0.0 as input ANALOG
APCFG |= BV(1); // Enable P0.1 as input ANALOG

I've a problem when I mesure the voltages. Some times the voltage measured is very low (2.7V or 3.1V).

But measuring with a oscilloscope the voltage batteries are 7.2V.

The problem is random.

In hal_adc.c there is a function "HalAdcRead()" with a comment:

" * The code does NOT disable the pin at the end of this function. I think it is better to leave the pin
 * enabled because the results will be more accurate. Because of the inherent capacitance on the
* pin, it takes time for the voltage on the pin to charge up to its steady-state level. If
* HalAdcRead() has to turn on the pin for every conversion, the results may show a lower voltage
* than actuality because the pin did not have time to fully charge."

But I think these inputs are disable by code in line 169 of "hal_adc.c" with this instruction:
/* Disable channel after done conversion */
ADCCFG &= (adcChannel ^ 0xFF);

Note that ADCCFG is mapped to APCFG register. So every time a channel is  selected, 
his pin is enabled and disabled by the code when a adc read is performed. 
So,
1. Would be better delete the "ADCCFG &= (adcChannel ^ 0xFF);" instruccion in code?
2. Could be a problem if I delete this instruction with P0.0 and P0.1 connected? 
3. The Sigma-Delta modulator could be afected by this?
Thanks.









 

  • Hi Joaquim,

    If you always use P0.0 and P0.1 as ADC inputs, you can remove "ADCCFG &= (adcChannel ^ 0xFF);". But I would recommend turning them back to digital GPIO tri-state inputs when the device goes to sleep to prevent possible leakage.

    The accuracy of the conversion results highly depend on the stability and noise properties of the reference voltage. What kind of reference voltage are you using? There are a couple of sources which can be selected as the ADC voltage reference. Using the most stable voltage source as the reference on AIN7 would produce the most accurate results.

    - Cetri

  • Hi Cetri,

    I'm using always P0.0 and P0.1 as ADC inputs.

    So, do you think is better leave "ADCCFG &= (adcChannel ^ 0xFF);" and turn them back to GPIO tri-state after each conversion?

    I'm using the AVDD_SOC Pin Reference. I think is not the best reference but our +3.3V supply is quite good.

    Thanks.

    Joaquim.