10.1 Initialize the ADC

The ADC Temperature Measurement uses the AVR DA on-chip temperature sensor, and no extra hardware is needed for this use case, except the AVR128DA48 Curiosity Nano Board. In addition to that, the input on the ADC0.MUXPOS register needs to be set on the temperature sensor:

Figure 10-1. ADC0.MUXPOS Selection

To achieve more accurate readings, the result of the temperature sensor measurement must be processed in the application software using compensation values from the device production or user calibration.

The temperature is calculated by the following equation, and it is expressed in Kelvin:

T = ( O f f s e t A D C Re s u l t ) × S l o p e 4096

The Temperature Sensor calibration value contains correction factors for temperature measurements from the on-chip temperature sensor. The SIGROW.TEMPSENSE0 is a correction factor for the gain/slope (unsigned), and SIGROW.TEMPSENSE1 is a correction factor for the offset (signed).

The following snippet code is recommended when using the compensation values from the signature row:

    uint16_t sigrow_offset = SIGROW.TEMPSENSE1;
    uint16_t sigrow_slope = SIGROW.TEMPSENSE0;

    /* Clear the interrupt flag by reading ADC0.RES */
    temp = sigrow_offset - ADC0.RES;
    temp *= sigrow_slope; /* Result will overflow 16-bit variable */
    temp += 0x0800; /* Add 4096/2 to get correct rounding on division below */
    temp >>= 12; /* Round off to nearest degree in Kelvin, by dividing with 2^12 (4096) */
    return temp - 273; /* Convert from Kelvin to Celsius (0 Kelvin - 273.15 = -273.1°C) */

Then the ADC results can be read in a while loop.