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.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.1.2 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.
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 Module Documentation
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(); } } }