7.2 PGA Configuration

Todo:
  • Plot a graph of measurements without using the PGA
  • Configure the ADC to use the PGA to amplify the signal
  • Plot a graph of measurements with the amplified signal
  1. Verify that the solution builds with no errors by selecting BuildBuild Solution from the top menu bar in Microchip Studio or pressing the F7 key.
  2. Flash the device by selecting Debug → Start without debugging for the top menu bar in Microchip Studio or pressing the Ctrl+Alt+F5 keys.
    Info: Configure the project to do periodic burst measurements using the RTC and event system as in assignment 2.
  3. Load the workspace Assignment6.json in the MPLAB Data Visualizer.
  4. Press the force sensor as hard as possible and observe the graph in the MPLAB Data Visualizer.
    Result: The plot should look similar to Figure   1, where the top value is around 1k. The value is expected to be around 1k, as the voltage divider divides the voltage by 4, and VCC is represented in the ADC by 4095.
    Figure 7-3. Assignment 6: No Amplification
  5. Configure the PGA to amplify the signal by 4x, have a bias current of 50%, a sampling duration of 15 clock cycles, and enable the PGA by writing the following in adc.c:
    ADC0.PGACTRL = ADC_GAIN_4X_gc | ADC_PGABIASSEL_1_2X_gc | ADC_ADCPGASAMPDUR_15CLK_gc | ADC_PGAEN_bm;
    Info: The PGABIASSEL determines how much current the PGA uses. How much current the PGA needs depends on the ADC clock frequency. See the PGA Control (PGACTRL) register description in the device data sheet for info about how much current the PGA needs.
    Info: When using the PGA, the SAMPDUR determines the input sample duration, while ADCPGASAMPDUR determines for how long the ADC samples the PGA.
  6. Connect the input via the PGA by writing:
    ADC0.MUXPOS = ADC_MUXPOS_AIN6_gc | ADC_VIA_PGA_gc; /*ADC channel AIN6->PA6, input connected to the ADC via PGA*/
    Info: The VIA bits in MUXPOS and MUXNEG are shared, so a value written to the VIA bit field in one of the two registers is updated in both. Therefore, it is impossible to have one input using the PGA and the other not using the PGA.
  7. Verify that the solution builds with no errors by selecting BuildBuild Solution from the top menu bar in Microchip Studio or pressing the F7 key.
  8. Flash the device by selecting Debug → Start without debugging for the top menu bar in Microchip Studio or pressing the Ctrl+Alt+F5 keys.
  9. Press the force sensor and observe the plot in the MPLAB Data Visualizer.
Result: The result should look similar to Figure   2, where the top value is about 4k.
Figure 7-4. Assignment 6: Amplified Signal