4.1 ADC 17-Bit Resolution

Todo:
  • Understand how to increase the resolution of the ADC measurement by oversampling
  • Setup DAC reference voltage used by the AC as input to the ADC
  • Configure the ADC to have 17-bit resolution using oversampling
Info: To increase the ADC resolution by n bits, the signal must be oversampled by 4n samples. To achieve a 17-bit resolution, an additional 5-bit resolution is needed, which means that the signal needs to be sampled 45 = 1024 times. The ADC can be configured to accumulate up to 1024 samples. The accumulated result will be the sum of the 1024 samples. This result needs to be scaled down to achieve the desired bit width by dividing by the scaling factor. The scaling factor is given by 2n. To increase the resolution by 5 bits, we either need to divide the result by 25 = 32 or right shift it by 5.
  1. At the beginning of adc_init, set up the DAC voltage reference to 2.048V by writing:
    VREF.CTRLA = VREF_AC0REFSEL_2V048_gc; /* Voltage reference for AC */
    AC0.DACREF = 0xFF; /* DACREF is VREF */
    Tip: The internal reference voltage generator (DACREF) can be used to create specific voltage references. The voltage reference VDACREF is configured through the Analog Comparator.
    Info:

    The DAC voltage reference depends on the DACREF value and the reference voltage selected in the VREF module Control Register A and is calculated as: V D A C R E F = D A C R E F 256 × V R E F

  2. Configure the MUXPOS to have the DAC reference as an input source:
    ADC0.MUXPOS = ADC_MUXPOS_DAC_gc; /*DAC from AC0*/
  3. Configure the ADC so it can achieve 17-bit resolution by setting ADC_SAMPLES in adc.h to the right number of samples using the ADC_SAMPNUM macros by writing:
    #define ADC_SAMPLES ADC_SAMPNUM_ACC1024_gc
  4. In the main() function right shift the accumulated result to scale the result down to 17-bit by writing:
    adc_t.adc_high_res_result = adc_t.adc_result>>(ADC_SAMPLES/2);
  5. Left-shift the averaged result, so it becomes on the same scale as the high-resolution result by writing:
    adc_t.adc_average_result = adc_t.adc_average_result<<(ADC_SAMPLES/2);
    Info: To see the impact of the difference in resolution between 12-bit and 17-bit, the two results are scaled to the same range.
    Result: The main should look like the following:
    adc_t.adc_average_result = adc_t.adc_result>>ADC_SAMPLES;
    adc_t.adc_average_result = adc_t.adc_average_result<<(ADC_SAMPLES/2);
    			
    adc_t.adc_high_res_result = adc_t.adc_result>>(ADC_SAMPLES/2);
    It is important to take the average of the accumulated measurements before the 12-bit result is scaled up.
  6. Verify that the solution builds with no errors by selecting Build → Build Solution from the top menu bar in Microchip Studio or pressing the F7 key.
  7. Flash the device by selecting Debug → Start without debugging for the top menu bar in Microchip Studio or pressing the Ctrl+Alt+F5 keys.
  8. Plot the 17-bit result and the 12-bit result in the Data visualizer by loading the workspace Assignment3.json.
Result: The ADC is configured to measure the DAC reference voltage from the AC module using oversampling to increase the resolution to 17-bit. Figure 4-1 shows the comparison between the 17-bit and the 12-bit result. The 17-bit result is in green, while the 12-bit result is in red. Observe that the 17-bit signal can take much smaller steps than the 12-bit signal.
Figure 4-1. Assignment 3: 17-Bit vs. 12-Bit