# Temperature Measurement

The temperature measurement is based on an on-chip temperature sensor. For temperature measurement, follow these steps:
1. 1.Configure the internal voltage reference to 1.1V by configuring the VREF peripheral.
2. 2.Select the internal voltage reference by writing the REFSEL bit field in ADCn.CTRLC register to 0x0.
3. 3.Select the ADC temperature sensor channel by configuring the MUXPOS (ADCn.MUXPOS) register. This enables the temperature sensor.
6. 6.In ADCn.CTRLC select SAMPCAP=1 .
7. 7.Acquire the temperature sensor output voltage by starting a conversion.
8. 8.Process the measurement result, as described below.
The measured voltage has a linear relationship to the temperature. Due to process variations, the temperature sensor output voltage varies between individual devices at the same temperature. The individual compensation factors are determined during the production test and saved in the Signature Row:
• SIGROW.TEMPSENSE0 is a gain/slope correction
• SIGROW.TEMPSENSE1 is an offset correction

To achieve accurate results, the result of the temperature sensor measurement must be processed in the application software using factory calibration values. The temperature (in Kelvin) is calculated by this rule:

Temp = (((RESH << 8) | RESL) - TEMPSENSE1) * TEMPSENSE0) >> 8

RESH and RESL are the high and low bytes of the Result (ADCn.RES) register, and TEMPSENSEn are the respective values from the Signature row.

It is recommended to follow these steps in user code:

int8_t sigrow_offset = SIGROW.TEMPSENSE1;  // Read signed value from signature row
uint8_t sigrow_gain = SIGROW.TEMPSENSE0;    // Read unsigned value from signature row
uint16_t temperature_in_K = temp;