Migrating ASF SAM C21 Application to MPLAB® Harmony v3 PIC32CM MC: Step 3

Last modified by Microchip on 2023/11/09 09:09


Configure the Analog-to-Digital Converter (ADC) Peripheral Library (PLIB)


Click on the Resource Management [MCC] tab, In the Device Resources, expand Peripherals > ADC.
Select and double click on ADC0 to add the ADC module to the project graph.

Available Components and Project Graph pane​​​

Select the ADC Peripheral Library and configure it to sample and convert the light sensor input.

The ADC is configured in Software Trigger mode to convert the samples. The internal reference voltage is fed as a reference voltage.

  • Select Prescaler: Peripheral clock divided by 8 divides the ADC input clock with the configured pre-scaler value and provides more sampling time (CLKADC = 48 MHz/8 = 6 MHz).
  • Select Reference: Internal Reference Voltage.
  • Select Conversion Trigger: SW Trigger.
  • Select Positive Input: ADC AIN3 Pin (the light sensor is connected to AIN3 pin of ADC).
  • Select Result Resolution: 12-bit result (ADC conversion value range from 0 to 4096).

adc configuration options​​​

Configure the ADC Pin.

In the MPLAB® Code Configurator (MCC), select the Pin Settings tab and then scroll-down to PORT pin PB09 in Pin ID column and configure this pin as ADC0_AIN3.

adc pin settings window

This completes the configuration of the ADC PLIB. The ADC is configured to start the conversion on a software event trigger.

Configure Supply Controller (SUPC)

Click on the Resource Management [MCC] tab, In the Device Resources, expand Peripherals > SUPC.
Select and double click on SUPC to add the SUPC module to the project graph.

add supc

In this step, under the SUPC VREF configuration, the reference voltage output is enabled, which is used by ADC as a reference voltage.

SUPC Configuration Options pane

Back to Top