34 Temperature Sensor
An on-chip temperature sensor is available. To do a temperature measurement, the internal ADC peripheral acquires the sensor output. Using correction values from the System Controller (SYSCTRL) fuses, the application can calculate a temperature value in kelvin.
- Configure the ADC voltage reference to internal 2.048V by writing to the Reference Selection (REFSEL) bit field in the Control C register of the ADC (ADC.CTRLC).
- In the ADC Input Control (ADC.INPUTCTRL) register select the temperature sensor (TSENSE) as input in the Positive Input Multiplexer (MUXPOS) bit field.
- Configure the ADC Sample Length by writing a value ≥ to the Sample Length (SAMPLEN) bit field in the Control E (ADC.CTRLE) register.
- Acquire the temperature sensor output voltage by running a 12-bit single-ended conversion using the ADC.COMMAND register.
- Process the measurement result, as described below.
- SYSCTRL.TEMPSENSE0 is a gain/slope correction
- SYSCTRL.TEMPSENSE1 is an offset correction
The calibration values can be used to improve the accuracy of the result. To achieve even more accurate results, it is possible to perform further calibration. For example, multi-point calibration is performed by imposing known temperatures on the device and recording the ADC results. This helps create a precise calibration curve which can be implemented in firmware to adjust the output result.
Use the following equation to calculate the temperature (in kelvin):
Using the Calibration Values to Improve the Accuracy of the Temperature Readings
//Prerequisite: Configure ADC0 as described in the references
uint16_t sigrow_gain = SYSCTRL.TEMPSENSE0; // Read unsigned gain/slope from System Controller fuse
int16_t sigrow_offset = SYSCTRL.TEMPSENSE1; // Read signed offset from System Controller fuse
ADC_COMMAND_START
while (!(ADC0->INTFLAG.reg & ADC_INTFLAG_RESRDY)) {
// Wait for result ready
}
uint16_t adc_reading = ADC0.RESULT >> 2; // 10-bit MSb of ADC result with 2.048V internal reference
uint32_t temp = adc_reading - sigrow_offset;
temp *= sigrow_gain; // Result might overflow 16-bit variable (10-bit + 8-bit)
temp += 0x80; // Add 256/2 to get correct integer rounding on division below
temp >>= 12; // Divide result by 4096 to get processed temperature in kelvin
uint16_t temperature_in_K = temp;Refer to the Electrical
Characteristics and the ADC - Analog-Digital Converter chapters for
details on the configuration of the ADC for temperature measurements.