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.

cc2538 ADC output interpretation

Other Parts Discussed in Thread: CC2538

Hi I need help with interpreting the ADC output of CC2538.  I am getting 23204 from the temperature sensor. I would like to know the formula to convert it to temperature. Similarly the battery sensor reads 30152, I need the formula to convert the data to voltage. Any help will be appreciated.

Thanks

Vasanth

  • Vasanth,

    how do you read the ADC result?
  • Hi Dennis Thanks for the reply. I am using contiki's built in function to read the ADC output; Which is as follows:

    int temperature = temperature_sensor.value(0);



    /*---------------------------------------------------------------------------*/
    void
    adc_init(void)
    {
    /* Start conversions only manually */
    REG(SOC_ADC_ADCCON1) |= SOC_ADC_ADCCON1_STSEL;
    }
    /*---------------------------------------------------------------------------*/
    int16_t
    adc_get(uint8_t channel, uint8_t ref, uint8_t div)
    {
    uint32_t cctest_tr0, rfcore_xreg_atest;
    int16_t res;

    /* On-chip temperature sensor */
    if(channel == SOC_ADC_ADCCON_CH_TEMP) {
    /* Connect the temperature sensor to the ADC */
    cctest_tr0 = REG(CCTEST_TR0);
    REG(CCTEST_TR0) = cctest_tr0 | CCTEST_TR0_ADCTM;

    /* Enable the temperature sensor */
    rfcore_xreg_atest = REG(RFCORE_XREG_ATEST);
    REG(RFCORE_XREG_ATEST) = (rfcore_xreg_atest & ~RFCORE_XREG_ATEST_ATEST_CTRL) |
    RFCORE_XREG_ATEST_ATEST_CTRL_TEMP;
    }

    /* Start a single extra conversion with the given parameters */
    REG(SOC_ADC_ADCCON3) = (REG(SOC_ADC_ADCCON3) &
    ~(SOC_ADC_ADCCON3_EREF | SOC_ADC_ADCCON3_EDIV | SOC_ADC_ADCCON3_ECH)) |
    ref | div | channel;

    /* Poll until end of conversion */
    while(!(REG(SOC_ADC_ADCCON1) & SOC_ADC_ADCCON1_EOC));

    /* Read conversion result, reading SOC_ADC_ADCH last to clear
    * SOC_ADC_ADCCON1.EOC */
    res = REG(SOC_ADC_ADCL) & 0xfc;
    res |= REG(SOC_ADC_ADCH) << 8;

    /* On-chip temperature sensor */
    if(channel == SOC_ADC_ADCCON_CH_TEMP) {
    /* Restore the initial temperature sensor state and connection (better for
    * power consumption) */
    REG(RFCORE_XREG_ATEST) = rfcore_xreg_atest;
    REG(CCTEST_TR0) = cctest_tr0;
    }

    /* Return conversion result */
    return res;
    }
  • Hi,

    Your post has been moved to the ZigBee®, 6LoWPAN & 802.15.4 MAC Forum as I believe they should be able to provide you with the information that you need.

    Thanks,

    David
  • You can download CC2538 foundation firmware from http://www.ti.com/tool/cc2538-sw and will find the file adc tempsens example under cc2538_foundation_firmware_1_0_1_0\driverlib\cc2538\examples\adc.

  • Battery voltage monitor can be implemented by using internal A/D. Please refer to section 15.2.1of CC2538 UG (SWRU319C)
  • Hi YK Chen,
    Thanks for your reply. I will try out the example and share the out come.
  • You are welcome.
  • Hi YiKai,

    The examples are very helpful and  It had the formula to calculate the temperature.  However the sensor reading is much higher than my room temperature.

    My room temperature is :  76F  24.44C

    The sensor reads:   88.76F  31.534C

    The sensor temperature goes down if I take it near to a AC vent. However there is a discrepancy. Does it need any offsetting?

    Thanks,
    Vasanth

  • Yes, it needs to do calibration.
  • hi Vasanth,
    how to convert the adc value to voltage ?
    now i call adc_get(0x07,0<<6 , 3<<4) function read the adc value is 32764
  • hi vasanth,
    i call the function:adc_get(0x7,0<<6,3<<4) the adc value is 32764 , how to convert it to voltage value?