4.1.3.1 12-bit ADCC with Context
12-bit Analog-to-Digital Converter with Computation and Context (ADC3)
4.1.3.1.1 Introduction
The Analog-to-Digital Converter with Computation and Context (ADC3) conversion of both single-ended and differential analog input signals to a 12-bit binary representation of that signal. This device uses analog inputs, which are multiplexed into a single sample and hold circuit. The output of the sample and hold is connected to the input of the converter. The converter generates a 12-bit binary result via successive approximation and stores the conversion result into the ADC result registers.
4.1.3.1.2 Supported Device Families
PIC18F-Q71 | PIC18F-Q8x |
4.1.3.1.3 Required Header Files:
#include "mcc_generated_files/adc/adc.h"
4.1.3.1.4 How to use the ADC3 PLIB Driver
The ADC3 Module driver generates an API interface to support the features of the peripheral. Some use cases of are linked below. Click the links to view the code snippets associated with each.
- 4.1.3.1.7.1 Melody ADCCC Use Case 1 - Configure ADC Basic Mode and Data Streamer: Single-Ended ADC sample, with output plotted using the Data Streamer protocol on the Data Visualizer.
- 4.1.3.1.7.2 Melody ADCCC Use Case 2: ADCCC in Burst_Average_mode with DataStreamer of ADC Result: The ADC takes and averages 16 samples, to mitigate noise. The averaged ADC result is sent to DataStreamer, for display in Data Visualizer. After each ADC conversion is completed and sent to DataStreamer the onboard LED is toggled.
- 4.1.3.1.7.3 Melody ADCCC Use Case 3 - Leveraging ADCCC Functionality to Mitigate Periodic Noise and Displaying using DataStreamer.: This Use Case uses the Signal and Noise Generator board, along with the Curiosity Nano Base and Q71 Curiosity Nano development board. The ADC is configured to use the System Clock prescaled as its base clock. The user can then tune away from periodic noise by modifying the number of samples accumulated and thus the acquisition count/time. The filtered ADC result is sent to DataStreamer, for display in Data Visualizer. After each ADC conversion is completed and sent to DataStreamer the onboard LED is toggled.
- 4.1.3.1.7.4 Melody ADCCC Use Case 4 - Window Detection: Create an ADC window detector with upper and lower thresholds. Lower bound 1.0V and upper bound 2.0V. Take a single ADC read and compare to window thresholds. If outside of user defined window (above 2.0V or below 1.0V), turn on LED.
- 4.1.3.1.7.5 Melody ADCCC Use Case 5 - Using FVR as ADC voltage reference to scale ADC reads: This is useful when working with a small single-ended analog signal that does not use full range from GND to VDD. This Use Case narrows the ADC window of interest using FVR (Fixed Voltage Reference) predefined voltage references: 1.024V, 2.048V, 4.096V.
- 4.1.3.1.7.6 Melody ADCCC Use Case 6 - Using DAC as ADC voltage reference: This is useful when working with a small analog signal that does not range from GND to VDD. This Use Case narrows the range of the ADC window using the DAC as a reference, which is useful when one of the FVR internal references (see ADCCC Use Case 5) is not close enough to the ADC range of interest. The user can set a specific reference voltage in order to maximize the ADC resolution over the ADC input range of interest.
4.1.3.1.5 Module Documentation
ADC
This is the generated header file for the ADC driver.
Module description
This is the generated header file for the ADC driver.
Typedefs
typedef uint16_t adc_result_t
Displays the result of the Analog-to-Digital (A/D) conversion.
Definitions
#define ADC_Initialize ADC_Initialize
Defines the Custom Name for the ADC_Initialize API.
#define ADC_SelectContext ADC_SelectContext
Defines the Custom Name for the ADC_SelectContext API.
#define ADC_EnableChannelScan ADC_EnableChannelScan
Defines the Custom Name for the ADC_EnableChannelScan API.
#define ADC_DisableChannelScan ADC_DisableChannelScan
Defines the Custom Name for the ADC_DisableChannelScan API.
#define ADC_EnableChannelSequencer ADC_EnableChannelSequencer
Defines the Custom Name for the ADC_EnableChannelSequencer API.
#define ADC_DisableChannelSequencer ADC_DisableChannelSequencer
Defines the Custom Name for the ADC_DisableChannelSequencer API.
#define ADC_SetChannel ADC_SetChannel
Defines the Custom Name for the ADC_SetChannel API.
#define ADC_DischargeSampleCapacitor ADC_DischargeSampleCapacitor
Defines the Custom Name for the ADC_DischargeSampleCapacitor API.
#define ADC_StartConversionOnChannel ADC_StartConversionOnChannel
Defines the Custom Name for the ADC_StartConversionOnChannel API.
#define ADC_StartConversion ADC_StartConversion
Defines the Custom Name for the ADC_StartConversion API.
#define ADC_StopConversion ADC_StopConversion
Defines the Custom Name for the ADC_StopConversion API.
#define ADC_IsConversionDone ADC_IsConversionDone
Defines the Custom Name for the ADC_IsConversionDone API.
#define ADC_GetConversionResult ADC_GetConversionResult
Defines the Custom Name for the ADC_GetConversionResult API.
#define ADC_GetSingleConversion ADC_GetSingleConversion
Defines the Custom Name for the ADC_GetSingleConversion API.
#define ADC_GetConversionStageStatus ADC_GetConversionStageStatus
Defines the Custom Name for the ADC_GetConversionStageStatus API.
#define ADC_EnableContinuousConversion ADC_EnableContinuousConversion
Defines the Custom Name for the ADC_EnableContinuousConversion API.
#define ADC_DisableContinuousConversion ADC_DisableContinuousConversion
Defines the Custom Name for the ADC_DisableContinuousConversion API.
#define ADC_SetStopOnInterrupt ADC_SetStopOnInterrupt
Defines the Custom Name for the ADC_SetStopOnInterrupt API.
#define ADC_EnableDoubleSampling ADC_EnableDoubleSampling
Defines the Custom Name for the ADC_EnableDoubleSampling API.
#define ADC_SetAcquisitionRegister ADC_SetAcquisitionRegister
Defines the Custom Name for the ADC_SetAcquisitionRegister API.
#define ADC_SetPrechargeRegister ADC_SetPrechargeRegister
Defines the Custom Name for the ADC_SetPrechargeRegister API.
#define ADC_DefineSetPoint ADC_DefineSetPoint
Defines the Custom Name for the ADC_DefineSetPoint API.
#define ADC_SetUpperThreshold ADC_SetUpperThreshold
Defines the Custom Name for the ADC_SetUpperThreshold API.
#define ADC_SetLowerThreshold ADC_SetLowerThreshold
Defines the Custom Name for the ADC_SetLowerThreshold API.
#define ADC_HasErrorCrossedUpperThreshold ADC_HasErrorCrossedUpperThreshold
Defines the Custom Name for the ADC_HasErrorCrossedUpperThreshold API.
#define ADC_HasErrorCrossedLowerThreshold ADC_HasErrorCrossedLowerThreshold
Defines the Custom Name for the ADC_HasErrorCrossedLowerThreshold API.
#define ADC_SetRepeatCount ADC_SetRepeatCount
Defines the Custom Name for the ADC_SetRepeatCount API.
#define ADC_GetCurrentCountofConversions ADC_GetCurrentCountofConversions
Defines the Custom Name for the ADC_GetCurrentCountofConversions API.
#define ADC_GetAccumulatorValue ADC_GetAccumulatorValue
Defines the Custom Name for the ADC_GetAccumulatorValue API.
#define ADC_ClearAccumulator ADC_ClearAccumulator
Defines the Custom Name for the ADC_ClearAccumulator API.
#define ADC_HasAccumulatorOverflowed ADC_HasAccumulatorOverflowed
Defines the Custom Name for the ADC_HasAccumulatorOverflowed API.
#define ADC_GetErrorCalculation ADC_GetErrorCalculation
Defines the Custom Name for the ADC_GetErrorCalculation API.
#define ADC_GetPreviousResult ADC_GetPreviousResult
Defines the Custom Name for the ADC_GetPreviousResult API.
#define ADC_GetFilterValue ADC_GetFilterValue
Defines the Custom Name for the ADC_GetFilterValue API.
#define ADC_SetADIInterruptHandler ADC_SetADIInterruptHandler
Defines the Custom Name for the ADC_SetADIInterruptHandler API.
#define ADC_SetContext1ThresholdInterruptHandler ADC_SetContext1ThresholdInterruptHandler
Defines the Custom Name for the ADC_SetContext1ThresholdInterruptHandler API.
#define ADC_SetContext2ThresholdInterruptHandler ADC_SetContext2ThresholdInterruptHandler
Defines the Custom Name for the ADC_SetContext2ThresholdInterruptHandler API.
#define ADC_SetContext3ThresholdInterruptHandler ADC_SetContext3ThresholdInterruptHandler
Defines the Custom Name for the ADC_SetContext3ThresholdInterruptHandler API.
#define ADC_SetContext4ThresholdInterruptHandler ADC_SetContext4ThresholdInterruptHandler
Defines the Custom Name for the ADC_SetContext4ThresholdInterruptHandler API.
Enumerations
enum adc_channel_t { channel_ADCG1 = 0x36, channel_OPA1IN_pos = 0x37, channel_OPA2IN_pos = 0x38, channel_DAC2 = 0x39, channel_DAC3 = 0x3a, channel_VSS = 0x3b, channel_Temp = 0x3c, channel_DAC1 = 0x3d, channel_FVR_Buffer1 = 0x3e, channel_FVR_Buffer2 = 0x3f, channel_OPA1IN0_pos = 0x82, channel_OPA1IN1_pos = 0x84, channel_OPA1IN2_pos = 0x85, channel_OPA1IN3_pos = 0x89, channel_OPA2IN0_pos = 0x4c, channel_OPA2IN1_pos = 0x41, channel_OPA2IN2_pos = 0x4b, channel_OPA2IN3_pos = 0x4a }
Contains the available ADC channels.
Functions
void ADC_Initialize (void)
Initializes the ADC module. This routine must be called before other ADC APIs.
void ADC_SelectContext (adc_context_t context)
Selects an ADC context to perform read/write operations on context-specific registers.
void ADC_EnableChannelScan (adc_context_t context)
Includes a channel context in the scan sequence. Select the correct context using ADC_SelectContext before calling this API.
void ADC_DisableChannelScan (adc_context_t context)
Excludes a channel context from the scan sequence. Select the correct context using ADC_SelectContext before calling this API.
void ADC_EnableChannelSequencer (void)
Enables the ADC channel sequencer. Initialize the ADC module using ADC_Initialize before calling this API.
void ADC_DisableChannelSequencer (void)
Disables the ADC channel sequencer. Initialize the ADC module using ADC_Initialize before calling this API.
void ADC_SetChannel (adc_channel_t channel)
Sets the positive channel as per user selection.
void ADC_DischargeSampleCapacitor (void)
Discharges the input sample capacitor for the selected context by setting the channel to AVss. Use ADC_SelectContext to select the correct ADC context before calling this API.
void ADC_StartConversionOnChannel (adc_channel_t channel)
Starts the A/D conversion on the selected channel.
void ADC_StartConversion (void)
Starts the A/D conversion on the selected channel.
void ADC_StopConversion (void)
Stops the ongoing A/D conversion.
bool ADC_IsConversionDone (void)
Checks if the ongoing A/D conversion is complete.
adc_result_t ADC_GetConversionResult (void)
Retrieves the result of the latest A/D conversion.
adc_result_t ADC_GetSingleConversion (adc_channel_t channel)
Retrieves the result of a single A/D conversion on the given channel in Single-Ended mode.
uint8_t ADC_GetConversionStageStatus (void)
Retrieves the ADC module cycle multi-stage status.
void ADC_EnableContinuousConversion (void)
Enables continuous conversion.
void ADC_DisableContinuousConversion (void)
Disables continuous conversion.
void ADC_SetStopOnInterrupt (void)
Enables the Stop-on-Interrupt bit.
void ADC_EnableDoubleSampling (void)
Enables the Double-Sample Enable bit.
void ADC_SetAcquisitionRegister (uint16_t acquisitionValue)
Loads the ADC Acquisition Time Control (ADACQ) register with the specified value.
void ADC_SetPrechargeRegister (uint16_t prechargeTime)
Loads the ADC Precharge Time Control (ADPRE) register with the specified value.
void ADC_DefineSetPoint (uint16_t setPoint)
Sets the value of the ADC Threshold Setpoint (ADSTPT) register.
void ADC_SetUpperThreshold (uint16_t upperThreshold)
Sets the value of the ADC Upper Threshold (ADUTH) register.
void ADC_SetLowerThreshold (uint16_t lowerThreshold)
Sets the value of the ADC Lower Threshold (ADLTH) register.
bool ADC_HasErrorCrossedUpperThreshold (void)
Determines if the ADC error is higher than the upper threshold.
bool ADC_HasErrorCrossedLowerThreshold (void)
Determines if the ADC error is less than the lower threshold.
void ADC_SetRepeatCount (uint8_t repeatCount)
Loads the ADC Repeat Counter (ADCNT) with the specified value.
uint8_t ADC_GetCurrentCountofConversions (void)
Retrieves the current value of the ADC Repeat Counter (ADCNT) register.
uint24_t ADC_GetAccumulatorValue (void)
Retrieves a 24-bit value from the ADC accumulator.
void ADC_ClearAccumulator (void)
Clears the accumulator.
bool ADC_HasAccumulatorOverflowed (void)
Determines if the ADC accumulator has overflowed.
int16_t ADC_GetErrorCalculation (void)
Retrieves the value of the ADC Setpoint Error (ADERR) register.
uint16_t ADC_GetPreviousResult (void)
Retrieves the value of the ADC Previous Result (ADPREV) register.
uint16_t ADC_GetFilterValue (void)
Retrieves the value of the ADC Filter (ADFLTR) register.
void ADC_SetADIInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Interrupt Service Routine (ISR).
void ADC_ADI_ISR (void)
Implements the ADC Interrupt (ADI) ISR for the interrupt-driven implementations.
void ADC_SetContext1ThresholdInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Context 1 (ADCH1) interrupt.
void ADC_ADCH1_ISR (void)
Implements the ADCH1 ISR for the interrupt-driven implementations.
void ADC_SetContext2ThresholdInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Context 2 (ADCH2) interrupt.
void ADC_ADCH2_ISR (void)
Implements the ADCH2 ISR for the interrupt-driven implementations.
void ADC_SetContext3ThresholdInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Context 3 (ADCH3) interrupt.
void ADC_ADCH3_ISR (void)
Implements the ADCH3 ISR for the interrupt-driven implementations.
void ADC_SetContext4ThresholdInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Context 4 (ADCH4) interrupt.
void ADC_ADCH4_ISR (void)
Implements the ADCH4 ISR for the interrupt-driven implementations.
Definition Documentation
ADC_ClearAccumulator
#define ADC_ClearAccumulator ADC_ClearAccumulator
Defines the Custom Name for the ADC_ClearAccumulator API.
ADC_DefineSetPoint
#define ADC_DefineSetPoint ADC_DefineSetPoint
Defines the Custom Name for the ADC_DefineSetPoint API.
ADC_DisableChannelScan
#define ADC_DisableChannelScan ADC_DisableChannelScan
Defines the Custom Name for the ADC_DisableChannelScan API.
ADC_DisableChannelSequencer
#define ADC_DisableChannelSequencer ADC_DisableChannelSequencer
Defines the Custom Name for the ADC_DisableChannelSequencer API.
ADC_DisableContinuousConversion
#define ADC_DisableContinuousConversion ADC_DisableContinuousConversion
Defines the Custom Name for the ADC_DisableContinuousConversion API.
ADC_DischargeSampleCapacitor
#define ADC_DischargeSampleCapacitor ADC_DischargeSampleCapacitor
Defines the Custom Name for the ADC_DischargeSampleCapacitor API.
ADC_EnableChannelScan
#define ADC_EnableChannelScan ADC_EnableChannelScan
Defines the Custom Name for the ADC_EnableChannelScan API.
ADC_EnableChannelSequencer
#define ADC_EnableChannelSequencer ADC_EnableChannelSequencer
Defines the Custom Name for the ADC_EnableChannelSequencer API.
ADC_EnableContinuousConversion
#define ADC_EnableContinuousConversion ADC_EnableContinuousConversion
Defines the Custom Name for the ADC_EnableContinuousConversion API.
ADC_EnableDoubleSampling
#define ADC_EnableDoubleSampling ADC_EnableDoubleSampling
Defines the Custom Name for the ADC_EnableDoubleSampling API.
ADC_GetAccumulatorValue
#define ADC_GetAccumulatorValue ADC_GetAccumulatorValue
Defines the Custom Name for the ADC_GetAccumulatorValue API.
ADC_GetConversionResult
#define ADC_GetConversionResult ADC_GetConversionResult
Defines the Custom Name for the ADC_GetConversionResult API.
ADC_GetConversionStageStatus
#define ADC_GetConversionStageStatus ADC_GetConversionStageStatus
Defines the Custom Name for the ADC_GetConversionStageStatus API.
ADC_GetCurrentCountofConversions
#define ADC_GetCurrentCountofConversions ADC_GetCurrentCountofConversions
Defines the Custom Name for the ADC_GetCurrentCountofConversions API.
ADC_GetErrorCalculation
#define ADC_GetErrorCalculation ADC_GetErrorCalculation
Defines the Custom Name for the ADC_GetErrorCalculation API.
ADC_GetFilterValue
#define ADC_GetFilterValue ADC_GetFilterValue
Defines the Custom Name for the ADC_GetFilterValue API.
ADC_GetPreviousResult
#define ADC_GetPreviousResult ADC_GetPreviousResult
Defines the Custom Name for the ADC_GetPreviousResult API.
ADC_GetSingleConversion
#define ADC_GetSingleConversion ADC_GetSingleConversion
Defines the Custom Name for the ADC_GetSingleConversion API.
ADC_HasAccumulatorOverflowed
#define ADC_HasAccumulatorOverflowed ADC_HasAccumulatorOverflowed
Defines the Custom Name for the ADC_HasAccumulatorOverflowed API.
ADC_HasErrorCrossedLowerThreshold
#define ADC_HasErrorCrossedLowerThreshold ADC_HasErrorCrossedLowerThreshold
Defines the Custom Name for the ADC_HasErrorCrossedLowerThreshold API.
ADC_HasErrorCrossedUpperThreshold
#define ADC_HasErrorCrossedUpperThreshold ADC_HasErrorCrossedUpperThreshold
Defines the Custom Name for the ADC_HasErrorCrossedUpperThreshold API.
ADC_Initialize
#define ADC_Initialize ADC_Initialize
Defines the Custom Name for the ADC_Initialize API.
ADC_IsConversionDone
#define ADC_IsConversionDone ADC_IsConversionDone
Defines the Custom Name for the ADC_IsConversionDone API.
ADC_SelectContext
#define ADC_SelectContext ADC_SelectContext
Defines the Custom Name for the ADC_SelectContext API.
ADC_SetAcquisitionRegister
#define ADC_SetAcquisitionRegister ADC_SetAcquisitionRegister
Defines the Custom Name for the ADC_SetAcquisitionRegister API.
ADC_SetADIInterruptHandler
#define ADC_SetADIInterruptHandler ADC_SetADIInterruptHandler
Defines the Custom Name for the ADC_SetADIInterruptHandler API.
ADC_SetChannel
#define ADC_SetChannel ADC_SetChannel
Defines the Custom Name for the ADC_SetChannel API.
ADC_SetContext1ThresholdInterruptHandler
#define ADC_SetContext1ThresholdInterruptHandler ADC_SetContext1ThresholdInterruptHandler
Defines the Custom Name for the ADC_SetContext1ThresholdInterruptHandler API.
ADC_SetContext2ThresholdInterruptHandler
#define ADC_SetContext2ThresholdInterruptHandler ADC_SetContext2ThresholdInterruptHandler
Defines the Custom Name for the ADC_SetContext2ThresholdInterruptHandler API.
ADC_SetContext3ThresholdInterruptHandler
#define ADC_SetContext3ThresholdInterruptHandler ADC_SetContext3ThresholdInterruptHandler
Defines the Custom Name for the ADC_SetContext3ThresholdInterruptHandler API.
ADC_SetContext4ThresholdInterruptHandler
#define ADC_SetContext4ThresholdInterruptHandler ADC_SetContext4ThresholdInterruptHandler
Defines the Custom Name for the ADC_SetContext4ThresholdInterruptHandler API.
ADC_SetLowerThreshold
#define ADC_SetLowerThreshold ADC_SetLowerThreshold
Defines the Custom Name for the ADC_SetLowerThreshold API.
ADC_SetPrechargeRegister
#define ADC_SetPrechargeRegister ADC_SetPrechargeRegister
Defines the Custom Name for the ADC_SetPrechargeRegister API.
ADC_SetRepeatCount
#define ADC_SetRepeatCount ADC_SetRepeatCount
Defines the Custom Name for the ADC_SetRepeatCount API.
ADC_SetStopOnInterrupt
#define ADC_SetStopOnInterrupt ADC_SetStopOnInterrupt
Defines the Custom Name for the ADC_SetStopOnInterrupt API.
ADC_SetUpperThreshold
#define ADC_SetUpperThreshold ADC_SetUpperThreshold
Defines the Custom Name for the ADC_SetUpperThreshold API.
ADC_StartConversion
#define ADC_StartConversion ADC_StartConversion
Defines the Custom Name for the ADC_StartConversion API.
ADC_StartConversionOnChannel
#define ADC_StartConversionOnChannel ADC_StartConversionOnChannel
Defines the Custom Name for the ADC_StartConversionOnChannel API.
ADC_StopConversion
#define ADC_StopConversion ADC_StopConversion
Defines the Custom Name for the ADC_StopConversion API.
Typedef Documentation
adc_result_t
Displays the result of the Analog-to-Digital (A/D) conversion.
Function Documentation
ADC_ADCH1_ISR()
void ADC_ADCH1_ISR (void )
Implements the ADCH1 ISR for the interrupt-driven implementations.
None. |
None. |
ADC_ADCH2_ISR()
void ADC_ADCH2_ISR (void )
Implements the ADCH2 ISR for the interrupt-driven implementations.
None. |
None. |
ADC_ADCH3_ISR()
void ADC_ADCH3_ISR (void )
Implements the ADCH3 ISR for the interrupt-driven implementations.
None. |
None. |
ADC_ADCH4_ISR()
void ADC_ADCH4_ISR (void )
Implements the ADCH4 ISR for the interrupt-driven implementations.
None. |
None. |
ADC_ADI_ISR()
void ADC_ADI_ISR (void )
Implements the ADC Interrupt (ADI) ISR for the interrupt-driven implementations.
None. |
None. |
ADC_ClearAccumulator()
void ADC_ClearAccumulator (void )[inline]
Clears the accumulator.
None. |
None. |
ADC_DefineSetPoint()
void ADC_DefineSetPoint (uint16_t setPoint)
Sets the value of the ADC Threshold Setpoint (ADSTPT) register.
setPoint |
- 16-bit value for the ADC Threshold Setpoint register. |
None. |
ADC_DisableChannelScan()
void ADC_DisableChannelScan (adc_context_t context)
Excludes a channel context from the scan sequence. Select the correct context using ADC_SelectContext before calling this API.
context |
- Context which needs to be excluded from the scan. Refer to the adc_context_t enum for the list of available contexts. |
None. |
ADC_DisableChannelSequencer()
void ADC_DisableChannelSequencer (void )[inline]
Disables the ADC channel sequencer. Initialize the ADC module using ADC_Initialize before calling this API.
None. |
None. |
ADC_DisableContinuousConversion()
void ADC_DisableContinuousConversion (void )[inline]
Disables continuous conversion.
None. |
None. |
ADC_DischargeSampleCapacitor()
void ADC_DischargeSampleCapacitor (void )[inline]
Discharges the input sample capacitor for the selected context by setting the channel to AVss. Use ADC_SelectContext to select the correct ADC context before calling this API.
None. |
None. |
ADC_EnableChannelScan()
void ADC_EnableChannelScan (adc_context_t context)
Includes a channel context in the scan sequence. Select the correct context using ADC_SelectContext before calling this API.
context |
- Context which needs to be included in the scan. Refer to the adc_context_t enum for the list of available contexts. |
None. |
ADC_EnableChannelSequencer()
void ADC_EnableChannelSequencer (void )[inline]
Enables the ADC channel sequencer. Initialize the ADC module using ADC_Initialize before calling this API.
None. |
None. |
ADC_EnableContinuousConversion()
void ADC_EnableContinuousConversion (void )[inline]
Enables continuous conversion.
None. |
None. |
ADC_EnableDoubleSampling()
void ADC_EnableDoubleSampling (void )[inline]
Enables the Double-Sample Enable bit.
None. |
None. |
ADC_GetAccumulatorValue()
uint24_t ADC_GetAccumulatorValue (void )[inline]
Retrieves a 24-bit value from the ADC accumulator.
None. |
Value of the ADC accumulator. |
ADC_GetConversionResult()
adc_result_t ADC_GetConversionResult (void )[inline]
Retrieves the result of the latest A/D conversion.
Call ADC_StartConversion() before calling this function and check the completion status using the ADC_IsConversionDone() API. |
None. |
The result of the A/D conversion. Refer to adc_result_t. |
ADC_GetConversionStageStatus()
uint8_t ADC_GetConversionStageStatus (void )[inline]
Retrieves the ADC module cycle multi-stage status.
Call ADC_StartConversion() before calling this function. |
None. |
Contents of the ADC Status (ADSTAT) register. |
ADC_GetCurrentCountofConversions()
uint8_t ADC_GetCurrentCountofConversions (void )[inline]
Retrieves the current value of the ADC Repeat Counter (ADCNT) register.
Call ADC_StartConversion() before calling this function. |
None. |
Current value of the ADC Repeat Counter register. |
ADC_GetErrorCalculation()
int16_t ADC_GetErrorCalculation (void )[inline]
Retrieves the value of the ADC Setpoint Error (ADERR) register.
Call ADC_StartConversion() before calling this function. |
None. |
16-bit value obtained from the high byte ADERR (ADERRH) and low byte ADERR (ADERRL) registers. |
ADC_GetFilterValue()
uint16_t ADC_GetFilterValue (void )[inline]
Retrieves the value of the ADC Filter (ADFLTR) register.
None. |
16-bit value obtained from the high byte ADFLTR (ADFLTRH) and low byte ADFLTR (ADFLTRL) registers. |
ADC_GetPreviousResult()
uint16_t ADC_GetPreviousResult (void )[inline]
Retrieves the value of the ADC Previous Result (ADPREV) register.
Call ADC_StartConversion() before calling this function. |
None. |
16-bit value obtained from the high byte ADPREV (ADPREVH) and low byte ADPREV (ADPREVL) registers. |
ADC_GetSingleConversion()
adc_result_t ADC_GetSingleConversion (adc_channel_t channel)
Retrieves the result of a single A/D conversion on the given channel in Single-Ended mode.
Call ADC_DisableContinuousConversion() before calling this function. |
channel |
- Analog channel number on which the A/D conversion has to be applied. Refer to adc_channel_t for the available channels. |
The result of the A/D conversion. Refer to adc_result_t. |
ADC_HasAccumulatorOverflowed()
bool ADC_HasAccumulatorOverflowed (void )[inline]
Determines if the ADC accumulator has overflowed.
Call ADC_StartConversion() before calling this function. |
None. |
True |
- ADC accumulator has overflowed. |
False |
- ADC accumulator has not overflowed. |
ADC_HasErrorCrossedLowerThreshold()
bool ADC_HasErrorCrossedLowerThreshold (void )[inline]
Determines if the ADC error is less than the lower threshold.
Call ADC_StartConversion() before calling this function. |
None. |
True |
- ADC error is less than the lower threshold. |
False |
- ADC error is higher than the lower threshold. |
ADC_HasErrorCrossedUpperThreshold()
bool ADC_HasErrorCrossedUpperThreshold (void )[inline]
Determines if the ADC error is higher than the upper threshold.
Call ADC_StartConversion() before calling this function. |
None. |
True |
- ADC error has crossed the upper threshold. |
False |
- ADC error has not crossed the upper threshold. |
ADC_Initialize()
void ADC_Initialize (void )
Initializes the ADC module. This routine must be called before other ADC APIs.
None. |
None. |
ADC_IsConversionDone()
bool ADC_IsConversionDone (void )[inline]
Checks if the ongoing A/D conversion is complete.
Call ADC_StartConversion() before calling this function. |
None. |
True |
- Conversion is complete. |
False |
- Conversion is ongoing. |
ADC_SelectContext()
void ADC_SelectContext (adc_context_t context)[inline]
Selects an ADC context to perform read/write operations on context-specific registers.
context |
- Context to be selected. Refer to the adc_context_t enum for the list of available contexts. |
None. |
ADC_SetAcquisitionRegister()
void ADC_SetAcquisitionRegister (uint16_t acquisitionValue)
Loads the ADC Acquisition Time Control (ADACQ) register with the specified value.
acquisitionValue |
- Value to be loaded in the ADC Acquisition Time Control register. |
None. |
ADC_SetADIInterruptHandler()
void ADC_SetADIInterruptHandler (void(*)(void) InterruptHandler)
Sets the callback for the ADC Interrupt Service Routine (ISR).
InterruptHandler |
- Callback function to be called. |
None. |
ADC_SetChannel()
void ADC_SetChannel (adc_channel_t channel)[inline]
Sets the positive channel as per user selection.
Initialize the ADC with ADC_Initialize() before calling this API. |
channel |
- Desired analog channel. Refer to the adc_channel_t enum for the list of available analog channels. |
None. |
ADC_SetContext1ThresholdInterruptHandler()
void ADC_SetContext1ThresholdInterruptHandler (void(*)(void) InterruptHandler)
Sets the callback for the ADC Context 1 (ADCH1) interrupt.
InterruptHandler |
- Callback function to be called. |
None. |
ADC_SetContext2ThresholdInterruptHandler()
void ADC_SetContext2ThresholdInterruptHandler (void(*)(void) InterruptHandler)
Sets the callback for the ADC Context 2 (ADCH2) interrupt.
InterruptHandler |
- Callback function to be called. |
None. |
ADC_SetContext3ThresholdInterruptHandler()
void ADC_SetContext3ThresholdInterruptHandler (void(*)(void) InterruptHandler)
Sets the callback for the ADC Context 3 (ADCH3) interrupt.
InterruptHandler |
- Callback function to be called. |
None. |
ADC_SetContext4ThresholdInterruptHandler()
void ADC_SetContext4ThresholdInterruptHandler (void(*)(void) InterruptHandler)
Sets the callback for the ADC Context 4 (ADCH4) interrupt.
InterruptHandler |
- Callback function to be called. |
None. |
ADC_SetLowerThreshold()
void ADC_SetLowerThreshold (uint16_t lowerThreshold)
Sets the value of the ADC Lower Threshold (ADLTH) register.
lowerThreshold |
- 16-bit value for the ADC Lower Threshold register. |
None. |
ADC_SetPrechargeRegister()
void ADC_SetPrechargeRegister (uint16_t prechargeTime)
Loads the ADC Precharge Time Control (ADPRE) register with the specified value.
prechargeTime |
- Value to be loaded in the ADC Precharge Time Control register. |
None. |
ADC_SetRepeatCount()
void ADC_SetRepeatCount (uint8_t repeatCount)[inline]
Loads the ADC Repeat Counter (ADCNT) with the specified value.
repeatCount |
- Value to be loaded to the ADC Repeat Counter register. |
None. |
ADC_SetStopOnInterrupt()
void ADC_SetStopOnInterrupt (void )[inline]
Enables the Stop-on-Interrupt bit.
Call ADC_EnableContinuousConversion() before calling this function. |
None. |
None. |
ADC_SetUpperThreshold()
void ADC_SetUpperThreshold (uint16_t upperThreshold)
Sets the value of the ADC Upper Threshold (ADUTH) register.
upperThreshold |
- 16-bit value for the ADC Upper Threshold register. |
None. |
ADC_StartConversion()
void ADC_StartConversion (void )[inline]
Starts the A/D conversion on the selected channel.
None. |
None. |
ADC_StartConversionOnChannel()
void ADC_StartConversionOnChannel (adc_channel_t channel)
Starts the A/D conversion on the selected channel.
channel |
- Analog channel number on which the A/D conversion has to be applied. Refer to adc_channel_t for the list of available channels. |
None. |
ADC_StopConversion()
void ADC_StopConversion (void )[inline]
Stops the ongoing A/D conversion.
Call ADC_StartConversion() before calling this function. |
None. |
None. |
Enumeration Type Documentation
adc_channel_t
enum adc_channel_t
Contains the available ADC channels.
channel_ADCG1 | |
channel_OPA1IN_pos | |
channel_OPA2IN_pos | |
channel_DAC2 | |
channel_DAC3 | |
channel_VSS | |
channel_Temp | |
channel_DAC1 | |
channel_FVR_Buffer1 | |
channel_FVR_Buffer2 | |
channel_OPA1IN0_pos | |
channel_OPA1IN1_pos | |
channel_OPA1IN2_pos | |
channel_OPA1IN3_pos | |
channel_OPA2IN0_pos | |
channel_OPA2IN1_pos | |
channel_OPA2IN2_pos | |
channel_OPA2IN3_pos |
4.1.3.1.6 File Documentation
source/adc.c File Reference
This is the generated driver implementation file for the ADC driver.
#include <xc.h> #include "../adc.h"
Functions
static void ADC_DefaultADI_ISR (void)
static void ADC_DefaultContext1Threshold_ISR (void)
static void ADC_DefaultContext2Threshold_ISR (void)
static void ADC_DefaultContext3Threshold_ISR (void)
static void ADC_DefaultContext4Threshold_ISR (void)
void ADC_Initialize (void)
Initializes the ADC module. This routine must be called before other ADC APIs.
void ADC_SelectContext (adc_context_t context)
Selects an ADC context to perform read/write operations on context-specific registers.
void ADC_EnableChannelScan (adc_context_t context)
Includes a channel context in the scan sequence. Select the correct context using ADC_SelectContext before calling this API.
void ADC_DisableChannelScan (adc_context_t context)
Excludes a channel context from the scan sequence. Select the correct context using ADC_SelectContext before calling this API.
void ADC_EnableChannelSequencer (void)
Enables the ADC channel sequencer. Initialize the ADC module using ADC_Initialize before calling this API.
void ADC_DisableChannelSequencer (void)
Disables the ADC channel sequencer. Initialize the ADC module using ADC_Initialize before calling this API.
void ADC_SetChannel (adc_channel_t channel)
Sets the positive channel as per user selection.
void ADC_StartConversionOnChannel (adc_channel_t channel)
Starts the A/D conversion on the selected channel.
void ADC_DischargeSampleCapacitor (void)
Discharges the input sample capacitor for the selected context by setting the channel to AVss. Use ADC_SelectContext to select the correct ADC context before calling this API.
void ADC_StartConversion (void)
Starts the A/D conversion on the selected channel.
void ADC_StopConversion (void)
Stops the ongoing A/D conversion.
bool ADC_IsConversionDone (void)
Checks if the ongoing A/D conversion is complete.
adc_result_t ADC_GetConversionResult (void)
Retrieves the result of the latest A/D conversion.
adc_result_t ADC_GetSingleConversion (adc_channel_t channel)
Retrieves the result of a single A/D conversion on the given channel in Single-Ended mode.
uint8_t ADC_GetConversionStageStatus (void)
Retrieves the ADC module cycle multi-stage status.
void ADC_EnableContinuousConversion (void)
Enables continuous conversion.
void ADC_DisableContinuousConversion (void)
Disables continuous conversion.
void ADC_SetStopOnInterrupt (void)
Enables the Stop-on-Interrupt bit.
void ADC_EnableDoubleSampling (void)
Enables the Double-Sample Enable bit.
void ADC_SetAcquisitionRegister (uint16_t acquisitionValue)
Loads the ADC Acquisition Time Control (ADACQ) register with the specified value.
void ADC_SetPrechargeRegister (uint16_t prechargeTime)
Loads the ADC Precharge Time Control (ADPRE) register with the specified value.
void ADC_DefineSetPoint (uint16_t setPoint)
Sets the value of the ADC Threshold Setpoint (ADSTPT) register.
void ADC_SetUpperThreshold (uint16_t upperThreshold)
Sets the value of the ADC Upper Threshold (ADUTH) register.
void ADC_SetLowerThreshold (uint16_t lowerThreshold)
Sets the value of the ADC Lower Threshold (ADLTH) register.
bool ADC_HasErrorCrossedUpperThreshold (void)
Determines if the ADC error is higher than the upper threshold.
bool ADC_HasErrorCrossedLowerThreshold (void)
Determines if the ADC error is less than the lower threshold.
void ADC_SetRepeatCount (uint8_t repeatCount)
Loads the ADC Repeat Counter (ADCNT) with the specified value.
uint8_t ADC_GetCurrentCountofConversions (void)
Retrieves the current value of the ADC Repeat Counter (ADCNT) register.
uint24_t ADC_GetAccumulatorValue (void)
Retrieves a 24-bit value from the ADC accumulator.
void ADC_ClearAccumulator (void)
Clears the accumulator.
bool ADC_HasAccumulatorOverflowed (void)
Determines if the ADC accumulator has overflowed.
int16_t ADC_GetErrorCalculation (void)
Retrieves the value of the ADC Setpoint Error (ADERR) register.
uint16_t ADC_GetPreviousResult (void)
Retrieves the value of the ADC Previous Result (ADPREV) register.
uint16_t ADC_GetFilterValue (void)
Retrieves the value of the ADC Filter (ADFLTR) register.
void ADC_ADI_ISR (void)
Implements the ADC Interrupt (ADI) ISR for the interrupt-driven implementations.
void ADC_SetADIInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Interrupt Service Routine (ISR).
void ADC_ADCH1_ISR (void)
Implements the ADCH1 ISR for the interrupt-driven implementations.
void ADC_SetContext1ThresholdInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Context 1 (ADCH1) interrupt.
void ADC_ADCH2_ISR (void)
Implements the ADCH2 ISR for the interrupt-driven implementations.
void ADC_SetContext2ThresholdInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Context 2 (ADCH2) interrupt.
void ADC_ADCH3_ISR (void)
Implements the ADCH3 ISR for the interrupt-driven implementations.
void ADC_SetContext3ThresholdInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Context 3 (ADCH3) interrupt.
void ADC_ADCH4_ISR (void)
Implements the ADCH4 ISR for the interrupt-driven implementations.
void ADC_SetContext4ThresholdInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Context 4 (ADCH4) interrupt.
Variables
static void(* ADC_ConversionCompleteHandler )(void)
static void(* ADC_Context1ThresholdHandler )(void)
static void(* ADC_Context2ThresholdHandler )(void)
static void(* ADC_Context3ThresholdHandler )(void)
static void(* ADC_Context4ThresholdHandler )(void)
Detailed Description
This is the generated driver implementation file for the ADC driver.
ADC Generated Driver File
Function Documentation
ADC_DefaultADI_ISR()
static void ADC_DefaultADI_ISR (void )[static]
ADC_DefaultContext1Threshold_ISR()
static void ADC_DefaultContext1Threshold_ISR (void )[static]
ADC_DefaultContext2Threshold_ISR()
static void ADC_DefaultContext2Threshold_ISR (void )[static]
ADC_DefaultContext3Threshold_ISR()
static void ADC_DefaultContext3Threshold_ISR (void )[static]
ADC_DefaultContext4Threshold_ISR()
static void ADC_DefaultContext4Threshold_ISR (void )[static]
Variable Documentation
ADC_Context1ThresholdHandler
void(* ADC_Context1ThresholdHandler) (void)[static]
ADC_Context2ThresholdHandler
void(* ADC_Context2ThresholdHandler) (void)[static]
ADC_Context3ThresholdHandler
void(* ADC_Context3ThresholdHandler) (void)[static]
ADC_Context4ThresholdHandler
void(* ADC_Context4ThresholdHandler) (void)[static]
ADC_ConversionCompleteHandler
void(* ADC_ConversionCompleteHandler) (void)[static]
Section: Included Files
source/adc.h File Reference
#include <stdint.h> #include <stdbool.h>
Functions
void ADC_Initialize (void)
Initializes the ADC module. This routine must be called before other ADC APIs.
void ADC_SelectContext (adc_context_t context)
Selects an ADC context to perform read/write operations on context-specific registers.
void ADC_EnableChannelScan (adc_context_t context)
Includes a channel context in the scan sequence. Select the correct context using ADC_SelectContext before calling this API.
void ADC_DisableChannelScan (adc_context_t context)
Excludes a channel context from the scan sequence. Select the correct context using ADC_SelectContext before calling this API.
void ADC_EnableChannelSequencer (void)
Enables the ADC channel sequencer. Initialize the ADC module using ADC_Initialize before calling this API.
void ADC_DisableChannelSequencer (void)
Disables the ADC channel sequencer. Initialize the ADC module using ADC_Initialize before calling this API.
void ADC_SetChannel (adc_channel_t channel)
Sets the positive channel as per user selection.
void ADC_DischargeSampleCapacitor (void)
Discharges the input sample capacitor for the selected context by setting the channel to AVss. Use ADC_SelectContext to select the correct ADC context before calling this API.
void ADC_StartConversionOnChannel (adc_channel_t channel)
Starts the A/D conversion on the selected channel.
void ADC_StartConversion (void)
Starts the A/D conversion on the selected channel.
void ADC_StopConversion (void)
Stops the ongoing A/D conversion.
bool ADC_IsConversionDone (void)
Checks if the ongoing A/D conversion is complete.
adc_result_t ADC_GetConversionResult (void)
Retrieves the result of the latest A/D conversion.
adc_result_t ADC_GetSingleConversion (adc_channel_t channel)
Retrieves the result of a single A/D conversion on the given channel in Single-Ended mode.
uint8_t ADC_GetConversionStageStatus (void)
Retrieves the ADC module cycle multi-stage status.
void ADC_EnableContinuousConversion (void)
Enables continuous conversion.
void ADC_DisableContinuousConversion (void)
Disables continuous conversion.
void ADC_SetStopOnInterrupt (void)
Enables the Stop-on-Interrupt bit.
void ADC_EnableDoubleSampling (void)
Enables the Double-Sample Enable bit.
void ADC_SetAcquisitionRegister (uint16_t acquisitionValue)
Loads the ADC Acquisition Time Control (ADACQ) register with the specified value.
void ADC_SetPrechargeRegister (uint16_t prechargeTime)
Loads the ADC Precharge Time Control (ADPRE) register with the specified value.
void ADC_DefineSetPoint (uint16_t setPoint)
Sets the value of the ADC Threshold Setpoint (ADSTPT) register.
void ADC_SetUpperThreshold (uint16_t upperThreshold)
Sets the value of the ADC Upper Threshold (ADUTH) register.
void ADC_SetLowerThreshold (uint16_t lowerThreshold)
Sets the value of the ADC Lower Threshold (ADLTH) register.
bool ADC_HasErrorCrossedUpperThreshold (void)
Determines if the ADC error is higher than the upper threshold.
bool ADC_HasErrorCrossedLowerThreshold (void)
Determines if the ADC error is less than the lower threshold.
void ADC_SetRepeatCount (uint8_t repeatCount)
Loads the ADC Repeat Counter (ADCNT) with the specified value.
uint8_t ADC_GetCurrentCountofConversions (void)
Retrieves the current value of the ADC Repeat Counter (ADCNT) register.
uint24_t ADC_GetAccumulatorValue (void)
Retrieves a 24-bit value from the ADC accumulator.
void ADC_ClearAccumulator (void)
Clears the accumulator.
bool ADC_HasAccumulatorOverflowed (void)
Determines if the ADC accumulator has overflowed.
int16_t ADC_GetErrorCalculation (void)
Retrieves the value of the ADC Setpoint Error (ADERR) register.
uint16_t ADC_GetPreviousResult (void)
Retrieves the value of the ADC Previous Result (ADPREV) register.
uint16_t ADC_GetFilterValue (void)
Retrieves the value of the ADC Filter (ADFLTR) register.
void ADC_SetADIInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Interrupt Service Routine (ISR).
void ADC_ADI_ISR (void)
Implements the ADC Interrupt (ADI) ISR for the interrupt-driven implementations.
void ADC_SetContext1ThresholdInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Context 1 (ADCH1) interrupt.
void ADC_ADCH1_ISR (void)
Implements the ADCH1 ISR for the interrupt-driven implementations.
void ADC_SetContext2ThresholdInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Context 2 (ADCH2) interrupt.
void ADC_ADCH2_ISR (void)
Implements the ADCH2 ISR for the interrupt-driven implementations.
void ADC_SetContext3ThresholdInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Context 3 (ADCH3) interrupt.
void ADC_ADCH3_ISR (void)
Implements the ADCH3 ISR for the interrupt-driven implementations.
void ADC_SetContext4ThresholdInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Context 4 (ADCH4) interrupt.
void ADC_ADCH4_ISR (void)
Implements the ADCH4 ISR for the interrupt-driven implementations.
Macros
#define ADC_Initialize ADC_Initialize
Defines the Custom Name for the ADC_Initialize API.
#define ADC_SelectContext ADC_SelectContext
Defines the Custom Name for the ADC_SelectContext API.
#define ADC_EnableChannelScan ADC_EnableChannelScan
Defines the Custom Name for the ADC_EnableChannelScan API.
#define ADC_DisableChannelScan ADC_DisableChannelScan
Defines the Custom Name for the ADC_DisableChannelScan API.
#define ADC_EnableChannelSequencer ADC_EnableChannelSequencer
Defines the Custom Name for the ADC_EnableChannelSequencer API.
#define ADC_DisableChannelSequencer ADC_DisableChannelSequencer
Defines the Custom Name for the ADC_DisableChannelSequencer API.
#define ADC_SetChannel ADC_SetChannel
Defines the Custom Name for the ADC_SetChannel API.
#define ADC_DischargeSampleCapacitor ADC_DischargeSampleCapacitor
Defines the Custom Name for the ADC_DischargeSampleCapacitor API.
#define ADC_StartConversionOnChannel ADC_StartConversionOnChannel
Defines the Custom Name for the ADC_StartConversionOnChannel API.
#define ADC_StartConversion ADC_StartConversion
Defines the Custom Name for the ADC_StartConversion API.
#define ADC_StopConversion ADC_StopConversion
Defines the Custom Name for the ADC_StopConversion API.
#define ADC_IsConversionDone ADC_IsConversionDone
Defines the Custom Name for the ADC_IsConversionDone API.
#define ADC_GetConversionResult ADC_GetConversionResult
Defines the Custom Name for the ADC_GetConversionResult API.
#define ADC_GetSingleConversion ADC_GetSingleConversion
Defines the Custom Name for the ADC_GetSingleConversion API.
#define ADC_GetConversionStageStatus ADC_GetConversionStageStatus
Defines the Custom Name for the ADC_GetConversionStageStatus API.
#define ADC_EnableContinuousConversion ADC_EnableContinuousConversion
Defines the Custom Name for the ADC_EnableContinuousConversion API.
#define ADC_DisableContinuousConversion ADC_DisableContinuousConversion
Defines the Custom Name for the ADC_DisableContinuousConversion API.
#define ADC_SetStopOnInterrupt ADC_SetStopOnInterrupt
Defines the Custom Name for the ADC_SetStopOnInterrupt API.
#define ADC_EnableDoubleSampling ADC_EnableDoubleSampling
Defines the Custom Name for the ADC_EnableDoubleSampling API.
#define ADC_SetAcquisitionRegister ADC_SetAcquisitionRegister
Defines the Custom Name for the ADC_SetAcquisitionRegister API.
#define ADC_SetPrechargeRegister ADC_SetPrechargeRegister
Defines the Custom Name for the ADC_SetPrechargeRegister API.
#define ADC_DefineSetPoint ADC_DefineSetPoint
Defines the Custom Name for the ADC_DefineSetPoint API.
#define ADC_SetUpperThreshold ADC_SetUpperThreshold
Defines the Custom Name for the ADC_SetUpperThreshold API.
#define ADC_SetLowerThreshold ADC_SetLowerThreshold
Defines the Custom Name for the ADC_SetLowerThreshold API.
#define ADC_HasErrorCrossedUpperThreshold ADC_HasErrorCrossedUpperThreshold
Defines the Custom Name for the ADC_HasErrorCrossedUpperThreshold API.
#define ADC_HasErrorCrossedLowerThreshold ADC_HasErrorCrossedLowerThreshold
Defines the Custom Name for the ADC_HasErrorCrossedLowerThreshold API.
#define ADC_SetRepeatCount ADC_SetRepeatCount
Defines the Custom Name for the ADC_SetRepeatCount API.
#define ADC_GetCurrentCountofConversions ADC_GetCurrentCountofConversions
Defines the Custom Name for the ADC_GetCurrentCountofConversions API.
#define ADC_GetAccumulatorValue ADC_GetAccumulatorValue
Defines the Custom Name for the ADC_GetAccumulatorValue API.
#define ADC_ClearAccumulator ADC_ClearAccumulator
Defines the Custom Name for the ADC_ClearAccumulator API.
#define ADC_HasAccumulatorOverflowed ADC_HasAccumulatorOverflowed
Defines the Custom Name for the ADC_HasAccumulatorOverflowed API.
#define ADC_GetErrorCalculation ADC_GetErrorCalculation
Defines the Custom Name for the ADC_GetErrorCalculation API.
#define ADC_GetPreviousResult ADC_GetPreviousResult
Defines the Custom Name for the ADC_GetPreviousResult API.
#define ADC_GetFilterValue ADC_GetFilterValue
Defines the Custom Name for the ADC_GetFilterValue API.
#define ADC_SetADIInterruptHandler ADC_SetADIInterruptHandler
Defines the Custom Name for the ADC_SetADIInterruptHandler API.
#define ADC_SetContext1ThresholdInterruptHandler ADC_SetContext1ThresholdInterruptHandler
Defines the Custom Name for the ADC_SetContext1ThresholdInterruptHandler API.
#define ADC_SetContext2ThresholdInterruptHandler ADC_SetContext2ThresholdInterruptHandler
Defines the Custom Name for the ADC_SetContext2ThresholdInterruptHandler API.
#define ADC_SetContext3ThresholdInterruptHandler ADC_SetContext3ThresholdInterruptHandler
Defines the Custom Name for the ADC_SetContext3ThresholdInterruptHandler API.
#define ADC_SetContext4ThresholdInterruptHandler ADC_SetContext4ThresholdInterruptHandler
Defines the Custom Name for the ADC_SetContext4ThresholdInterruptHandler API.
Typedefs
typedef __uint24 uint24_t
typedef uint16_t adc_result_t
Displays the result of the Analog-to-Digital (A/D) conversion.
Enumerations
enum adc_channel_t { channel_ADCG1 = 0x36, channel_OPA1IN_pos = 0x37, channel_OPA2IN_pos = 0x38, channel_DAC2 = 0x39, channel_DAC3 = 0x3a, channel_VSS = 0x3b, channel_Temp = 0x3c, channel_DAC1 = 0x3d, channel_FVR_Buffer1 = 0x3e, channel_FVR_Buffer2 = 0x3f, channel_OPA1IN0_pos = 0x82, channel_OPA1IN1_pos = 0x84, channel_OPA1IN2_pos = 0x85, channel_OPA1IN3_pos = 0x89, channel_OPA2IN0_pos = 0x4c, channel_OPA2IN1_pos = 0x41, channel_OPA2IN2_pos = 0x4b, channel_OPA2IN3_pos = 0x4a }
Contains the available ADC channels.
enum adc_context_t { context_1 = 0, context_2 = 1, context_3 = 2, context_4 = 3 }
Detailed Description
ADC Generated Driver API Header File
Typedef Documentation
uint24_t
typedef __uint24 uint24_t
Enumeration Type Documentation
adc_context_t
enum adc_context_t
context_1 | |
context_2 | |
context_3 | |
context_4 |
4.1.3.1.7 Melody ADCCC Use Cases
Melody ADCCC Use Case 1 - Configure ADC Basic Mode and Data Streamer
For new users it is recommended to start with a Single-Ended ADC read to make the learning curve easier. The output will be displayed using Data Streamer.
-
Add the following drivers/libraries to the project:
-
Data Streamer
-
ADC
-
-
DataStreamer Configuration:
-
UART Dependency: UART2
-
Variable type: uint16_t
-
Variable name: adc_result
-
-
ADC Easy View Configuration:
-
Single-ended mode
-
Right-justified
-
VDD 3.3V
-
Clock Selection ADCRC
-
-
ADC Context 1 Configuration:
-
Positive Channel: ANA2
-
Positive Reference: VDD -Other:
-
Any other peripherals or pins needed for the use case.
-
-
Configure Pin Grid View:
-
PORTA Pin 2 as ANPx input
-
-
Generate the code
-
Add the code snippet(s) to the application code
-
Program the board
#include "mcc_generated_files/system/system.h"
volatile bool SEND_FRAME = false;
void DS_Frame_Update(void){
DataStreamer.adc_result = ADC_GetSingleConversion(channel_ANA2);
SEND_FRAME = true;
}
int main(void) { SYSTEM_Initialize(); DataStreamer.adc_result = 0; while(1) { DS_Frame_Update(); // write the result of an ADC read to the Data Streamer struct if(SEND_FRAME) { // if the Data Streamer frame has been updated WriteFrame(); // Write the new frame SEND_FRAME = false; // Set the boolean back to false for next time LED_Toggle(); // Toggle the LED as a visual indicator } } }
Melody ADCCC Use Case 2: ADCCC in Burst_Average_mode with DataStreamer of ADC Result
The ADC is configured to take 16 samples and then average. This is useful for mitigating random noise. The averaged ADC result is sent to DataStreamer, for display in Data Visualizer. After each ADC conversion is completed and sent to DataStreamer the onboard LED is toggled.
-
Add ADC
-
Add DataStreamer
-
Single-ended mode
-
Right-justified
-
VDD 3.3V
-
External Positive Reference Voltage: 3.3V
-
Clock Selection ADCRC ADC Context 1 Configuration:
-
Positive Channel: ANA2
-
Positive Reference: VDD
-
Operating Mode Selection: Burst_Average_mode
-
Error Calculation Mode: First derivative of filtered value
-
Upper Threshold: 3.3V
-
Lower Threshold: 0V
-
Threshold Setpoint: 0V
-
Repeat Threshold: 64
-
Accumulator Right Shift: 6
-
Acquisition Count: 1 (minimum, dependent on analog circuit output impedance)
-
Configuration Settings:
-
Variable type: uint16_t
-
Variable name: adc_result
-
-
Dependency Selector:
-
UART Dependency: UART2.
-
-
Clock Configuration: Default (1 MHz)
-
Pins: (For all pins check board schematics)
-
Pin Grid View: Select an ANx (ANA2).
-
Pin Grid View: Select pin for UART Transmit - Tx (RB4).
-
Pin Grid View: Select LED pin as output.
-
Pins: Rename Custom Name to "LED".
-
After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:
#include "mcc_generated_files/system/system.h"
volatile bool SEND_FRAME = false;
void DS_Frame_Update(void){
ADC_SetChannel(channel_ANA2);
ADC_StartConversion();
while(!(ADC_IsConversionDone()));
DataStreamer.adc_result = ADC_GetFilterValue();
SEND_FRAME = true;
}
int main(void) { SYSTEM_Initialize(); DataStreamer.adc_result = 0; while(1) { DS_Frame_Update(); if(SEND_FRAME) { WriteFrame(); SEND_FRAME = false; LED_Toggle(); } } }
Melody ADCCC Use Case 3 - Leveraging ADCCC Functionality to Mitigate Periodic Noise and Displaying using DataStreamer.
This Use Case uses the Signal and Noise Generator board, along with the Curiosity Nano Base and Q71 Curiosity Nano development board. The ADC is configured to use the System Clock prescaled as its base clock. The user can then tune away from periodic noise by modifying the number of samples accumulated and thus the acquisition count/time. The filtered ADC result is sent to DataStreamer, for display in Data Visualizer. After each ADC conversion is completed and sent to DataStreamer the onboard LED is toggled.
Set the Signal and Noise Generator to output a DC voltage, then add Periodic Noise with frequency 100kHz and amplitude 0.1Vpp.
-
Add ADC
-
Add DataStreamer
-
Single-ended mode
-
Right-justified
-
VDD 3.3V
-
External Positive Reference Voltage: 3.3V
-
Clock Selection: FOSC
-
Clock Divider: FOSC/4 ADC Context 1 Configuration:
-
Positive Channel: ANA2
-
Positive Reference: VDD
-
Operating Mode Selection: Burst_Average_mode
-
Error Calculation Mode: Filtered Value vs Setpoint
-
Upper Threshold: 32767
-
Lower Threshold: -32768
-
Threshold Setpoint: 0
-
Repeat Threshold: 64
-
Accumulator Right Shift: 6
-
Acquisition Count: 8191 (Note Acquistion Time of 2.048ms)
-
Previous Sample Input: FLTR
-
Configuration Settings:
-
Variable type: uint16_t
-
Variable name: adc_result
-
-
Dependency Selector:
-
UART Dependency: UART2.
-
-
Clock Configuration: 4 MHz
-
Clock Source: HFINTOSC
-
HF Internal Clock: 4 MHz
-
Clock Divider: 1
-
-
Configure Pin Grid View:
-
PORTA Pin 2 as ANPx input
-
Set UART Tx Pin as Output (RB4 on Q71 Curiosity Nano)
-
Select LED pin as output (RC7 on Q71 Curiosity Nano)
-
Rename Custom Name to "LED"
-
-
Generate the code
-
Add the code snippet(s) to the application code
-
Program the board
-
Open Data Visualizer, Click New Variable Streamer, Import, mcc_generated_files -> data_streamer -> data_streamer.ds. Click Next, then Finish.
#include "mcc_generated_files/system/system.h"
volatile bool SEND_FRAME = false;
uint16_t adcResult;
void DS_Frame_Update(void){
ADC_StartConversion();
while(!(ADC_IsConversionDone()));
DataStreamer.adc_result = ADC_GetFilterValue();
LED_Toggle();
SEND_FRAME = true;
}
int main(void) { SYSTEM_Initialize(); ADC_SetChannel(channel_ANA2); DataStreamer.adc_result = 0; // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global Interrupts // Use the following macros to: // Enable the Global Interrupts //INTERRUPT_GlobalInterruptEnable(); // Disable the Global Interrupts //INTERRUPT_GlobalInterruptDisable(); while(1) { // Start ADC conversion and wait for result ADC_StartConversion(); while(!(ADC_IsConversionDone())); // Return Filtered value adcResult = ADC_GetFilterValue(); DS_Frame_Update(); // write the result of an ADC read to the Data Streamer struct if(SEND_FRAME) { // if the Data Streamer frame has been updated WriteFrame(); // Write the new frame SEND_FRAME = false; // Set the boolean back to false for next time LED_Toggle(); // Toggle the LED as a visual indicator } } }Build the project and program the device. Open Data Visualizer and view the noise on the ADC signal. The Data Axis can be adjusted to zoom in on the noise.
Now change the following MCC Melody settings:
-
Acquisition Count: 130 (Note Acquistion Time of 32.5us) After changing the ADC configuration, click 'Generate' to generate the code. Build the project and program the device. Open Data Visualizer and observe the noise is mitigated on the ADC signal. The Data Axis can be adjusted to zoom in on the noise.
Melody ADCCC Use Case 4 - Window Detection
Create an ADC window detector with upper and lower thresholds. Lower bound 1.0V and upper bound 2.0V. Take a single ADC read and compare to window thresholds. If outside of user defined window (above 2.0V or below 1.0V), turn on LED.
-
Add ADC3
-
Add Data Streamer
-
Hardware Settings:
-
Set Input Configuration: Single Ended Mode
-
Set Result Format: Right Justified
-
VDD (V): 3.3
-
-
Clock Selection: ADCRC
-
Context 1 Channel Selection
-
Positive Channel Selection: ANA2 (if using Signal and Noise Generator)
-
-
Computation and Threshold Comparison:
-
Operating Mode Selection: Basic Mode
-
Error Calculation Mode: Actual Result vs Setpoint
-
Threshold Interrupt Mode: ADERR < ADLTH or ADERR > ADUTH
-
Upper Threshold (V): 2
-
Lower Threshold (V): 1
-
Threshold Setpoint (V): 0
-
-
Advanced Hardware Settings:
-
Acquisition Count: 1 (if using Signal and Noise Generator or other device with buffered output)
-
Previous Sample Input: RES
-
-
Interrupt Settings:
-
ADCH1 Interrupt Enable
-
-
Software Settings:
-
UART Dependency Selection: Select the UART that is connected to Serial/CDC port. On Q71 Curiosity Nano, this is UART2.
-
-
Data Streamer Table:
-
Add variable: uint16_t adc_result
-
Add variable: uint8_t LED_state
-
-
Clock Configuration: Default (1 MHz)
-
Configure Pin Grid View:
-
PORTA Pin 2 as ANPx input
-
Set UART Tx Pin as Output (RB4 on Q71 Curiosity Nano)
-
Select LED pin as output (RC7 on Q71 Curiosity Nano)
-
Rename Custom Name to "LED"
-
-
Generate the code
-
Add the code snippet(s) to the application code
-
Program the board
-
Open Data Visualizer, Click New Variable Streamer, Import, mcc_generated_files -> data_streamer -> data_streamer.ds. Click Next, then Finish.
#include "mcc_generated_files/system/system.h"
volatile bool SEND_FRAME = false;
uint16_t adc_result;
volatile uint8_t outside_threshold = 0;
void DS_Frame_Update(void){
ADC_StartConversion();
while(!(ADC_IsConversionDone()));
DataStreamer.adc_result = ADC_GetFilterValue();
LED_Toggle();
SEND_FRAME = true;
}
void ADC_Interrupt_Threshold_ISR(void) { // Clear the ADC interrupt flag PIR1bits.ADCH1IF = 0; // Set software flag to use in while(1) loop outside_threshold = 1; }
int main(void) { SYSTEM_Initialize(); // Point interrupt Handler to our custom ISR ADC_SetContext1ThresholdInterruptHandler(&ADC_Interrupt_Threshold_ISR); // If using Signal and Noise Generator board, use pin RA2 ADC_SetChannel(channel_ANA2); // Initialize Data Streamer ADC variable DataStreamer.adc_result = 0; // Enable the Global Interrupts INTERRUPT_GlobalInterruptEnable(); while(1) { // Check if outside user defined threshold // If so turn on LED (active LOW) { if (outside_threshold) { LED_SetLow(); // turn on LED outside_threshold = 0; // reset so it can be set again by ISR } else LED_SetHigh(); // otherwise turn off LED DS_Frame_Update(); if(SEND_FRAME) { // if the Data Streamer frame has been updated WriteFrame(); // Write the new frame SEND_FRAME = false; // Set the boolean back to false for next time } } }
Melody ADCCC Use Case 5 - Using FVR as ADC voltage reference to scale ADC reads
This is useful when working with a small single-ended analog signal that does not use full range from GND to VDD. This Use Case narrows the ADC window of interest using FVR (Fixed Voltage Reference) predefined voltage references: 1.024V, 2.048V, 4.096V
-
Add ADC3
-
Add FVR
-
Add Data Streamer
-
Software Settings:
-
UART Dependency Selection: Select the UART that is connected to Serial/CDC port. On Q71 Curiosity Nano, this is UART2.
-
-
Data Streamer Table:
-
Add variable: uint16_t adc_result
-
-
Hardware Settings:
-
Enable FVR
-
FVR Buffer Gain to ADC: 2x (note the voltage 2.048V is listed when this option is selected)
-
FVR Buffer Gain to other Peripherals: OFF
-
-
Hardware Settings:
-
Set Input Configuration: Single Ended Mode
-
Set Result Format: Right Justified
-
VDD (V): 3.3
-
-
Clock Selection: ADCRC
-
Context 1 Channel Selection
-
Positive Channel Selection: ANA2 (if using Signal and Noise Generator)
-
Positive Voltage Reference: FVR
-
-
Computation and Threshold Comparison:
-
Operating Mode Selection: Basic Mode
-
-
Advanced Hardware Settings:
-
Acquisition Count: 1 (if using Signal and Noise Generator or other device with buffered output)
-
Previous Sample Input: RES
-
-
Configure Pin Grid View:
-
PORTA Pin 2 as ANPx input
-
Set UART Tx Pin as Output (RB4 on Q71 Curiosity Nano)
-
-
Generate the code
-
Add the code snippet(s) to the application code
-
Program the board
-
Open Data Visualizer, Click New Variable Streamer, Import, mcc_generated_files -> data_streamer -> data_streamer.ds. Click Next, then Finish.
-
If using Signal and Noise Generator board, select either Sine Wave or Square Wave and adjust signal Amplitude and Offset to fit within ADCCC reference voltage.
#include "mcc_generated_files/system/system.h"
volatile bool SEND_FRAME = false;
uint16_t adc_result;
void DS_Frame_Update(void){
ADC_StartConversion();
while(!(ADC_IsConversionDone()));
DataStreamer.adc_result = ADC_GetFilterValue();
LED_Toggle();
SEND_FRAME = true;
}
int main(void) { SYSTEM_Initialize(); // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global Interrupts // Use the following macros to: // Enable the Global Interrupts //INTERRUPT_GlobalInterruptEnable(); // Disable the Global Interrupts //INTERRUPT_GlobalInterruptDisable(); while(1) { DS_Frame_Update(); if(SEND_FRAME) { // if the Data Streamer frame has been updated WriteFrame(); // Write the new frame SEND_FRAME = false; // Set the boolean back to false for next time } } }
Melody ADCCC Use Case 6 - Using DAC as ADC voltage reference
This is useful when working with a small analog signal that does not range from GND to VDD. This Use Case narrows the range of the ADC window using the DAC as a reference, which is useful when one of the FVR internal references (see ADCCC Use Case 5) is not close enough to the ADC range of interest. The user can set a specific reference voltage in order to maximize the ADC resolution over the ADC input range of interest.
-
Add ADC3
-
Add DAC
-
Add Data Streamer
-
Software Settings:
-
UART Dependency Selection: Select the UART that is connected to Serial/CDC port. On Q71 Curiosity Nano, this is UART2.
-
-
Data Streamer Table:
-
Add variable: uint16_t adc_result
-
-
Software Settings:
-
VDD: Enter microcontroller VDD. This example uses 3.3V
-
Required Ref: Enter reference voltage (between 1.8V and VDD). This example uses 1.8V
-
-
Hardware Settings:
-
DAC Enable: Turn ON
-
DAC Positive Reference Selection: VDD
-
DAC Negative Reference Selection: VSS
-
DAC Output Enable Selection: DACOUT2 Enabled and DACOUT1 Disabled (DACOUT1 on pin RA2, DACOUT2 on pin RB7)
-
-
Hardware Settings:
-
Set Input Configuration: Single Ended Mode
-
Set Result Format: Right Justified
-
VDD (V): Enter microcontroller VDD. This example uses 3.3V
-
-
Clock Selection: ADCRC
-
Context 1 Channel Selection
-
Positive Channel Selection: ANA2 (if using Signal and Noise Generator)
-
Positive Voltage Reference: External (The VREF field fill be automatically populated. If it is incorrect, check correct VDD value has been entered for both DAC and ADC.)
-
-
Computation and Threshold Comparison:
-
Operating Mode Selection: Basic Mode
-
-
Advanced Hardware Settings:
-
Acquisition Count: 1 (if using Signal and Noise Generator or other device with buffered output)
-
Previous Sample Input: RES
-
-
Configure Pin Grid View:
-
PORTA Pin 2 as ANPx input
-
Set UART Tx Pin as Output (RB4 on Q71 Curiosity Nano)
-
IMPORTANT NOTE: Place a jumper wire between DAC output (RB7) and ADC VREF+ (RA3).
-
Generate the code
-
Add the code snippet(s) to the application code
-
Program the board
-
Open Data Visualizer, Click New Variable Streamer, Import, mcc_generated_files -> data_streamer -> data_streamer.ds. Click Next, then Finish.
-
If using Signal and Noise Generator board, select either Sine Wave or Square Wave and adjust signal Amplitude and Offset to fit within ADCCC reference voltage.
#include "mcc_generated_files/system/system.h"
volatile bool SEND_FRAME = false;
void DS_Frame_Update(void){
ADC_StartConversion();
while(!(ADC_IsConversionDone()));
DataStreamer.adc_result = ADC_GetConversionResult();
SEND_FRAME = true;
}
int main(void) { SYSTEM_Initialize(); while(1) { DS_Frame_Update(); // write the result of an ADC read to the Data Streamer struct if(SEND_FRAME) { // if the Data Streamer frame has been updated WriteFrame(); // Write the new frame SEND_FRAME = false; // Set the boolean back to false for next time } } }