3.1.2.2 10-bit ADCC with Ch. Group Sel.

10-bit ADC with Computation and Channel Group Selection

3.1.2.2.1 Introduction

The Analog-to-Digital Converter with Computation (ADCC) peripheral converts both single-ended and differential analog input signals to a 10-bit binary representation of that signal. This peripheral takes in analog signals and combines them into a Sample-and-Hold (S/H) circuit. It is then fed to a converter to turn this measurement into a 10-digit binary number and is stored in the ADC result registers. This ADCC also supports Channel Grouping which allows multiple, simultaneous input connections to the ADC.

3.1.2.2.2 Supported Device Families

PIC16F180xxPIC18F-Q20

3.1.2.2.3 Required header files:


#include "mcc_generated_files/adcc/adcc.h"

3.1.2.2.4 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 3.0.0 ADC Package Version 2.0.0
Enumerations
Functions

Definition Documentation

ADC_BIT_CLEAR

#define ADC_BIT_CLEAR 0U

ADC bit clear value.

ADC_BIT_SET

#define ADC_BIT_SET 1U

ADC bit set value.

ADC_RESOLUTION

#define ADC_RESOLUTION 10U

ADC resolution value.

IO_RA0

#define IO_RA0 ADC_CHANNEL_ANA0

Defines the Custom Name pin mapping for channels in adc_channel_t.

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.

Parameters:
None.
Returns:

adc_accumulate_t value of ADC accumulator register

ADC_AccumulatorClear()

void ADC_AccumulatorClear (void )

Clears the accumulator.

Parameters:
None.
Returns:

None.

ADC_AcquisitionTimeSet()

void ADC_AcquisitionTimeSet (uint16_t acquisitionValue)

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

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.

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.

Parameters:
rightShiftValue

Right shift value

Returns:

None.

ADC_ChannelSelect()

void ADC_ChannelSelect (adc_channel_t channel)

Sets the channel to use for the ADC conversion.

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.

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_ComputationModeSet()

void ADC_ComputationModeSet (adc_computation_mode_t computationMode)

Sets the computation mode.

Parameters:
computationMode

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

Returns:

None.

ADC_ContinuousConversionDisable()

void ADC_ContinuousConversionDisable (void )

Sets the Continuous Operation Enable (CONT) bit to '0'.

Parameters:
None.
Returns:

None.

ADC_ContinuousConversionEnable()

void ADC_ContinuousConversionEnable (void )

Sets the Continuous Operation Enable (CONT) bit to '1'.

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 )

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

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.

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_CurrentConversionCountGet()

adc_repeat_count_t ADC_CurrentConversionCountGet (void )

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

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_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'.

Parameters:
None.
Returns:

None.

ADC_DoubleSamplingEnable()

void ADC_DoubleSamplingEnable (void )

Sets the Double-Sample Enable (DSEN) bit to '1'.

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.

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.

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.

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.

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.

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

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.

Parameters:
None.
Return values:
True

ADC error is less than the lower threshold

False

ADC error is not less than 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.

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.

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.

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.

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.

Parameters:
None.
Returns:

None.

ADC_SampleRepeatCountSet()

void ADC_SampleRepeatCountSet (adc_repeat_count_t repeatCount)

Loads the repeat counter with the specified value.

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.

Parameters:
ADC_StopOnInterruptDisable()

void ADC_StopOnInterruptDisable (void )

Sets the Stop-on-Interrupt (SOI) bit to '0'.

Parameters:
None.
Returns:

None.

ADC_StopOnInterruptEnable()

void ADC_StopOnInterruptEnable (void )

Sets the Stop-on-Interrupt (SOI) bit to '1'.

Precondition:

Call ADC_ContinuousConversionEnable API before using this API.

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.

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

Parameters:
None.
Returns:

None.

ADC_ThresholdInterruptEnable()

void ADC_ThresholdInterruptEnable (void )

Sets the ADC Threshold Interrupt Enable (ADHxIE) bit to '1'.

Parameters:
None.
Returns:

None.

ADC_ThresholdInterruptFlagClear()

void ADC_ThresholdInterruptFlagClear (void )

Sets the ADC Threshold Interrupt Flag bit to '0'.

Parameters:
None.
Returns:

None.

ADC_ThresholdISR()

void ADC_ThresholdISR (void )

Implements the ADC Threshold Interrupt (ADTI) service routine for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC_ThresholdModeSet()

void ADC_ThresholdModeSet (adc_threshold_mode_t thresholdMode)

Sets the conversion threshold mode.

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.

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

Enumeration for the ADC error calculation modes.

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

Enumeration that describes the available ADC channels.

ADC_CHANNEL_ADCG1

ADCG1

ADC_CHANNEL_VSS

VSS

ADC_CHANNEL_TEMP

Temp

ADC_CHANNEL_FVR_BUF1

FVR_buf1

ADC_CHANNEL_FVR_BUF2

FVR_buf2

ADC_CHANNEL_ANA0

IO_RA0: RA0

adc_computation_mode_t

enum adc_computation_mode_t

Enumeration for the ADC computation modes.

ADC_BASIC

Basic_mode

ADC_SERIES_ACCUMULATE

Accumulate_mode

ADC_SERIES_AVERAGE

Average_mode

ADC_BURST_AVERAGE

Burst_average_mode

ADC_LOW_PASS_FILTER

Low_pass_filter_mode

adc_conversion_stage_t

enum adc_conversion_stage_t

Enumeration for the ADC conversion stage statuses.

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

Enumeration for the ADC threshold modes.

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

Enumeration for the ADC auto-trigger sources.

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_TMR6

TMR6

ADC_TRIGGER_SOURCE_CCP1

CCP1

ADC_TRIGGER_SOURCE_CCP2

CCP2

ADC_TRIGGER_SOURCE_PWM3

PWM3

ADC_TRIGGER_SOURCE_PWM4

PWM4

ADC_TRIGGER_SOURCE_PWM5

PWM5

ADC_TRIGGER_SOURCE_NCO1

NCO1

ADC_TRIGGER_SOURCE_C1OUT

C1OUT

ADC_TRIGGER_SOURCE_IOC

IOC

ADC_TRIGGER_SOURCE_CLC1

CLC1

ADC_TRIGGER_SOURCE_CLC2

CLC2

ADC_TRIGGER_SOURCE_CLC3

CLC3

ADC_TRIGGER_SOURCE_CLC4

CLC4

ADC_TRIGGER_SOURCE_ADERRH

ADERRH

ADC_TRIGGER_SOURCE_ADRESH

ADRESH

ADC_TRIGGER_SOURCE_ADPCH

ADPCH

3.1.2.2.5 File Documentation

source/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/Sngle-Ended_Tasks/adc/adc.h File Reference

Enter a short description of your topic here (optional).

This is the start of your topic.

Functions

Detailed Description

ADC Generated Driver API Header File

source/Single-Ended_Interrupts/adc/adc_types.h File Reference

Enumerations

Detailed Description

ADC Type Definitions Header File

source/Single-Ended_Tasks/adc/adc_types.h File Reference

Enter a short description of your topic here (optional).

This is the start of your topic.

Enumerations

Detailed Description-types-task

ADC Type Definitions Header File

source/Single-Ended_Interrupts/adc/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 3.0.0 ADC Package Version 2.0.0

Variable Documentation

adc_busy_status

bool adc_busy_status[static]

ADC_ConversionDoneCallback

void(* ADC_ConversionDoneCallback) (void)[static]

ADC_ThresholdCallback

void(* ADC_ThresholdCallback) (void)[static]

source/Single-Ended_Tasks/adc/adc.c File Reference

Enter a short description of your topic here (optional).

This is the start of your topic.

Functions

Detailed Description

This file contains the API implementations for the ADC driver.

ADC Generated Driver File

Version: ADC Driver Version 3.0.0 ADC Package Version 2.0.0

Variable Documentation

adc_busy_status

bool adc_busy_status[static]

ADC_ConversionDoneCallback

void(* ADC_ConversionDoneCallback) (void)[static]

ADC_ThresholdCallback

void(* ADC_ThresholdCallback) (void)[static]