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.

ADC difference for ZStack-CC2530-2.4.0-1.4.0 and ZStack-CC2530-2.3.0-1.4.0

Other Parts Discussed in Thread: CC2530

Dear all,

I found that hal_adc.c in ZStack-CC2530-2.4.0-1.4.0 and ZStack-CC2530-2.3.0-1.4.0 are different.

Now i add hal_adc.c and hal_adc.h of ZStack-CC2530-2.4.0-1.4.0 into my own project based on BasicRF.

And i have called HalAdcInit() in halBoardInit(), which set the ADC reference of pin AVDD5.

then i want to have ADC on port P0.0, the code snap is listed as follows:

---------------------------------------------------------------------------------------------------------

adctemp=HalAdcRead(HAL_ADC_CHANNEL_0,HAL_ADC_RESOLUTION_10);

---------------------------------------------------------------------------------------------------------

However, the returned value of adctemp seems have some problems.

If i set HAL_ADC_RESOLUTION_10, then it returns 511.

If i set HAL_ADC_RESOLUTION_8, then it returns 127.

So, what does that mean? 

Would you please give me some advise?

Thanks a lot!

 

  • Hi Jiong,

     

    First thing: Did you configured P0.0 to be an analogue input for the ADC?

    Secondly, what is the voltage you are measuring by a voltmeter on P0.0

    (in other words, what are the sampled values you are expecting to get

    from this pin)?

     

    Br,

    Igor

  • Dear Sherer,

    Thanks for your reply.

    I haven't configed P0.0 before HalAdcRead, cause i found that in HalAdcRead, there are lines of code:

     ----------------------------------------------------------------------------------------------------------------------------------------

    if (channel < 8)
      {
        for (i=0; i < channel; i++)
        {
          adcChannel <<= 1;
        }
      }

      /* Enable channel */
      ADCCFG |= adcChannel;

    -------------------------------------------------------------------------------------------------------------------------------------------

    So, i think that if i pass channel to the HalAdcRead, it will config for me. Is that true?

     

    Furthermore, i want to monitor battery voltage from P0.0. And the max volt will be 3.3V, which is the same value for Pin AVDD5. Can this be implemented?

     

    Thanks for your help!

  • Hi jiong,

     

    I think that it is a better way to do a battery monitoring by

    sampling HAL_ADC_CHN_VDD3. which is the VDD/3

    (where VDD is the voltage on AVDD5 pin).

    In such way you get the full scale of input voltage, without

    the need of using P0.0.

    Is there any particular reason why you want to measure the

    battery voltage from P0.0?

     

    Br,

    Igor

     

  • Dear Sherer,

    The battery volt ranges from 0~4.3V, and we use a LDO to stablize the volt to 3.3V, which is the volt we supply to CC2530.

    And we also use resistive subdivision to make sure that the volt on P0.0 will not exceed 3.3V.

    So, actually, we use the output of LDO as reference Volt, and monitor the volt of battery after resistive subdivision.

    Is this solution OK?

    Thanks for your attention.

  • Dear jiong,

     

    It is not a good idea to measure directly the input voltage.

    What you can do is to set ADC reference to HAL_ADC_REF_125V,

    which is represents a constant voltage of 1.15V.

    HalAdcSetReference( HAL_ADC_REF_125V ); 

    Then you can use the HalAdcRead() as follow:

    uint8 someVar = (uint8)HalAdcRead( HAL_ADC_CHN_VDD3, HAL_ADC_RESOLUTION_8 );

    Now, if someVar equals to 127 you know that the LDO output voltage

    is ~3.45V. From here on you can implement your logic.

    Hope this helps.

     

    Br,

    Igor

     

  • Dear Sherer,

    Thanks for your great help.