5.3 Signed and Unsigned Output
The data format for a sample in Single-Ended mode is unsigned one’s
complement, where 0x0000
represents zero and 0x0FFF
represents the largest number. If the analog input is higher than the reference level of
the ADC, the 12-bit ADC output will be equal to the maximum value of
0x0FFF
. Likewise, if the input is below 0V, the ADC output will be
0x0000
.
For Differential mode, the data format is two's complement with sign extension.
Sample Register Output
The data type of the sample variable should be uint16_t when using Single-Ended mode.
The data type of the sample variable should be int16_t when using Differential mode.
For example, when using Single-Ended mode in 12-bit mode, the voltage of a single sample may be interpreted as shown in the code snippet below.
uint16_t sample_variable = ADCn.SAMPLE;
float sample_voltage = (sample_variable * VREF) / 4095;
When using Differential mode in 12-bit mode, the voltage of a single sample may be interpreted as shown in the code snippet below.
int16_t sample_variable = ADCn.SAMPLE;
float sample_voltage = (sample_variable * VREF) / 2047;
Result Register Output
The data type of the result variable should be uint32_t when using Single-Ended mode.
The data type of the result variable should be int32_t when using Differential mode.
For example, when using Single-Ended mode in 12-bit mode, the voltage of SAMPNUM accumulated samples may be interpreted as shown in the code snippet below.
uint32_t result_variable = ADCn.SAMPLE;
float result_voltage = ((result_variable * VREF) / SAMPNUM) / 4095;
When using Differential mode in 12-bit mode, the voltage of SAMPNUM accumulated samples may be interpreted as shown in the code snippet below.
int32_t result_variable = ADCn.SAMPLE;
float result_voltage = ((result_variable * VREF) / SAMPNUM) / 2047;