EFR32 ADC Internal Temperature Sensor

by <a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Hero Employee</font></font> </a> PhillipB on ‎12-28-2016 04:29 PM

Question

How can I measure temperature using the internal ADC temperature sensor?

Answer

The "Temperature Measurement" subsection of the ADC chapter in the reference manual contains an expression for this temperature result (TCELSIUS) in terms of the following parameters:

 

  • CAL_TEMP - available in the Device Information (DI) Page, see "DI Page Entry Map" section in Reference Manual for more information
  • ADC0CAL3_TEMPREAD1V25 - also available in DI page
  • V_TS_SLOPE - available in the device Datasheet
  • VFS - specified as 1.25V (1250mV) in the provided expression
  • ADC_result - ADC measurement at 1.25V VFS option and 12-bit resolution

The "inttemp" example for the EFM32 Pearl Gecko (available in-full within Simplicity Studio) demonstrates in ConvertToCelsius() how this technique is implemented using the DI contents on the Pearl Gecko and the formula provided in section 22.3.8.9 "Temperature Measurement" of the Pearl Gecko Reference Manual. Though the variable names are slightly different, this is an identical procedure to that given in section 23.3.4.1 "Temperature Measurement" of the EFR32BG1 Reference Manual.

 

 

/**************************************************************************//**
 * @brief Convert ADC sample values to celsius.
 * @detail See section 25.3.4.1 in the reference manual for detail on
 *   temperature measurement and conversion.
 * @param adcSample Raw value from ADC to be converted to celsius
 * @return The temperature in degrees celsius.
 *****************************************************************************/
static float ConvertToCelsius(int32_t adcSample)
{
  uint32_t calTemp0;
  uint32_t calValue0;
  int32_t readDiff;
  float temp;

  /* Factory calibration temperature from device information page. */
  calTemp0 = ((DEVINFO->CAL & _DEVINFO_CAL_TEMP_MASK)
              >> _DEVINFO_CAL_TEMP_SHIFT);

  calValue0 = ((DEVINFO->ADC0CAL3
                /* _DEVINFO_ADC0CAL3_TEMPREAD1V25_MASK is not correct in
                    current CMSIS. This is a 12-bit value, not 16-bit. */
                & 0xFFF0)
               >> _DEVINFO_ADC0CAL3_TEMPREAD1V25_SHIFT);

  if ((calTemp0 == 0xFF) || (calValue0 == 0xFFF))
  {
    /* The temperature sensor is not calibrated */
    return -100.0;
  }

  /* Vref = 1250mV
     TGRAD_ADCTH = 1.835 mV/degC (from datasheet)
  */
  readDiff = calValue0 - adcSample;
  temp     = ((float)readDiff * 1250);
  temp    /= (4096 * -1.835);

  /* Calculate offset from calibration temperature */
  temp     = (float)calTemp0 - temp;
  return temp;
}

 

 

Comments
by <a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Super Star</font></font> </a> Sili-Chip
on ‎05-06-2017 01:02 PM
Before this can be done I think the ADC has to be initiated? Above the aforementioned temperature section of the manual it says "The configuration of single channel mode is done using the ADCn_SINGLECTRL and ADCn_SINGLECTRLX registers..."

How is this done? Could you elaborate a bit for me please? Are these contained in instructions in Case code? Is this put in the main.c file?

Thanks,
by <a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Hero Employee</font></font> </a> PhillipB
on ‎05-08-2017 10:59 AM

Hello,

 

This KB article describes how to convert a ADC conversion of the internal temp sensor from raw ADC codes into a temperature expression.

 

For information re: how to use the ADC to obtain the initial conversion, please see the "inttemp" example for the EFM32 Pearl Gecko (available in-full within Simplicity Studio), or application note "AN0021: Analog to Digital Converter" available from http://www.silabs.com/32bit-appnotes.

 

Best regards,

- Phillip

by <a href="http://community.silabs.com/t5/Welcome-and-Announcements/Community-Ranking-System-and-Recognition-Program/m-p/140490#U140490"><font color="#000000"><font size="2">Super Star</font></font> </a> Sili-Chip
on ‎05-08-2017 11:35 AM

Hi,

 

AN0021 code

I did instal the AN0021 application note (code) as instructed and was able to import inot work space. Once imported there are three folders (presuming the pg is the closest to my BGM1xx) adc_example_  

...gg

...pg

...tg

 

However when I try and debug it says no program file (works for me other own projects. Can I just import the c files into an existing project:

 

main_adc_example_gecko_s1.c (or soc)?

 

If is this supposed to replace the main.c file; or would I just put them in one of the folders and refer to them in main.c with #include...?

 

Inttemp

There is intemp in the peripherals example folder but unfortunatley the peripheral examples do not work with my SDK - I have been trying to resolve for a while on this thread but not much luck so far (can you help?):

 

http://community.silabs.com/t5/Bluetooth-Wi-Fi-Knowledge-Base/Blue-Gecko-peripheral-examples/tac-p/1...

 

 

Thank you,