3.1.3.1 12-bit ADCC with Context

12-bit Analog-to-Digital Converter with Computation and Context (ADC3)

3.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.

3.1.3.1.2 Supported Device Families

PIC18F-Q71PIC18F-Q8x

3.1.3.1.3 Required Header Files:

#include "mcc_generated_files/adc/adc.h"

3.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.

3.1.3.1.5 Module Documentation

Analog-to-Digital Converter (ADC)

This file provides API prototypes for the ADC driver.

Module description

This file provides API prototypes for the ADC driver.

This file provides type definitions for the ADC module.

Version: ADC Driver Version 2.0.0 ADC Package Version 2.0.0
Enumerations
Functions

Definition Documentation

ADC_BIT_CLEAR

#define ADC_BIT_CLEAR 0

ADC bit clear value.

ADC_BIT_SET

#define ADC_BIT_SET 1

ADC bit set value.

ADC_RESOLUTION

#define ADC_RESOLUTION 12

ADC resolution value.

Typedef Documentation

adc_accumulate_t

adc_accumulate_t

ADC conversion accumulator type.

adc_repeat_count_t

adc_repeat_count_t

ADC conversion repeat count type.

adc_result_t

adc_result_t

ADC conversion result type.

adc_threshold_t

adc_threshold_t

ADC conversion threshold type.

Function Documentation

ADC_AccumulatedResultGet()

adc_accumulate_t ADC_AccumulatedResultGet (void )

Retrieves the value of the accumulated conversions for the current context.

Parameters:
None.
Returns:

adc_accumulate_t - Value of ADC accumulator register

ADC_AccumulatorClear()

void ADC_AccumulatorClear (void )

Clears the accumulator for the current context.

Parameters:
None.
Returns:

None.

ADC_AcquisitionTimeSet()

void ADC_AcquisitionTimeSet (uint16_t acquisitionValue)

Sets the specified value for the ADC Acquisition Time Control (ADACQ) register for the current context.

Parameters:
acquisitionValue

Value to be loaded in the ADACQ register

Returns:

None.

ADC_AutoTriggerSourceSet()

void ADC_AutoTriggerSourceSet (adc_trigger_source_t triggerSource)

Sets the auto conversion trigger source for all ADC contexts.

Parameters:
triggerSource

Desired auto conversion trigger source. Refer to the adc_trigger_source_t for the list of available trigger sources.

Returns:

None.

ADC_BusyStatusSet()

void ADC_BusyStatusSet (bool status)

Sets the busy status of the ADC module.

Parameters:
status

True to set the ADC status to busy, false to set it to not busy.

Returns:

None.

ADC_CalculationRightShiftSet()

void ADC_CalculationRightShiftSet (uint8_t rightShiftValue)

Sets the ADC Accumulated Calculation Right Shift Select (CRS) bits for the current context.

Parameters:
rightShiftValue

Right shift value

Returns:

None.

ADC_ChannelScanDisable()

void ADC_ChannelScanDisable (adc_context_t context)

Excludes the selected channel context from the scan sequence. Select the correct context using ADC_ContextSelect before calling this API.

Parameters:
context

The desired context. Refer to adc_context_t for the available context options.

Returns:

None.

ADC_ChannelScanEnable()

void ADC_ChannelScanEnable (adc_context_t context)

Includes the selected channel context in the scan sequence. Select the correct context using ADC_ContextSelect before calling this API.

Parameters:
context

The desired context. Refer to adc_context_t for the available context options.

Returns:

None.

ADC_ChannelSelect()

void ADC_ChannelSelect (adc_channel_t channel)

Sets the channel to use for the ADC conversion in the current context.

Parameters:
channel

Desired analog channel. Refer to the adc_channel_t enum for the list of available analog channels.

Returns:

None.

ADC_ChannelSelectAndConvert()

adc_result_t ADC_ChannelSelectAndConvert (adc_channel_t channel)

Starts the conversion and retrieves the result of the single conversion on the selected channel for the current context.

Parameters:
channel

Desired analog channel. Refer to the adc_channel_t enum for the list of available analog channels.

Returns:

adc_result_t - The result of the conversion

ADC_ChannelSequencerDisable()

void ADC_ChannelSequencerDisable (void )

Disables the ADC channel sequencer.

Parameters:
None.
Returns:

None.

ADC_ChannelSequencerEnable()

void ADC_ChannelSequencerEnable (void )

Enables the ADC channel sequencer.

Parameters:
None.
Returns:

None.

ADC_ChargePumpDisable()

void ADC_ChargePumpDisable (void )

Sets the ADC Charge Pump On Control (CPON) bit to ‘0’.

Parameters:
None.
Returns:

None.

ADC_ChargePumpEnable()

void ADC_ChargePumpEnable (void )

Sets the ADC Charge Pump On Control (CPON) bit to ‘1’.

Parameters:
None.
Returns:

None.

ADC_ComputationModeSet()

void ADC_ComputationModeSet (adc_computation_mode_t computationMode)

Sets the computation mode for the current context.

Parameters:
computationMode

Desired computation mode. Refer to the adc_computation_mode_t enum for the list of available computation modes.

Returns:

None.

ADC_Context1ThresholdCallbackRegister()

void ADC_Context1ThresholdCallbackRegister (void(*)(void) callback)

Sets the callback for the ADC Context 1 (ADCH1) threshold interrupt.

Parameters:
*callback

The pointer to the function to be executed

Returns:

None.

ADC_Context1ThresholdInterruptDisable()

void ADC_Context1ThresholdInterruptDisable (void )

Sets the ADC Threshold Interrupt Enable (ADCH1IE) bit to ‘0’ for ADC Context 1.

Parameters:
None.
Returns:

None.

ADC_Context1ThresholdInterruptEnable()

void ADC_Context1ThresholdInterruptEnable (void )

Sets the ADC Threshold Interrupt Enable (ADCH1IE) bit to ‘1’ for ADC Context 1.

Parameters:
None.
Returns:

None.

ADC_Context1ThresholdInterruptFlagClear()

void ADC_Context1ThresholdInterruptFlagClear (void )

Clears the ADC Threshold Interrupt Flag (ADCH1IF) bit to ‘0’ for ADC Context 1.

Parameters:
None.
Returns:

None.

ADC_Context1ThresholdISR()

void ADC_Context1ThresholdISR (void )

Implements the ADC Context 1 Threshold Interrupt (ADCH1) service routine for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC_Context2ThresholdCallbackRegister()

void ADC_Context2ThresholdCallbackRegister (void(*)(void) callback)

Sets the callback for the ADC Context 2 (ADCH2) interrupt.

Parameters:
*callback

The pointer to the function to be executed

Returns:

None.

ADC_Context2ThresholdInterruptDisable()

void ADC_Context2ThresholdInterruptDisable (void )

Sets the ADC Threshold Interrupt Enable (ADCH2IE) bit to ‘0’ for ADC Context 2.

Parameters:
None.
Returns:

None.

ADC_Context2ThresholdInterruptEnable()

void ADC_Context2ThresholdInterruptEnable (void )

Sets the ADC Threshold Interrupt Enable (ADCH2IE) bit to ‘1’ for ADC Context 2.

Parameters:
None.
Returns:

None.

ADC_Context2ThresholdInterruptFlagClear()

void ADC_Context2ThresholdInterruptFlagClear (void )

Clears the ADC Threshold Interrupt Flag (ADCH2IF) bit to ‘0’ for ADC Context 2.

Parameters:
None.
Returns:

None.

ADC_Context2ThresholdISR()

void ADC_Context2ThresholdISR (void )

Implements the ADC Context 2 Threshold Interrupt (ADCH2) service routine for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC_Context3ThresholdCallbackRegister()

void ADC_Context3ThresholdCallbackRegister (void(*)(void) callback)

Sets the callback for the ADC Context 3 (ADCH3) interrupt.

Parameters:
*callback

The pointer to the function to be executed

Returns:

None.

ADC_Context3ThresholdInterruptDisable()

void ADC_Context3ThresholdInterruptDisable (void )

Sets the ADC Threshold Interrupt Enable (ADCH3IE) bit to ‘0’ for ADC Context 3.

Parameters:
None.
Returns:

None.

ADC_Context3ThresholdInterruptEnable()

void ADC_Context3ThresholdInterruptEnable (void )

Sets the ADC Threshold Interrupt Enable (ADCH3IE) bit to ‘1’ for ADC Context 3.

Parameters:
None.
Returns:

None.

ADC_Context3ThresholdInterruptFlagClear()

void ADC_Context3ThresholdInterruptFlagClear (void )

Clears the ADC Threshold Interrupt Flag (ADCH3IF) bit to ‘0’ for ADC Context 3.

Parameters:
None.
Returns:

None.

ADC_Context3ThresholdISR()

void ADC_Context3ThresholdISR (void )

Implements the ADC Context 3 Threshold Interrupt (ADCH3) service routine for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC_Context4ThresholdCallbackRegister()

void ADC_Context4ThresholdCallbackRegister (void(*)(void) callback)

Sets the callback for the ADC Context 4 (ADCH4) interrupt.

Parameters:
*callback

The pointer to the function to be executed

Returns:

None.

ADC_Context4ThresholdInterruptDisable()

void ADC_Context4ThresholdInterruptDisable (void )

Sets the ADC Threshold Interrupt Enable (ADCH4IE) bit to ‘0’ for ADC Context 4.

Parameters:
None.
Returns:

None.

ADC_Context4ThresholdInterruptEnable()

void ADC_Context4ThresholdInterruptEnable (void )

Sets the ADC Threshold Interrupt Enable (ADCH4IE) bit to ‘1’ for ADC Context 4.

Parameters:
None.
Returns:

None.

ADC_Context4ThresholdInterruptFlagClear()

void ADC_Context4ThresholdInterruptFlagClear (void )

Clears the ADC Threshold Interrupt Flag (ADCH4IF) bit to ‘0’ for ADC Context 4.

Parameters:
None.
Returns:

None.

ADC_Context4ThresholdISR()

void ADC_Context4ThresholdISR (void )

Implements the ADC Context 4 Threshold Interrupt (ADCH4) service routine for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC_ContextSelect()

void ADC_ContextSelect (adc_context_t context)

Selects an ADC context to perform read/write operations on context-specific registers.

Parameters:
context

Context to be selected. Refer to the adc_context_t enum for the list of available contexts.

Returns:

None.

ADC_ContinuousConversionDisable()

void ADC_ContinuousConversionDisable (void )

Sets the Continuous Operation Enable (CONT) bit to ‘0’ for the current context.

Parameters:
None.
Returns:

None.

ADC_ContinuousConversionEnable()

void ADC_ContinuousConversionEnable (void )

Sets the Continuous Operation Enable (CONT) bit to ‘1’ for the current context.

Parameters:
None.
Returns:

None.

ADC_ConversionDoneCallbackRegister()

void ADC_ConversionDoneCallbackRegister (void(*)(void) callback)

Sets the callback function for the ADC Conversion Done Interrupt (ADI).

Parameters:
Pointer

The pointer to the function to be executed

Returns:

None.

ADC_ConversionDoneInterruptDisable()

void ADC_ConversionDoneInterruptDisable (void )

Sets the ADC Interrupt Enable (ADIE) bit to 0.

Parameters:
None.
Returns:

None.

ADC_ConversionDoneInterruptEnable()

void ADC_ConversionDoneInterruptEnable (void )

Sets the ADC Interrupt Enable (ADIE) bit to ‘1’.

Parameters:
None.
Returns:

None.

ADC_ConversionDoneInterruptFlagClear()

void ADC_ConversionDoneInterruptFlagClear (void )

Clears the ADC Conversion Done Interrupt Flag (ADIF) bit to ‘0’.

Parameters:
None.
Returns:

None.

ADC_ConversionResultGet()

adc_result_t ADC_ConversionResultGet (void )

Retrieves the result of the latest conversion for the current context.

Precondition:

Call ADC_ConversionStart(void) before using this API.

Parameters:
None.
Returns:

adc_result_t - The result of the conversion

ADC_ConversionStageStatusGet()

adc_conversion_stage_t ADC_ConversionStageStatusGet (void )

Retrieves the conversion stage status for the current context.

Parameters:
None.
Returns:

adc_conversion_stage_t - Stage of the conversion stages

ADC_ConversionStart()

void ADC_ConversionStart (void )

Starts the conversion on a selected channel.

Precondition:

Select the channel(s) using ADC_ChannelSelect and call ADC_Initialize(void) to initialize the ADC module before using this API.

Parameters:
None.
Returns:

None.

ADC_ConversionStop()

void ADC_ConversionStop (void )

Stops the ongoing conversion.

Parameters:
None.
Returns:

None.

ADC_CurrentContextGet()

adc_context_t ADC_CurrentContextGet (void )

Returns the current context number.

Parameters:
None.
Returns:

adc_context_t - Context selected. Refer to the adc_context_t enum for the list of available contexts.

ADC_CurrentConversionCountGet()

adc_repeat_count_t ADC_CurrentConversionCountGet (void )

Retrieves the current value of the ADC Repeat Counter (ADCNT) register for the current context.

Parameters:
None.
Returns:

adc_repeat_count_t - Current value of the ADCNT register

ADC_Deinitialize()

void ADC_Deinitialize (void )

Deinitializes the registers to power-on Reset values.

Parameters:
None.
Returns:

None.

ADC_DifferentialChannelSelect()

void ADC_DifferentialChannelSelect (adc_posChannel_t posChannel, adc_negChannel_t negChannel)

Sets the positive and negative channels to use for the ADC conversion in the current context.

Parameters:
posChannel

Desired positive analog channel. Refer to the adc_posChannel_t enum for the list of available analog channels.

negChannel

Desired negative analog channel. Refer to the adc_negChannel_t enum for the list of available analog channels.

Returns:

None.

ADC_DifferentialChannelSelectAndConvert()

adc_result_t ADC_DifferentialChannelSelectAndConvert (adc_posChannel_t posChannel, adc_negChannel_t negChannel)

Starts the conversion and retrieves the result of one conversion on the selected channels for the current context.

Parameters:
posChannel

Desired positive analog channel. Refer to the adc_posChannel_t enum for the list of available analog channels.

negChannel

Desired negative analog channel. Refer to the adc_negChannel_t enum for the list of available analog channels.

Returns:

adc_result_t - The result of the conversion

ADC_Disable()

void ADC_Disable (void )

Sets the ADC Enable (ON) bit to '0'.

Parameters:
None.
Returns:

None.

ADC_DoubleSamplingDisable()

void ADC_DoubleSamplingDisable (void )

Sets the Double-Sample Enable (DSEN) bit to ‘0’ for the current context.

Parameters:
None.
Returns:

None.

ADC_DoubleSamplingEnable()

void ADC_DoubleSamplingEnable (void )

Sets the Double-Sample Enable (DSEN) bit to ‘1’ for the current context.

Parameters:
None.
Returns:

None.

ADC_Enable()

void ADC_Enable (void )

Sets the ADC Enable (ON) bit to ‘1’.

Parameters:
None.
Returns:

None.

ADC_ErrorCalculationGet()

adc_result_t ADC_ErrorCalculationGet (void )

Retrieves the value of the ADC Setpoint Error (ADERR) register for the current context.

Parameters:
None.
Returns:

adc_result_t - Value obtained from the ADERR register

ADC_ErrorCalculationModeSet()

void ADC_ErrorCalculationModeSet (adc_calculation_mode_t errorCalculationMode)

Sets the ADC Error Calculation Mode Select (CALC) bits for the current context.

Parameters:
errorCalculationMode

Desired errorCalculationMode value. Refer to the adc_calculation_mode_t for the error calculation mode options.

Returns:

None.

ADC_FilterValueGet()

adc_result_t ADC_FilterValueGet (void )

Retrieves the value of the ADC Filter (ADFLTR) register for the current context.

Parameters:
None.
Returns:

adc_result_t - Value obtained after the ADC Accumulator (ADACC) register is right shifted by the CRS bits. In Low-Pass Filter (LPF) mode, this is the output of the Low-Pass Filter.

ADC_HasAccumulatorOverflowed()

bool ADC_HasAccumulatorOverflowed (void )

Determines whether the accumulator has overflowed for the current context.

Parameters:
None.
Return values:
True

ADC accumulator has overflowed

False

ADC accumulator has not overflowed

ADC_Initialize()

void ADC_Initialize (void )

Initializes the registers based on the configurable options in the MPLAB® Code Configurator (MCC) Melody UI for the Analog-to-Digital Converter (ADC) operation.

Parameters:
None.
Returns:

None.

ADC_IsAccumulatorClearComplete()

bool ADC_IsAccumulatorClearComplete (void )

Status of the accumulator clear operation for the current context.

Parameters:
None.
Return values:
True

ADC accumulator clear operation complete

False

ADC accumulator clear operation not complete

ADC_IsBusy()

bool ADC_IsBusy (void )

Returns the busy status of the ADC module.

Parameters:
None.
Return values:
True

The ADC is in use

False

The ADC is not in use

ADC_IsChargePumpReady()

bool ADC_IsChargePumpReady (void )

Checks the Charge Pump Ready status.

Parameters:
None.
Return values:
True

Charge Pump is ready

False

Charge Pump is not ready

ADC_IsContext1ThresholdInterruptFlagSet()

bool ADC_IsContext1ThresholdInterruptFlagSet (void )

Checks the ADC Threshold Interrupt Flag (ADCH1IF) status for ADC Context 1.

Parameters:
None.
Return values:
True

ADCH1IF flag is set

False

ADCH1IF flag is not set

ADC_IsContext2ThresholdInterruptFlagSet()

bool ADC_IsContext2ThresholdInterruptFlagSet (void )

Checks the ADC Threshold Interrupt Flag (ADCH2IF) status for ADC Context 2.

Parameters:
None.
Return values:
True

ADCH2IF flag is set

False

ADCH2IF flag is not set

ADC_IsContext3ThresholdInterruptFlagSet()

bool ADC_IsContext3ThresholdInterruptFlagSet (void )

Checks the ADC Threshold Interrupt Flag (ADCH3IF) status for ADC Context 3.

Parameters:
None.
Return values:
True

ADCH3IF flag is set

False

ADCH3IF flag is not set

ADC_IsContext4ThresholdInterruptFlagSet()

bool ADC_IsContext4ThresholdInterruptFlagSet (void )

Checks the ADC Threshold Interrupt Flag (ADCH4IF) status for ADC Context 4.

Parameters:
None.
Return values:
True

ADCH4IF flag is set

False

ADCH4IF flag is not set

ADC_IsConversionDone()

bool ADC_IsConversionDone (void )

Checks if the ongoing conversion is complete.

Precondition:

ADC_ConversionStart(void) is called before using this API.

Parameters:
None.
Return values:
True

Conversion is complete

False

Conversion is ongoing

ADC_IsConversionDoneInterruptFlagSet()

bool ADC_IsConversionDoneInterruptFlagSet (void )

Checks the ADC Conversion Done Interrupt Flag (ADIF) status.

Parameters:
None.
Return values:
True

ADI flag is set

False

ADI flag is not set

ADC_IsErrorGreaterThanUpperThreshold()

bool ADC_IsErrorGreaterThanUpperThreshold (void )

Determines if the value in the ADC Setpoint Error (ADERR) register is greater than the upper threshold for the current context.

Parameters:
None.
Return values:
True

ADC error is greater than the upper threshold

False

ADC error is not greater than the upper threshold

ADC_IsErrorLesserThanLowerThreshold()

bool ADC_IsErrorLesserThanLowerThreshold (void )

Determines if the value in the ADC Setpoint Error (ADERR) register is lesser than the lower threshold for the current context.

Parameters:
None.
Return values:
True

ADC error is less than the lower threshold

False

ADC error is not less the lower threshold

ADC_ISR()

void ADC_ISR (void )

Implements the ADC Conversion Done Interrupt (ADI) service routine for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC_IsThresholdInterruptFlagSet()

bool ADC_IsThresholdInterruptFlagSet (void )

Checks the ADC Threshold Interrupt (ADCHxIF) flag for the current context.

Parameters:
None.
Return values:
True

ADCHxIF flag is set

False

ADCHxIF flag is not set

ADC_LowerThresholdSet()

void ADC_LowerThresholdSet (adc_threshold_t lowerThreshold)

Sets the value of the ADC Lower Threshold (ADLTH) register for the current context.

Parameters:
lowerThreshold

Lower threshold value of the adc_threshold_t type for the ADLTH register

Returns:

None.

ADC_PrechargeTimeSet()

void ADC_PrechargeTimeSet (uint16_t prechargeTime)

Sets the specified value for the ADC Precharge Time Control (ADPRE) register for the current context.

Parameters:
prechargeTime

Value to be loaded in the ADPRE register

Returns:

None.

ADC_PreviousResultGet()

adc_result_t ADC_PreviousResultGet (void )

Retrieves the value of the ADC Previous Result (ADPREV) register for the current context.

Parameters:
None.
Returns:

adc_result_t - Value obtained from the ADPREV register

ADC_ResolutionGet()

uint8_t ADC_ResolutionGet (void )

Returns the resolution of the ADC module.

Parameters:
None.
Returns:

uint8_t - Resolution value

ADC_SampleCapacitorDischarge()

void ADC_SampleCapacitorDischarge (void )

Discharges the input sample capacitor by setting the channel to AVss for the current context.

Parameters:
None.
Returns:

None.

ADC_SampleRepeatCountSet()

void ADC_SampleRepeatCountSet (adc_repeat_count_t repeatCount)

Loads the repeat counter with the specified value for the current context.

Parameters:
repeatCount

Repeat count value. Refer to the adc_repeat_count_t type.

Returns:

None.

ADC_SetPointDefine()

void ADC_SetPointDefine (adc_threshold_t setPoint)

Sets the value of the ADC Threshold Setpoint (ADSTPT) register for the current context.

Parameters:
setPoint

Value for the ADSTPT register of the adc_threshold_t type

Returns:

None.

ADC_StopOnInterruptDisable()

void ADC_StopOnInterruptDisable (void )

Sets the Stop-on-Interrupt (SOI) bit to ‘0’ for the current context.

Parameters:
None.
Returns:

None.

ADC_StopOnInterruptEnable()

void ADC_StopOnInterruptEnable (void )

Sets the Stop-on-Interrupt (SOI) bit to ‘1’ for the current context.

Precondition:

Call ADC_ContinuousConversionEnable API before using this API. Select the ADC context before calling this API using ADC_ContextSelect.

Parameters:
None.
Returns:

None.

ADC_Tasks()

void ADC_Tasks (void )

Implements the Tasks routine for the polling implementations.

Parameters:
None.
Returns:

None.

ADC_ThresholdCallbackRegister()

void ADC_ThresholdCallbackRegister (void(*)(void) callback)

Sets the callback for the threshold interrupt of the current context.

Parameters:
*callback

The pointer to the function to be executed

Returns:

None.

ADC_ThresholdInterruptDisable()

void ADC_ThresholdInterruptDisable (void )

Sets the ADC Threshold Interrupt Disable (ADHxIE) bit to ‘0’ for the current context.

Parameters:
None.
Returns:

None.

ADC_ThresholdInterruptEnable()

void ADC_ThresholdInterruptEnable (void )

Sets the ADC Threshold Interrupt Enable (ADHxIE) bit to ‘1’ for the current context.

Parameters:
None.
Returns:

None.

ADC_ThresholdInterruptFlagClear()

void ADC_ThresholdInterruptFlagClear (void )

Clears the ADC Threshold Interrupt Flag bit to ‘0’ for the current context.

Parameters:
None.
Returns:

None.

ADC_ThresholdModeSet()

void ADC_ThresholdModeSet (adc_threshold_mode_t thresholdMode)

Sets the conversion threshold mode for the current context.

Parameters:
thresholdMode

Desired threshold mode. Refer to the adc_threshold_mode_t enum for the list of available threshold modes.

Returns:

None.

ADC_UpperThresholdSet()

void ADC_UpperThresholdSet (adc_threshold_t upperThreshold)

Sets the value of the ADC Upper Threshold (ADUTH) register for the current context.

Parameters:
upperThreshold

Upper threshold value of the adc_threshold_t type for the ADUTH register.

Returns:

None.

Enumeration Type Documentation

adc_calculation_mode_t

enum adc_calculation_mode_t

ADC_FIRST_DERIVATIVE_OF_SINGLE_MEASUREMENT

First derivative of single measurement

ADC_ACTUAL_RESULT_VS_SETPOINT

Actual result vs setpoint

ADC_ACTUAL_RESULT_VS_FILTERED_VALUE

Actual result vs filtered value

ADC_FIRST_DERIVATIVE_OF_FILTERED_VALUE

First derivative of filtered value

ADC_FILTERED_VALUE_VS_SETPOINT

Filtered value vs setpoint

adc_channel_t

enum adc_channel_t

ADC_CHANNEL_VSS
ADC_CHANNEL_TEMP
ADC_CHANNEL_DAC1
ADC_CHANNEL_FVR_BUFFER1
ADC_CHANNEL_FVR_BUFFER2
ADC_CHANNEL_ANA1
ADC_CHANNEL_ANA2
ADC_CHANNEL_ANA6
ADC_CHANNEL_ANB2
ADC_CHANNEL_ANB4
ADC_CHANNEL_ANC1
adc_computation_mode_t

enum adc_computation_mode_t

ADC_BASIC

Basic mode

ADC_SERIES_ACCUMULATE

Series Accumulate mode

ADC_SERIES_AVERAGE

Series Average mode

ADC_BURST_AVERAGE

Burst Average mode

ADC_LOW_PASS_FILTER

Low-Pass Filter mode

adc_context_t

enum adc_context_t

context_1
context_2
context_3
context_4
adc_conversion_stage_t

enum adc_conversion_stage_t

ADC_NOT_CONVERTING

Not converting

ADC_1ST_PRECHARGE

1st precharge

ADC_1ST_ACQUISITION

1st acquisition

ADC_1ST_CONVERSION

1st conversion

ADC_SUSPENDED_BETWEEN_1ST_AND_2ND_SAMPLE

Suspended between 1st and 2nd sample

ADC_2ND_PRECHARGE

2nd precharge

ADC_2ND_ACQUISITION

2nd acquisition

ADC_2ND_CONVERSION

2nd conversion

adc_negChannel_t

enum adc_negChannel_t

ADC_NEGCHANNEL_ANA3
ADC_NEGCHANNEL_VSS
adc_posChannel_t

enum adc_posChannel_t

ADC_POSCHANNEL_ANA1
ADC_POSCHANNEL_VSS
adc_threshold_mode_t

enum adc_threshold_mode_t

ADC_NEVER_INTERRUPT

Disabled

ADC_BELOW_LOWER_THRESHOLD

ADERR < ADLTH

ADC_ABOVE_LOWER_THRESHOLD

ADERR >= ADLTH

ADC_INSIDE_LOWER_AND_UPPER_THRESHOLD

ADERR > ADLTH and ADERR < ADUTH

ADC_OUTSIDE_LOWER_AND_UPPER_THRESHOLD

ADERR < ADLTH or ADERR > ADUTH

ADC_BELOW_UPPER_THRESHOLD

ADERR <= ADUTH

ADC_ABOVE_UPPER_THRESHOLD

ADERR > ADUTH

ADC_ALWAYS_INTERRUPT

Enabled

adc_trigger_source_t

enum adc_trigger_source_t

ADC_TRIGGER_SOURCE_DISABLED

Disabled

ADC_TRIGGER_SOURCE_ADACTPPS

ADACTPPS

ADC_TRIGGER_SOURCE_TMR0

TMR0

ADC_TRIGGER_SOURCE_TMR1

TMR1

ADC_TRIGGER_SOURCE_TMR2

TMR2

ADC_TRIGGER_SOURCE_TMR3

TMR3

ADC_TRIGGER_SOURCE_TMR4

TMR4

ADC_TRIGGER_SOURCE_TMR5

TMR5

ADC_TRIGGER_SOURCE_TMR6

TMR6

ADC_TRIGGER_SOURCE_SMT1_OVERFLOW

SMT1_Overflow

ADC_TRIGGER_SOURCE_CCP1

CCP1

ADC_TRIGGER_SOURCE_CCP2

CCP2

ADC_TRIGGER_SOURCE_CCP3

CCP3

ADC_TRIGGER_SOURCE_PWM1_OUT1

PWM1_OUT1

ADC_TRIGGER_SOURCE_PWM1_OUT2

PWM1_OUT2

ADC_TRIGGER_SOURCE_PWM2_OUT1

PWM2_OUT1

ADC_TRIGGER_SOURCE_PWM2_OUT2

PWM2_OUT2

ADC_TRIGGER_SOURCE_PWM3_OUT1

PWM3_OUT1

ADC_TRIGGER_SOURCE_PWM3_OUT2

PWM3_OUT2

ADC_TRIGGER_SOURCE_NCO1

NCO1

ADC_TRIGGER_SOURCE_NCO2

NCO2

ADC_TRIGGER_SOURCE_NCO3

NCO3

ADC_TRIGGER_SOURCE_CMP1

CMP1

ADC_TRIGGER_SOURCE_CMP2

CMP2

ADC_TRIGGER_SOURCE_LOGICAL_OR_OF_ALL_IOC_FLAGS

Logical OR of all IOC flags

ADC_TRIGGER_SOURCE_CLC1

CLC1

ADC_TRIGGER_SOURCE_CLC2

CLC2

ADC_TRIGGER_SOURCE_CLC3

CLC3

ADC_TRIGGER_SOURCE_CLC4

CLC4

ADC_TRIGGER_SOURCE_CLC5

CLC5

ADC_TRIGGER_SOURCE_CLC6

CLC6

ADC_TRIGGER_SOURCE_CLC7

CLC7

ADC_TRIGGER_SOURCE_CLC8

CLC8

ADC_TRIGGER_SOURCE_ADERRH

ADERRH

ADC_TRIGGER_SOURCE_ADRESH

ADRESH

ADC_TRIGGER_SOURCE_ADPCH

ADPCH

3.1.3.1.6 File Documentation

source/Channel-Grouping_Differential_Interrupts/adc/adc.h File Reference

#include <stdint.h>
#include <stdbool.h>
#include "./adc_types.h"

Functions

Detailed Description

ADC Generated Driver API Header File

source/Channel-Grouping_Differential_Tasks/adc/adc.h File Reference

#include <stdint.h>
#include <stdbool.h>
#include "./adc_types.h"

Functions

Detailed Description

ADC Generated Driver API Header File

source/Channel-Grouping_Single-Ended_Interrupts/adc/adc.h File Reference

#include <stdint.h>
#include <stdbool.h>
#include "./adc_types.h"

Functions

Detailed Description

ADC Generated Driver API Header File

source/Channel-Grouping_Single-Ended_Tasks/adc/adc.h File Reference

#include <stdint.h>
#include <stdbool.h>
#include "./adc_types.h"

Functions

Detailed Description

ADC Generated Driver API Header File

source/Charge-Pump_Single-Ended_Interrupts/adc/adc.h File Reference

#include <stdint.h>
#include <stdbool.h>
#include "./adc_types.h"

Functions

Detailed Description

ADC Generated Driver API Header File

source/Charge-Pump_Single-Ended_Tasks/adc/adc.h File Reference

#include <stdint.h>
#include <stdbool.h>
#include "./adc_types.h"

Functions

Detailed Description

ADC Generated Driver API Header File

source/Channel-Grouping_Differential_Interrupts/adc/adc_types.h File Reference

Enumerations

Detailed Description

ADC Type Definitions Header File

source/Channel-Grouping_Differential_Tasks/adc/adc_types.h File Reference

Enumerations

Detailed Description

ADC Type Definitions Header File

Typedef Documentation

adc_accumulate_t

typedef int32_t adc_accumulate_t

adc_repeat_count_t

typedef uint8_t adc_repeat_count_t

adc_result_t

typedef int16_t adc_result_t

adc_threshold_t

typedef int16_t adc_threshold_t

Enumeration Type Documentation

adc_calculation_mode_t

enum adc_calculation_mode_t

ADC_FIRST_DERIVATIVE_OF_SINGLE_MEASUREMENT

First derivative of single measurement

ADC_ACTUAL_RESULT_VS_SETPOINT

Actual result vs setpoint

ADC_ACTUAL_RESULT_VS_FILTERED_VALUE

Actual result vs filtered value

ADC_FIRST_DERIVATIVE_OF_FILTERED_VALUE

First derivative of filtered value

ADC_FILTERED_VALUE_VS_SETPOINT

Filtered value vs setpoint

adc_computation_mode_t

enum adc_computation_mode_t

ADC_BASIC

Basic mode

ADC_SERIES_ACCUMULATE

Series Accumulate mode

ADC_SERIES_AVERAGE

Series Average mode

ADC_BURST_AVERAGE

Burst Average mode

ADC_LOW_PASS_FILTER

Low-Pass Filter mode

ADC_BASIC

Basic mode

ADC_SERIES_ACCUMULATE

Series Accumulate mode

ADC_SERIES_AVERAGE

Series Average mode

ADC_BURST_AVERAGE

Burst Average mode

ADC_LOW_PASS_FILTER

Low-Pass Filter mode

adc_context_t

enum adc_context_t

context_1
context_2
context_3
context_4
adc_conversion_stage_t

enum adc_conversion_stage_t

ADC_NOT_CONVERTING

Not converting

ADC_1ST_PRECHARGE

1st precharge

ADC_1ST_ACQUISITION

1st acquisition

ADC_1ST_CONVERSION

1st conversion

ADC_SUSPENDED_BETWEEN_1ST_AND_2ND_SAMPLE

Suspended between 1st and 2nd sample

ADC_2ND_PRECHARGE

2nd precharge

ADC_2ND_ACQUISITION

2nd acquisition

ADC_2ND_CONVERSION

2nd conversion

adc_negChannel_t

enum adc_negChannel_t

ADC_NEGCHANNEL_ANA3
ADC_NEGCHANNEL_VSS
adc_posChannel_t

enum adc_posChannel_t

ADC_POSCHANNEL_ANA1
ADC_POSCHANNEL_VSS
adc_threshold_mode_t

enum adc_threshold_mode_t

ADC_NEVER_INTERRUPT

Disabled

ADC_BELOW_LOWER_THRESHOLD

ADERR < ADLTH

ADC_ABOVE_LOWER_THRESHOLD

ADERR >= ADLTH

ADC_INSIDE_LOWER_AND_UPPER_THRESHOLD

ADERR > ADLTH and ADERR < ADUTH

ADC_OUTSIDE_LOWER_AND_UPPER_THRESHOLD

ADERR < ADLTH or ADERR > ADUTH

ADC_BELOW_UPPER_THRESHOLD

ADERR <= ADUTH

ADC_ABOVE_UPPER_THRESHOLD

ADERR > ADUTH

ADC_ALWAYS_INTERRUPT

Enabled

adc_trigger_source_t

enum adc_trigger_source_t

ADC_TRIGGER_SOURCE_DISABLED

Disabled

ADC_TRIGGER_SOURCE_ADACTPPS

ADACTPPS

ADC_TRIGGER_SOURCE_TMR0

TMR0

ADC_TRIGGER_SOURCE_TMR1

TMR1

ADC_TRIGGER_SOURCE_TMR2

TMR2

ADC_TRIGGER_SOURCE_TMR3

TMR3

ADC_TRIGGER_SOURCE_TMR4

TMR4

ADC_TRIGGER_SOURCE_TMR5

TMR5

ADC_TRIGGER_SOURCE_TMR6

TMR6

ADC_TRIGGER_SOURCE_SMT1_OVERFLOW

SMT1_Overflow

ADC_TRIGGER_SOURCE_CCP1

CCP1

ADC_TRIGGER_SOURCE_CCP2

CCP2

ADC_TRIGGER_SOURCE_CCP3

CCP3

ADC_TRIGGER_SOURCE_PWM1_OUT1

PWM1_OUT1

ADC_TRIGGER_SOURCE_PWM1_OUT2

PWM1_OUT2

ADC_TRIGGER_SOURCE_PWM2_OUT1

PWM2_OUT1

ADC_TRIGGER_SOURCE_PWM2_OUT2

PWM2_OUT2

ADC_TRIGGER_SOURCE_PWM3_OUT1

PWM3_OUT1

ADC_TRIGGER_SOURCE_PWM3_OUT2

PWM3_OUT2

ADC_TRIGGER_SOURCE_NCO1

NCO1

ADC_TRIGGER_SOURCE_NCO2

NCO2

ADC_TRIGGER_SOURCE_NCO3

NCO3

ADC_TRIGGER_SOURCE_CMP1

CMP1

ADC_TRIGGER_SOURCE_CMP2

CMP2

ADC_TRIGGER_SOURCE_LOGICAL_OR_OF_ALL_IOC_FLAGS

Logical OR of all IOC flags

ADC_TRIGGER_SOURCE_CLC1

CLC1

ADC_TRIGGER_SOURCE_CLC2

CLC2

ADC_TRIGGER_SOURCE_CLC3

CLC3

ADC_TRIGGER_SOURCE_CLC4

CLC4

ADC_TRIGGER_SOURCE_CLC5

CLC5

ADC_TRIGGER_SOURCE_CLC6

CLC6

ADC_TRIGGER_SOURCE_CLC7

CLC7

ADC_TRIGGER_SOURCE_CLC8

CLC8

ADC_TRIGGER_SOURCE_ADERRH

ADERRH

ADC_TRIGGER_SOURCE_ADRESH

ADRESH

ADC_TRIGGER_SOURCE_ADPCH

ADPCH

source/Channel-Grouping_Single-Ended_Interrupts/adc/adc_types.h File Reference

Enumerations

Detailed Description

ADC Type Definitions Header File

Typedef Documentation

adc_accumulate_t

typedef int32_t adc_accumulate_t

adc_repeat_count_t

typedef uint8_t adc_repeat_count_t

adc_result_t

typedef int16_t adc_result_t

adc_threshold_t

typedef int16_t adc_threshold_t

Enumeration Type Documentation

adc_calculation_mode_t

enum adc_calculation_mode_t

ADC_FIRST_DERIVATIVE_OF_SINGLE_MEASUREMENT

First derivative of single measurement

ADC_ACTUAL_RESULT_VS_SETPOINT

Actual result vs setpoint

ADC_ACTUAL_RESULT_VS_FILTERED_VALUE

Actual result vs filtered value

ADC_FIRST_DERIVATIVE_OF_FILTERED_VALUE

First derivative of filtered value

ADC_FILTERED_VALUE_VS_SETPOINT

Filtered value vs setpoint

adc_computation_mode_t

enum adc_computation_mode_t

ADC_BASIC

Basic mode

ADC_SERIES_ACCUMULATE

Series Accumulate mode

ADC_SERIES_AVERAGE

Series Average mode

ADC_BURST_AVERAGE

Burst Average mode

ADC_LOW_PASS_FILTER

Low-Pass Filter mode

adc_context_t

enum adc_context_t

context_1
context_2
context_3
context_4
adc_conversion_stage_t

enum adc_conversion_stage_t

ADC_NOT_CONVERTING

Not converting

ADC_1ST_PRECHARGE

1st precharge

ADC_1ST_ACQUISITION

1st acquisition

ADC_1ST_CONVERSION

1st conversion

ADC_SUSPENDED_BETWEEN_1ST_AND_2ND_SAMPLE

Suspended between 1st and 2nd sample

ADC_2ND_PRECHARGE

2nd precharge

ADC_2ND_ACQUISITION

2nd acquisition

ADC_2ND_CONVERSION

2nd conversion

adc_threshold_mode_t

enum adc_threshold_mode_t

ADC_NEVER_INTERRUPT

Disabled

ADC_BELOW_LOWER_THRESHOLD

ADERR < ADLTH

ADC_ABOVE_LOWER_THRESHOLD

ADERR >= ADLTH

ADC_INSIDE_LOWER_AND_UPPER_THRESHOLD

ADERR > ADLTH and ADERR < ADUTH

ADC_OUTSIDE_LOWER_AND_UPPER_THRESHOLD

ADERR < ADLTH or ADERR > ADUTH

ADC_BELOW_UPPER_THRESHOLD

ADERR <= ADUTH

ADC_ABOVE_UPPER_THRESHOLD

ADERR > ADUTH

ADC_ALWAYS_INTERRUPT

Enabled

adc_trigger_source_t

enum adc_trigger_source_t

ADC_TRIGGER_SOURCE_DISABLED

Disabled

ADC_TRIGGER_SOURCE_ADACTPPS

ADACTPPS

ADC_TRIGGER_SOURCE_TMR0

TMR0

ADC_TRIGGER_SOURCE_TMR1

TMR1

ADC_TRIGGER_SOURCE_TMR2

TMR2

ADC_TRIGGER_SOURCE_TMR3

TMR3

ADC_TRIGGER_SOURCE_TMR4

TMR4

ADC_TRIGGER_SOURCE_TMR5

TMR5

ADC_TRIGGER_SOURCE_TMR6

TMR6

ADC_TRIGGER_SOURCE_SMT1_OVERFLOW

SMT1_Overflow

ADC_TRIGGER_SOURCE_CCP1

CCP1

ADC_TRIGGER_SOURCE_CCP2

CCP2

ADC_TRIGGER_SOURCE_CCP3

CCP3

ADC_TRIGGER_SOURCE_PWM1_OUT1

PWM1_OUT1

ADC_TRIGGER_SOURCE_PWM1_OUT2

PWM1_OUT2

ADC_TRIGGER_SOURCE_PWM2_OUT1

PWM2_OUT1

ADC_TRIGGER_SOURCE_PWM2_OUT2

PWM2_OUT2

ADC_TRIGGER_SOURCE_PWM3_OUT1

PWM3_OUT1

ADC_TRIGGER_SOURCE_PWM3_OUT2

PWM3_OUT2

ADC_TRIGGER_SOURCE_NCO1

NCO1

ADC_TRIGGER_SOURCE_NCO2

NCO2

ADC_TRIGGER_SOURCE_NCO3

NCO3

ADC_TRIGGER_SOURCE_CMP1

CMP1

ADC_TRIGGER_SOURCE_CMP2

CMP2

ADC_TRIGGER_SOURCE_LOGICAL_OR_OF_ALL_IOC_FLAGS

Logical OR of all IOC flags

ADC_TRIGGER_SOURCE_CLC1

CLC1

ADC_TRIGGER_SOURCE_CLC2

CLC2

ADC_TRIGGER_SOURCE_CLC3

CLC3

ADC_TRIGGER_SOURCE_CLC4

CLC4

ADC_TRIGGER_SOURCE_CLC5

CLC5

ADC_TRIGGER_SOURCE_CLC6

CLC6

ADC_TRIGGER_SOURCE_CLC7

CLC7

ADC_TRIGGER_SOURCE_CLC8

CLC8

ADC_TRIGGER_SOURCE_ADERRH

ADERRH

ADC_TRIGGER_SOURCE_ADRESH

ADRESH

ADC_TRIGGER_SOURCE_ADPCH

ADPCH

source/Channel-Grouping_Single-Ended_Tasks/adc/adc_types.h File Reference

Enumerations

Detailed Description

ADC Type Definitions Header File

Typedef Documentation

adc_accumulate_t

typedef int32_t adc_accumulate_t

adc_repeat_count_t

typedef uint8_t adc_repeat_count_t

adc_result_t

typedef int16_t adc_result_t

adc_threshold_t

typedef int16_t adc_threshold_t

Enumeration Type Documentation

adc_calculation_mode_t

enum adc_calculation_mode_t

ADC_FIRST_DERIVATIVE_OF_SINGLE_MEASUREMENT

First derivative of single measurement

ADC_ACTUAL_RESULT_VS_SETPOINT

Actual result vs setpoint

ADC_ACTUAL_RESULT_VS_FILTERED_VALUE

Actual result vs filtered value

ADC_FIRST_DERIVATIVE_OF_FILTERED_VALUE

First derivative of filtered value

ADC_FILTERED_VALUE_VS_SETPOINT

Filtered value vs setpoint

adc_channel_t

enum adc_channel_t

ADC_CHANNEL_VSS
ADC_CHANNEL_TEMP
ADC_CHANNEL_DAC1
ADC_CHANNEL_FVR_BUFFER1
ADC_CHANNEL_FVR_BUFFER2
ADC_CHANNEL_ANA1
ADC_CHANNEL_ANA2
ADC_CHANNEL_ANA6
ADC_CHANNEL_ANB2
ADC_CHANNEL_ANB4
ADC_CHANNEL_ANC1
adc_computation_mode_t

enum adc_computation_mode_t

ADC_BASIC

Basic mode

ADC_SERIES_ACCUMULATE

Series Accumulate mode

ADC_SERIES_AVERAGE

Series Average mode

ADC_BURST_AVERAGE

Burst Average mode

ADC_LOW_PASS_FILTER

Low-Pass Filter mode

adc_context_t

enum adc_context_t

context_1
context_2
context_3
context_4
adc_conversion_stage_t

enum adc_conversion_stage_t

ADC_NOT_CONVERTING

Not converting

ADC_1ST_PRECHARGE

1st precharge

ADC_1ST_ACQUISITION

1st acquisition

ADC_1ST_CONVERSION

1st conversion

ADC_SUSPENDED_BETWEEN_1ST_AND_2ND_SAMPLE

Suspended between 1st and 2nd sample

ADC_2ND_PRECHARGE

2nd precharge

ADC_2ND_ACQUISITION

2nd acquisition

ADC_2ND_CONVERSION

2nd conversion

adc_threshold_mode_t

enum adc_threshold_mode_t

ADC_NEVER_INTERRUPT

Disabled

ADC_BELOW_LOWER_THRESHOLD

ADERR < ADLTH

ADC_ABOVE_LOWER_THRESHOLD

ADERR >= ADLTH

ADC_INSIDE_LOWER_AND_UPPER_THRESHOLD

ADERR > ADLTH and ADERR < ADUTH

ADC_OUTSIDE_LOWER_AND_UPPER_THRESHOLD

ADERR < ADLTH or ADERR > ADUTH

ADC_BELOW_UPPER_THRESHOLD

ADERR <= ADUTH

ADC_ABOVE_UPPER_THRESHOLD

ADERR > ADUTH

ADC_ALWAYS_INTERRUPT

Enabled

adc_trigger_source_t

enum adc_trigger_source_t

ADC_TRIGGER_SOURCE_DISABLED

Disabled

ADC_TRIGGER_SOURCE_ADACTPPS

ADACTPPS

ADC_TRIGGER_SOURCE_TMR0

TMR0

ADC_TRIGGER_SOURCE_TMR1

TMR1

ADC_TRIGGER_SOURCE_TMR2

TMR2

ADC_TRIGGER_SOURCE_TMR3

TMR3

ADC_TRIGGER_SOURCE_TMR4

TMR4

ADC_TRIGGER_SOURCE_TMR5

TMR5

ADC_TRIGGER_SOURCE_TMR6

TMR6

ADC_TRIGGER_SOURCE_SMT1_OVERFLOW

SMT1_Overflow

ADC_TRIGGER_SOURCE_CCP1

CCP1

ADC_TRIGGER_SOURCE_CCP2

CCP2

ADC_TRIGGER_SOURCE_CCP3

CCP3

ADC_TRIGGER_SOURCE_PWM1_OUT1

PWM1_OUT1

ADC_TRIGGER_SOURCE_PWM1_OUT2

PWM1_OUT2

ADC_TRIGGER_SOURCE_PWM2_OUT1

PWM2_OUT1

ADC_TRIGGER_SOURCE_PWM2_OUT2

PWM2_OUT2

ADC_TRIGGER_SOURCE_PWM3_OUT1

PWM3_OUT1

ADC_TRIGGER_SOURCE_PWM3_OUT2

PWM3_OUT2

ADC_TRIGGER_SOURCE_NCO1

NCO1

ADC_TRIGGER_SOURCE_NCO2

NCO2

ADC_TRIGGER_SOURCE_NCO3

NCO3

ADC_TRIGGER_SOURCE_CMP1

CMP1

ADC_TRIGGER_SOURCE_CMP2

CMP2

ADC_TRIGGER_SOURCE_LOGICAL_OR_OF_ALL_IOC_FLAGS

Logical OR of all IOC flags

ADC_TRIGGER_SOURCE_CLC1

CLC1

ADC_TRIGGER_SOURCE_CLC2

CLC2

ADC_TRIGGER_SOURCE_CLC3

CLC3

ADC_TRIGGER_SOURCE_CLC4

CLC4

ADC_TRIGGER_SOURCE_CLC5

CLC5

ADC_TRIGGER_SOURCE_CLC6

CLC6

ADC_TRIGGER_SOURCE_CLC7

CLC7

ADC_TRIGGER_SOURCE_CLC8

CLC8

ADC_TRIGGER_SOURCE_ADERRH

ADERRH

ADC_TRIGGER_SOURCE_ADRESH

ADRESH

ADC_TRIGGER_SOURCE_ADPCH

ADPCH

source/Charge-Pump_Single-Ended_Interrupts/adc/adc_types.h File Reference

Enumerations

Detailed Description

ADC Type Definitions Header File

Typedef Documentation

adc_accumulate_t

typedef int32_t adc_accumulate_t

adc_repeat_count_t

typedef uint8_t adc_repeat_count_t

adc_result_t

typedef int16_t adc_result_t

adc_threshold_t

typedef int16_t adc_threshold_t

Enumeration Type Documentation

adc_calculation_mode_t

enum adc_calculation_mode_t

ADC_FIRST_DERIVATIVE_OF_SINGLE_MEASUREMENT

First derivative of single measurement

ADC_ACTUAL_RESULT_VS_SETPOINT

Actual result vs setpoint

ADC_ACTUAL_RESULT_VS_FILTERED_VALUE

Actual result vs filtered value

ADC_FIRST_DERIVATIVE_OF_FILTERED_VALUE

First derivative of filtered value

ADC_FILTERED_VALUE_VS_SETPOINT

Filtered value vs setpoint

adc_channel_t

enum adc_channel_t

ADC_CHANNEL_VSS
ADC_CHANNEL_TEMP
ADC_CHANNEL_DAC1
ADC_CHANNEL_FVR_BUFFER1
ADC_CHANNEL_FVR_BUFFER2
ADC_CHANNEL_ANA1
ADC_CHANNEL_ANA2
ADC_CHANNEL_ANA6
ADC_CHANNEL_ANB2
ADC_CHANNEL_ANB4
ADC_CHANNEL_ANC1
adc_computation_mode_t

enum adc_computation_mode_t

ADC_BASIC

Basic mode

ADC_SERIES_ACCUMULATE

Series Accumulate mode

ADC_SERIES_AVERAGE

Series Average mode

ADC_BURST_AVERAGE

Burst Average mode

ADC_LOW_PASS_FILTER

Low-Pass Filter mode

adc_context_t

enum adc_context_t

context_1
context_2
context_3
context_4
adc_conversion_stage_t

enum adc_conversion_stage_t

ADC_NOT_CONVERTING

Not converting

ADC_1ST_PRECHARGE

1st precharge

ADC_1ST_ACQUISITION

1st acquisition

ADC_1ST_CONVERSION

1st conversion

ADC_SUSPENDED_BETWEEN_1ST_AND_2ND_SAMPLE

Suspended between 1st and 2nd sample

ADC_2ND_PRECHARGE

2nd precharge

ADC_2ND_ACQUISITION

2nd acquisition

ADC_2ND_CONVERSION

2nd conversion

adc_threshold_mode_t

enum adc_threshold_mode_t

ADC_NEVER_INTERRUPT

Disabled

ADC_BELOW_LOWER_THRESHOLD

ADERR < ADLTH

ADC_ABOVE_LOWER_THRESHOLD

ADERR >= ADLTH

ADC_INSIDE_LOWER_AND_UPPER_THRESHOLD

ADERR > ADLTH and ADERR < ADUTH

ADC_OUTSIDE_LOWER_AND_UPPER_THRESHOLD

ADERR < ADLTH or ADERR > ADUTH

ADC_BELOW_UPPER_THRESHOLD

ADERR <= ADUTH

ADC_ABOVE_UPPER_THRESHOLD

ADERR > ADUTH

ADC_ALWAYS_INTERRUPT

Enabled

adc_trigger_source_t

enum adc_trigger_source_t

ADC_TRIGGER_SOURCE_DISABLED

Disabled

ADC_TRIGGER_SOURCE_ADACTPPS

ADACTPPS

ADC_TRIGGER_SOURCE_TMR0

TMR0

ADC_TRIGGER_SOURCE_TMR1

TMR1

ADC_TRIGGER_SOURCE_TMR2

TMR2

ADC_TRIGGER_SOURCE_TMR3

TMR3

ADC_TRIGGER_SOURCE_TMR4

TMR4

ADC_TRIGGER_SOURCE_TMR5

TMR5

ADC_TRIGGER_SOURCE_TMR6

TMR6

ADC_TRIGGER_SOURCE_SMT1_OVERFLOW

SMT1_Overflow

ADC_TRIGGER_SOURCE_CCP1

CCP1

ADC_TRIGGER_SOURCE_CCP2

CCP2

ADC_TRIGGER_SOURCE_CCP3

CCP3

ADC_TRIGGER_SOURCE_PWM1_OUT1

PWM1_OUT1

ADC_TRIGGER_SOURCE_PWM1_OUT2

PWM1_OUT2

ADC_TRIGGER_SOURCE_PWM2_OUT1

PWM2_OUT1

ADC_TRIGGER_SOURCE_PWM2_OUT2

PWM2_OUT2

ADC_TRIGGER_SOURCE_PWM3_OUT1

PWM3_OUT1

ADC_TRIGGER_SOURCE_PWM3_OUT2

PWM3_OUT2

ADC_TRIGGER_SOURCE_NCO1

NCO1

ADC_TRIGGER_SOURCE_NCO2

NCO2

ADC_TRIGGER_SOURCE_NCO3

NCO3

ADC_TRIGGER_SOURCE_CMP1

CMP1

ADC_TRIGGER_SOURCE_CMP2

CMP2

ADC_TRIGGER_SOURCE_LOGICAL_OR_OF_ALL_IOC_FLAGS

Logical OR of all IOC flags

ADC_TRIGGER_SOURCE_CLC1

CLC1

ADC_TRIGGER_SOURCE_CLC2

CLC2

ADC_TRIGGER_SOURCE_CLC3

CLC3

ADC_TRIGGER_SOURCE_CLC4

CLC4

ADC_TRIGGER_SOURCE_CLC5

CLC5

ADC_TRIGGER_SOURCE_CLC6

CLC6

ADC_TRIGGER_SOURCE_CLC7

CLC7

ADC_TRIGGER_SOURCE_CLC8

CLC8

ADC_TRIGGER_SOURCE_ADERRH

ADERRH

ADC_TRIGGER_SOURCE_ADRESH

ADRESH

ADC_TRIGGER_SOURCE_ADPCH

ADPCH

source/Charge-Pump_Single-Ended_Tasks/adc/adc_types.h File Reference

Enumerations

Detailed Description

ADC Type Definitions Header File

Typedef Documentation

adc_accumulate_t

typedef int32_t adc_accumulate_t

adc_repeat_count_t

typedef uint8_t adc_repeat_count_t

adc_result_t

typedef int16_t adc_result_t

adc_threshold_t

typedef int16_t adc_threshold_t

Enumeration Type Documentation

adc_calculation_mode_t

enum adc_calculation_mode_t

ADC_FIRST_DERIVATIVE_OF_SINGLE_MEASUREMENT

First derivative of single measurement

ADC_ACTUAL_RESULT_VS_SETPOINT

Actual result vs setpoint

ADC_ACTUAL_RESULT_VS_FILTERED_VALUE

Actual result vs filtered value

ADC_FIRST_DERIVATIVE_OF_FILTERED_VALUE

First derivative of filtered value

ADC_FILTERED_VALUE_VS_SETPOINT

Filtered value vs setpoint

adc_channel_t

enum adc_channel_t

ADC_CHANNEL_VSS
ADC_CHANNEL_TEMP
ADC_CHANNEL_DAC1
ADC_CHANNEL_FVR_BUFFER1
ADC_CHANNEL_FVR_BUFFER2
ADC_CHANNEL_ANA1
ADC_CHANNEL_ANA2
ADC_CHANNEL_ANA6
ADC_CHANNEL_ANB2
ADC_CHANNEL_ANB4
ADC_CHANNEL_ANC1
adc_computation_mode_t

enum adc_computation_mode_t

ADC_BASIC

Basic mode

ADC_SERIES_ACCUMULATE

Series Accumulate mode

ADC_SERIES_AVERAGE

Series Average mode

ADC_BURST_AVERAGE

Burst Average mode

ADC_LOW_PASS_FILTER

Low-Pass Filter mode

adc_context_t

enum adc_context_t

context_1
context_2
context_3
context_4
adc_conversion_stage_t

enum adc_conversion_stage_t

ADC_NOT_CONVERTING

Not converting

ADC_1ST_PRECHARGE

1st precharge

ADC_1ST_ACQUISITION

1st acquisition

ADC_1ST_CONVERSION

1st conversion

ADC_SUSPENDED_BETWEEN_1ST_AND_2ND_SAMPLE

Suspended between 1st and 2nd sample

ADC_2ND_PRECHARGE

2nd precharge

ADC_2ND_ACQUISITION

2nd acquisition

ADC_2ND_CONVERSION

2nd conversion

adc_threshold_mode_t

enum adc_threshold_mode_t

ADC_NEVER_INTERRUPT

Disabled

ADC_BELOW_LOWER_THRESHOLD

ADERR < ADLTH

ADC_ABOVE_LOWER_THRESHOLD

ADERR >= ADLTH

ADC_INSIDE_LOWER_AND_UPPER_THRESHOLD

ADERR > ADLTH and ADERR < ADUTH

ADC_OUTSIDE_LOWER_AND_UPPER_THRESHOLD

ADERR < ADLTH or ADERR > ADUTH

ADC_BELOW_UPPER_THRESHOLD

ADERR <= ADUTH

ADC_ABOVE_UPPER_THRESHOLD

ADERR > ADUTH

ADC_ALWAYS_INTERRUPT

Enabled

adc_trigger_source_t

enum adc_trigger_source_t

ADC_TRIGGER_SOURCE_DISABLED

Disabled

ADC_TRIGGER_SOURCE_ADACTPPS

ADACTPPS

ADC_TRIGGER_SOURCE_TMR0

TMR0

ADC_TRIGGER_SOURCE_TMR1

TMR1

ADC_TRIGGER_SOURCE_TMR2

TMR2

ADC_TRIGGER_SOURCE_TMR3

TMR3

ADC_TRIGGER_SOURCE_TMR4

TMR4

ADC_TRIGGER_SOURCE_TMR5

TMR5

ADC_TRIGGER_SOURCE_TMR6

TMR6

ADC_TRIGGER_SOURCE_SMT1_OVERFLOW

SMT1_Overflow

ADC_TRIGGER_SOURCE_CCP1

CCP1

ADC_TRIGGER_SOURCE_CCP2

CCP2

ADC_TRIGGER_SOURCE_CCP3

CCP3

ADC_TRIGGER_SOURCE_PWM1_OUT1

PWM1_OUT1

ADC_TRIGGER_SOURCE_PWM1_OUT2

PWM1_OUT2

ADC_TRIGGER_SOURCE_PWM2_OUT1

PWM2_OUT1

ADC_TRIGGER_SOURCE_PWM2_OUT2

PWM2_OUT2

ADC_TRIGGER_SOURCE_PWM3_OUT1

PWM3_OUT1

ADC_TRIGGER_SOURCE_PWM3_OUT2

PWM3_OUT2

ADC_TRIGGER_SOURCE_NCO1

NCO1

ADC_TRIGGER_SOURCE_NCO2

NCO2

ADC_TRIGGER_SOURCE_NCO3

NCO3

ADC_TRIGGER_SOURCE_CMP1

CMP1

ADC_TRIGGER_SOURCE_CMP2

CMP2

ADC_TRIGGER_SOURCE_LOGICAL_OR_OF_ALL_IOC_FLAGS

Logical OR of all IOC flags

ADC_TRIGGER_SOURCE_CLC1

CLC1

ADC_TRIGGER_SOURCE_CLC2

CLC2

ADC_TRIGGER_SOURCE_CLC3

CLC3

ADC_TRIGGER_SOURCE_CLC4

CLC4

ADC_TRIGGER_SOURCE_CLC5

CLC5

ADC_TRIGGER_SOURCE_CLC6

CLC6

ADC_TRIGGER_SOURCE_CLC7

CLC7

ADC_TRIGGER_SOURCE_CLC8

CLC8

ADC_TRIGGER_SOURCE_ADERRH

ADERRH

ADC_TRIGGER_SOURCE_ADRESH

ADRESH

ADC_TRIGGER_SOURCE_ADPCH

ADPCH

source/Channel-Grouping_Differential_Interrupts/adc/src/adc.c File Reference

This file contains the API implementations for the ADC driver.

#include <xc.h>
#include "../adc.h"
#include "../adc_types.h"

Functions

Detailed Description

This file contains the API implementations for the ADC driver.

ADC Generated Driver File

Version: ADC Driver Version 2.0.0 ADC Package Version 2.0.0

Variable Documentation

adc_busy_status

bool adc_busy_status[static]

ADC_Context1ThresholdCallback

void(* ADC_Context1ThresholdCallback) (void)[static]

ADC_Context2ThresholdCallback

void(* ADC_Context2ThresholdCallback) (void)[static]

ADC_Context3ThresholdCallback

void(* ADC_Context3ThresholdCallback) (void)[static]

ADC_Context4ThresholdCallback

void(* ADC_Context4ThresholdCallback) (void)[static]

ADC_ConversionDoneCallback

void(* ADC_ConversionDoneCallback) (void)[static]

source/Channel-Grouping_Differential_Tasks/adc/src/adc.c File Reference

This file contains the API implementations for the ADC driver.

#include <xc.h>
#include "../adc.h"
#include "../adc_types.h"

Functions

Detailed Description

This file contains the API implementations for the ADC driver.

ADC Generated Driver File

Version: ADC Driver Version 2.0.0 ADC Package Version 2.0.0

Variable Documentation

adc_busy_status

bool adc_busy_status[static]

ADC_Context1ThresholdCallback

void(* ADC_Context1ThresholdCallback) (void)[static]

ADC_Context2ThresholdCallback

void(* ADC_Context2ThresholdCallback) (void)[static]

ADC_Context3ThresholdCallback

void(* ADC_Context3ThresholdCallback) (void)[static]

ADC_Context4ThresholdCallback

void(* ADC_Context4ThresholdCallback) (void)[static]

ADC_ConversionDoneCallback

void(* ADC_ConversionDoneCallback) (void)[static]

source/Channel-Grouping_Single-Ended_Interrupts/adc/src/adc.c File Reference

This file contains the API implementations for the ADC driver.

#include <xc.h>
#include "../adc.h"
#include "../adc_types.h"

Functions

Detailed Description

This file contains the API implementations for the ADC driver.

ADC Generated Driver File

Version: ADC Driver Version 2.0.0 ADC Package Version 2.0.0

Variable Documentation

adc_busy_status

bool adc_busy_status[static]

ADC_Context1ThresholdCallback

void(* ADC_Context1ThresholdCallback) (void)[static]

ADC_Context2ThresholdCallback

void(* ADC_Context2ThresholdCallback) (void)[static]

ADC_Context3ThresholdCallback

void(* ADC_Context3ThresholdCallback) (void)[static]

ADC_Context4ThresholdCallback

void(* ADC_Context4ThresholdCallback) (void)[static]

ADC_ConversionDoneCallback

void(* ADC_ConversionDoneCallback) (void)[static]

source/Channel-Grouping_Single-Ended_Tasks/adc/src/adc.c File Reference

This file contains the API implementations for the ADC driver.

#include <xc.h>
#include "../adc.h"
#include "../adc_types.h"

Functions

Detailed Description

This file contains the API implementations for the ADC driver.

ADC Generated Driver File

Version: ADC Driver Version 2.0.0 ADC Package Version 2.0.0

Variable Documentation

adc_busy_status

bool adc_busy_status[static]

ADC_Context1ThresholdCallback

void(* ADC_Context1ThresholdCallback) (void)[static]

ADC_Context2ThresholdCallback

void(* ADC_Context2ThresholdCallback) (void)[static]

ADC_Context3ThresholdCallback

void(* ADC_Context3ThresholdCallback) (void)[static]

ADC_Context4ThresholdCallback

void(* ADC_Context4ThresholdCallback) (void)[static]

ADC_ConversionDoneCallback

void(* ADC_ConversionDoneCallback) (void)[static]

source/Charge-Pump_Single-Ended_Interrupts/adc/src/adc.c File Reference

This file contains the API implementations for the ADC driver.

#include <xc.h>
#include "../adc.h"
#include "../adc_types.h"

Functions

Detailed Description

This file contains the API implementations for the ADC driver.

ADC Generated Driver File

Version: ADC Driver Version 2.0.0 ADC Package Version 2.0.0

Variable Documentation

adc_busy_status

bool adc_busy_status[static]

ADC_Context1ThresholdCallback

void(* ADC_Context1ThresholdCallback) (void)[static]

ADC_Context2ThresholdCallback

void(* ADC_Context2ThresholdCallback) (void)[static]

ADC_Context3ThresholdCallback

void(* ADC_Context3ThresholdCallback) (void)[static]

ADC_Context4ThresholdCallback

void(* ADC_Context4ThresholdCallback) (void)[static]

ADC_ConversionDoneCallback

void(* ADC_ConversionDoneCallback) (void)[static]

source/Charge-Pump_Single-Ended_Tasks/adc/src/adc.c File Reference

This file contains the API implementations for the ADC driver.

#include <xc.h>
#include "../adc.h"
#include "../adc_types.h"

Functions

Detailed Description

This file contains the API implementations for the ADC driver.

ADC Generated Driver File

Version: ADC Driver Version 2.0.0 ADC Package Version 2.0.0

Variable Documentation

adc_busy_status

bool adc_busy_status[static]

ADC_Context1ThresholdCallback

void(* ADC_Context1ThresholdCallback) (void)[static]

ADC_Context2ThresholdCallback

void(* ADC_Context2ThresholdCallback) (void)[static]

ADC_Context3ThresholdCallback

void(* ADC_Context3ThresholdCallback) (void)[static]

ADC_Context4ThresholdCallback

void(* ADC_Context4ThresholdCallback) (void)[static]

ADC_ConversionDoneCallback

void(* ADC_ConversionDoneCallback) (void)[static]

3.1.3.1.7 Melody ADCCC Use Cases

Melody ADCCC Use Case 1 - Configure ADC Basic Mode & 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.

The use cases show example uses of the ADCCC Driver, within an MCC Melody project:
  • Add the following drivers/libraries to the project:
    1. Data Streamer

    2. ADC

  • DataStreamer Configuration:
    1. UART Dependency: UART2

    2. Variable type: uint16_t

    3. Variable name: adc_result  

  • ADC Easy View Configuration:
    1. Single-ended mode

    2. Right-justified

    3. VDD 3.3V

    4. Clock Selection ADCRC

  • ADC Context 1 Configuration:
    1. Positive Channel: ANA2

    2. Positive Reference: VDD

  • Configure Pin Grid View:
    1. PORTA Pin 2 as ANPx input

    2. Set UART Tx Pin as Output (RB4 on Q71 Curiosity Nano)

Other:
  • 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;
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 the result. 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.

Device Resources:
  1. Add ADC

  2. Add DataStreamer

ADC Easy View Configuration:
  1. Single-ended mode

  2. Right-justified

  3. VDD 3.3V

  4. External Positive Reference Voltage: 3.3V

  5. Clock Selection ADCRC

ADC Context 1 Configuration:
  1. Positive Channel: ANA2

  2. Positive Reference: VDD

  3. Operating Mode Selection: Burst_Average_mode

  4. Error Calculation Mode: First derivative of filtered value

  5. Upper Threshold: 3.3V

  6. Lower Threshold: 0V

  7. Threshold Setpoint: 0V

  8. Repeat Threshold: 64

  9. Accumulator Right Shift: 6

  10. Acquisition Count: 1 (minimum, dependent on analog circuit output impedance)

DataStreamer:
  • Configuration Settings:
    1. Variable type: uint16_t

    2. Variable name: adc_result

  • Dependency Selector:  

    1. UART Dependency: UART2.

System:
  • Clock Configuration: Default (1 MHz)

  • Pins: (For all pins check board schematics)
    1. Pin Grid View: Select an ANx (ANA2).

    2. Pin Grid View: Select pin for UART Transmit - Tx (RB4).

    3. Pin Grid View: Select LED pin as output.  

    4. Pins: Rename Custom Name to "LED".

Configure Pin Grid View:
  1. PORTA Pin 2 as ANPx input

  2. Set UART Tx Pin as Output (RB4 on Q71 Curiosity Nano)

Other:
  • 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;
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.

Device Resources:
  1. Add ADC

  2. Add DataStreamer

ADC Easy View Configuration:
  1. Single-ended mode

  2. Right-justified

  3. VDD 3.3V

  4. External Positive Reference Voltage: 3.3V

  5. Clock Selection: FOSC

  6. Clock Divider: FOSC/4 ADC Context 1 Configuration:

  7. Positive Channel: ANA2

  8. Positive Reference: VDD

  9. Operating Mode Selection: Burst_Average_mode

  10. Error Calculation Mode: Filtered Value vs Setpoint

  11. Upper Threshold: 32767

  12. Lower Threshold: -32768

  13. Threshold Setpoint: 0

  14. Repeat Threshold: 64

  15. Accumulator Right Shift: 6

  16. Acquisition Count: 8191 (Note Acquistion Time of 2.048ms)

  17. Previous Sample Input: FLTR

DataStreamer:
  • Configuration Settings:
    1. Variable type: uint16_t

    2. Variable name: adc_result

  • Dependency Selector:  

    1. UART Dependency: UART2.

System:
  • Clock Configuration: 4 MHz
    1. Clock Source: HFINTOSC

    2. HF Internal Clock: 4 MHz

    3. Clock Divider: 1

  • Configure Pin Grid View:
    1. PORTA Pin 2 as ANPx input

    2. Set UART Tx Pin as Output (RB4 on Q71 Curiosity Nano)

    3. Select LED pin as output (RC7 on Q71 Curiosity Nano)

    4. Rename Custom Name to "LED"

Other:
  • 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:

ADC Context 1 Configuration:
  1. 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.

Device Resources:
  1. Add ADC3

  2. Add Data Streamer

ADC3:  

  • Hardware Settings:
    1. Set Input Configuration: Single Ended Mode

    2. Set Result Format: Right Justified

    3. VDD (V): 3.3

  • Clock Selection: ADCRC

  • Context 1 Channel Selection
    1. Positive Channel Selection: ANA2 (if using Signal and Noise Generator)

  • Computation and Threshold Comparison:
    1. Operating Mode Selection: Basic Mode

    2. Error Calculation Mode: Actual Result vs Setpoint

    3. Threshold Interrupt Mode: ADERR < ADLTH or ADERR > ADUTH

    4. Upper Threshold (V): 2

    5. Lower Threshold (V): 1

    6. Threshold Setpoint (V): 0

  • Advanced Hardware Settings:
    1. Acquisition Count: 1 (if using Signal and Noise Generator or other device with buffered output)

    2. Previous Sample Input: RES

  • Interrupt Settings:
    1. ADCH1 Interrupt Enable

Data Streamer:  

  • Software Settings:
    1. UART Dependency Selection: Select the UART that is connected to Serial/CDC port. On Q71 Curiosity Nano, this is UART2.

  • Data Streamer Table:
    1. Add variable: uint16_t adc_result

    2. Add variable: uint8_t LED_state

System:
  • Clock Configuration: Default (1 MHz)

  • Configure Pin Grid View:
    1. PORTA Pin 2 as ANPx input

    2. Set UART Tx Pin as Output (RB4 on Q71 Curiosity Nano)

    3. Select LED pin as output (RC7 on Q71 Curiosity Nano)

    4. Rename Custom Name to "LED"

Other:
  • 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

Device Resources:
  1. Add ADC3

  2. Add FVR

  3. Add Data Streamer

Data Streamer:  

  • Software Settings:
    1. UART Dependency Selection: Select the UART that is connected to Serial/CDC port. On Q71 Curiosity Nano, this is UART2.

  • Data Streamer Table:
    1. Add variable: uint16_t adc_result

FVR:
  • Hardware Settings:
    1. Enable FVR

    2. FVR Buffer Gain to ADC: 2x (note the voltage 2.048V is listed when this option is selected)

    3. FVR Buffer Gain to other Peripherals: OFF

ADC3:  

  • Hardware Settings:
    1. Set Input Configuration: Single Ended Mode

    2. Set Result Format: Right Justified

    3. VDD (V): 3.3

  • Clock Selection: ADCRC

  • Context 1 Channel Selection
    1. Positive Channel Selection: ANA2 (if using Signal and Noise Generator)

    2. Positive Voltage Reference: FVR

  • Computation and Threshold Comparison:
    1. Operating Mode Selection: Basic Mode

  • Advanced Hardware Settings:
    1. Acquisition Count: 1 (if using Signal and Noise Generator or other device with buffered output)

    2. Previous Sample Input: RES

  • Configure Pin Grid View:
    1. PORTA Pin 2 as ANPx input

    2. Set UART Tx Pin as Output (RB4 on Q71 Curiosity Nano)

Other:
  • 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.

Device Resources:
  1. Add ADC3

  2. Add DAC

  3. Add Data Streamer

Data Streamer:  

  • Software Settings:
    1. UART Dependency Selection: Select the UART that is connected to Serial/CDC port. On Q71 Curiosity Nano, this is UART2.

  • Data Streamer Table:
    1. Add variable: uint16_t adc_result

DAC:
  • Software Settings:
    1. VDD: Enter microcontroller VDD. This example uses 3.3V

    2. Required Ref: Enter reference voltage (between 1.8V and VDD). This example uses 1.8V

  • Hardware Settings:
    1. DAC Enable: Turn ON

    2. DAC Positive Reference Selection: VDD

    3. DAC Negative Reference Selection: VSS

    4. DAC Output Enable Selection: DACOUT2 Enabled and DACOUT1 Disabled (DACOUT1 on pin RA2, DACOUT2 on pin RB7)

ADC3:  

  • Hardware Settings:
    1. Set Input Configuration: Single Ended Mode

    2. Set Result Format: Right Justified

    3. VDD (V): Enter microcontroller VDD. This example uses 3.3V

  • Clock Selection: ADCRC

  • Context 1 Channel Selection
    1. Positive Channel Selection: ANA2 (if using Signal and Noise Generator)

    2. 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:
    1. Operating Mode Selection: Basic Mode

  • Advanced Hardware Settings:
    1. Acquisition Count: 1 (if using Signal and Noise Generator or other device with buffered output)

    2. Previous Sample Input: RES  

  • Configure Pin Grid View:
    1. PORTA Pin 2 as ANPx input

    2. 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).

Other:
  • 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
        }
    }    
}