ADC Peripheral Library (PLIB) for Harmony v2

This library allows you to:

  • Initialize the ADC module:
    • Enable/disable the ADC module
    • Select voltage reference sources
    • Select input channel and configure the MUX inputs
    • Select scan mode; positive and negative analog input channel
    • Select conversion clock
    • Set the number of the S&H channels to be used
  • Control the ADC sampling process:
    • Enable/disable sampling
    • Select manual or auto-sampling
    • Select conversion trigger and sampling time
    • Select the number of readings per interrupt
    • Select the number of samples in the DMA buffer for each ADC module and select how the DMA will access the ADC buffers
  • Control the ADC conversion process:
    • Select conversion trigger and sampling time
    • Start and terminate conversion process
    • Configure channel pair and trigger source
    • Configure interrupt control and conversion order
  • Format the result buffer:
    • Select how conversion results are stored in the buffer
    • Select the result format and assign the result sign
    • Select the mode: 10-bit or 2-bit

Example Library Functions

Description Associated Functions
Voltage reference source; enable/disable ADC PLIB_ADC_VoltageReferenceSelect (MY_ADC_INSTANCE, ADC_REFERENCE_VREFPLUS_TO_AVSS)
PLIB_ADC_Enable (MY_ADC_INSTANCE)
PLIB_ADC_Disable (MY_ADC_INSTANCE)
ADC conversion clock PLIB_ADC_ConversionClockSet (MY_ADC_INSTANCE, 80000000, 320000000)
Input channel selection; MUX A and B inputs PLIB_ADC_InputSelectPositive (MY_ADC_INSTANCE, ADC_INPUT_POSITIVE_AN2)
PLIB_ADC_InputSelectNegative (ADC_ID_1, ADC_INPUTS_NEGATIVE)
Determine how sampling will occur PLIB_ADC_SampleAcquisitionTimeSet (MY_ADC_INSTANCE, 2)
Manual or Auto-Sampling PLIB_ADC_SampleAutoStartEnable (MY_ADC_INSTANCE)
PLIB_ADC_SampleAutoStartDisable (MY_ADC_INSTANCE)
Conversion trigger, sampling time PLIB_ADC_ConversionStart (MY_ADC_INSTANCE)
PLIB_ADC_ConversionClockSourceSelect (MY_ADC_INSTANCE, ADC_CLOCK_SOURCE)
PLIB_ADC_ConversionTriggerSourceSelect (MY_ADC_INSTANCE, ADC_CLOCK_SOURCE_SYSTEM_CLOCK)
Conversion results buffer PLIB_ADC_ResultBufferModeSelect (MY_ADC_INSTANCE,ADC_BUFFER_MODE_TWO_8WORD_BUFFERS)
Result sign format PLIB_ADC_ResultFormatSelect (MY_ADC_INSTANCE, ADC_RESULT_FORMAT)
Number of readings per interrupt PLIB_ADC_SamplesPerInterruptSelect (MY_ADC_INSTANCE, ADC_16SAMPLES_PER_INTERRUPT)
Number of samples in the DMA buffer for each ADC; how the DMA will access the ADC buffers PLIB_ADC_DMAEnable (MY_ADC_INSTANCE)
PLIB_ADC_DMADisable (MY_ADC_INSTANCE)
PLIB_ADC_DMAInputBufferSelect (MY_ADC_INSTANCE, ADC_DMA_INPUT_BUFFER_1WORD)
10-bit or 12-bit mode PLIB_ADC_ResultSizeSelect (MY_ADC_INSTANCE, ADC_RESULT_SIZE_10_BITS)
Channel pair configuration PLIB_ADC_PairTriggerSourceSelect (MY_ADC_INSTANCE, ADC_PAIR_AN0_AN1,ADC_CONVERSION_TRIGGER_TMR3_COMPARE_MATCH)
Misc. ADC functions:
• Asynchronous sampling selection
• Conversion order selection
• Global software trigger control
PLIB_ADC_AsynchronousDedicatedSamplingEnable (MY_ADC_INSTANCE) PLIB_ADC_AsynchronousDedicatedSamplingDisable (MY_ADC_INSTANCE) PLIB_ADC_GlobalSoftwareTriggerSet (MY_ADC_INSTANCE)

NOTE: MY_ADC_INSTANCE is the ADC instance selected for use by the application developer. E.g.,
#define MY_ADC_INSTANCE DRV_ADC_INDEX_0
int main ( )
{….}


DRV_ADC_INDEX is the ADC module's index number macro, defined in the DRV_ADC header file. These provide the ADC index definitions. E.g.,
#define DRV_ADC_INDEX_0 0

Important notes on using this library:

  • The MPLAB® Harmony PLIB Overview provides more details and background on PLIB usage
  • Peripheral Libraries are only supported for internal (on board) microcontroller peripherals. External peripherals are always connected to the microcontroller through one or more internal peripheral interfaces and therefore, do not require peripheral library support.

 Learn More

 
Harmony ADC Tutorial
Learn more >
 
Example Code and Projects
Learn more >
 
Entire ADC PLIB Interface
Learn more >
 
ADC Hardware Description
Learn more >
© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.