3.1.1.3 10-bit ADC with HW CVD

10-bit Analog-to-Digital-Converter with Hardware Capacitive Voltage Detection (CVD)

3.1.1.3.1 Introduction

This ADC module allows conversion of an analog input signal to a 10-bit binary representation of that signal. The analog inputs are multiplexed into a single Sample-and-Hold circuit. The converter then generates a 10-bit binary result via successive approximation and stores the conversion result into the ADC result registers. This ADC module also feature an auto-conversion trigger which allows periodic ADC measurements without software intervention and a hardware capacitive module divider (CVD) which can perform a relative capacitance measurement on any ADC channel using the internal ADC sample and hold capacitance as a reference.

3.1.1.3.2 Supported Device Families

PIC12/16LF155xPIC16LF156x

3.1.1.3.3 Required Header Files:

#include "mcc_generated_files/adc/adc.h"

3.1.1.3.4 Module Documentation

ADC

This file contains the API prototypes and data types for the Analog-to-Digital Converter ADC driver.

Module description

This file contains the API prototypes and data types for the Analog-to-Digital Converter ADC driver.

Version: ADC Driver Version 1.0.0
Typedefs
  • typedef uint16_t adc_result_t

    Used for the result of the Analog-to-Digital (A/D) conversion.

Definitions
Functions

Definition Documentation

ADC1_EnableDoubleSampling

#define ADC1_EnableDoubleSampling ADC1_EnableDoubleSampling

Defines the Custom Name for the ADC1_EnableDoubleSampling API.

ADC1_GetConversion

#define ADC1_GetConversion ADC1_GetConversion

Defines the Custom Name for the ADC1_GetConversion API.

ADC1_GetConversionResult

#define ADC1_GetConversionResult ADC1_GetConversionResult

Defines the Custom Name for the ADC1_GetConversionResult API.

ADC1_GetConversionStatus

#define ADC1_GetConversionStatus ADC1_GetConversionStatus

Defines the Custom Name for the ADC1_GetConversionStatus API.

ADC1_GetDoubleConversionResult

#define ADC1_GetDoubleConversionResult ADC1_GetDoubleConversionResult

Defines the Custom Name for the ADC1_GetDoubleConversionResult API.

ADC1_GetStageStatus

#define ADC1_GetStageStatus ADC1_GetStageStatus

Defines the Custom Name for the ADC1_GetStageStatus API.

ADC1_IsConversionDone

#define ADC1_IsConversionDone ADC1_IsConversionDone

Defines the Custom Name for the ADC1_IsConversionDone API.

ADC1_SetAcquisitionTime

#define ADC1_SetAcquisitionTime ADC1_SetAcquisitionTime

Defines the Custom Name for the ADC1_SetAcquisitionTime API.

ADC1_SetInterruptHandler

#define ADC1_SetInterruptHandler ADC1_SetInterruptHandler

Defines the Custom Name for the ADC1_SetInterruptHandler API.

ADC1_SetPrechargeTime

#define ADC1_SetPrechargeTime ADC1_SetPrechargeTime

Defines the Custom Name for the ADC1_SetPrechargeTime API.

ADC1_StartConversion

#define ADC1_StartConversion ADC1_StartConversion

Defines the Custom Name for the ADC1_StartConversion API.

ADC2_EnableDoubleSampling

#define ADC2_EnableDoubleSampling ADC2_EnableDoubleSampling

Defines the Custom Name for the ADC2_EnableDoubleSampling API.

ADC2_GetConversion

#define ADC2_GetConversion ADC2_GetConversion

Defines the Custom Name for the ADC2_GetConversion API.

ADC2_GetConversionResult

#define ADC2_GetConversionResult ADC2_GetConversionResult

Defines the Custom Name for the ADC2_GetConversionResult API.

ADC2_GetConversionStatus

#define ADC2_GetConversionStatus ADC2_GetConversionStatus

Defines the Custom Name for the ADC2_GetConversionStatus API.

ADC2_GetDoubleConversionResult

#define ADC2_GetDoubleConversionResult ADC2_GetDoubleConversionResult

Defines the Custom Name for the ADC2_GetDoubleConversionResult API.

ADC2_GetStageStatus

#define ADC2_GetStageStatus ADC2_GetStageStatus

Defines the Custom Name for the ADC2_GetStageStatus API.

ADC2_IsConversionDone

#define ADC2_IsConversionDone ADC2_IsConversionDone

Defines the Custom Name for the ADC2_IsConversionDone API.

ADC2_SetAcquisitionTime

#define ADC2_SetAcquisitionTime ADC2_SetAcquisitionTime

Defines the Custom Name for the ADC2_SetAcquisitionTime API.

ADC2_SetInterruptHandler

#define ADC2_SetInterruptHandler ADC2_SetInterruptHandler

Defines the Custom Name for the ADC2_SetInterruptHandler API.

ADC2_SetPrechargeTime

#define ADC2_SetPrechargeTime ADC2_SetPrechargeTime

Defines the Custom Name for the ADC2_SetPrechargeTime API.

ADC2_StartConversion

#define ADC2_StartConversion ADC2_StartConversion

Defines the Custom Name for the ADC2_StartConversion API.

ADC_GetSyncConversion

#define ADC_GetSyncConversion ADC_GetSyncConversion

Defines the Custom Name for the ADC_GetSyncConversion API.

ADC_GetSyncConversionResult

#define ADC_GetSyncConversionResult ADC_GetSyncConversionResult

Defines the Custom Name for the ADC_GetSyncConversionResult API.

ADC_Initialize

#define ADC_Initialize ADC_Initialize

Defines the Custom Name for the ADC_Initialize API.

ADC_IsSyncConversionDone

#define ADC_IsSyncConversionDone ADC_IsSyncConversionDone

Defines the Custom Name for the ADC_IsSyncConversionDone API.

ADC_StartSyncConversion

#define ADC_StartSyncConversion ADC_StartSyncConversion

Defines the Custom Name for the ADC_StartSyncConversion API.

ADC_TemperatureAcquisitionDelay

#define ADC_TemperatureAcquisitionDelay ADC_TemperatureAcquisitionDelay

Defines the Custom Name for the ADC_TemperatureAcquisitionDelay API.

Typedef Documentation

adc_result_t

adc_result_t

Used for the result of the Analog-to-Digital (A/D) conversion.

Function Documentation

ADC1_EnableDoubleSampling()

void ADC1_EnableDoubleSampling (void )

This routine is used to enable a double conversion on the same channel on the ADC1. The converted result result will be stored in two different 10-bit result registers.

Parameters:
None.
Returns:

None.

ADC1_GetConversion()

adc_result_t ADC1_GetConversion (adc1_channel_t channel)

Retrieves the result of a single ADC1 conversion on any given channel.

Parameters:
channel

- Analog channel number on which the ADC1 conversion will be applied. Refer to adc1_channel_t for the available channels

Returns:

The result of the ADC1 conversion. Refer to the adc_result_t

ADC1_GetConversionResult()

adc_result_t ADC1_GetConversionResult (void )

Retrieves the result of the latest ADC1 conversion.

Parameters:
None.
Returns:

The result of the ADC1 conversion. Refer to the adc_result_t

ADC1_GetConversionStatus()

uint8_t ADC1_GetConversionStatus (void )

Returns the ADC1 conversion status.

Parameters:
None.
Returns:

The result of the ADC1 conversion status

ADC1_GetDoubleConversionResult()

adc1_double_result_t ADC1_GetDoubleConversionResult (void )

Returns the ADC1 double conversion result. This routine is used to get the analog-to-digital converted values. The converted result will be stored in two different 10-bit result registers.

Parameters:
None.
Returns:

The result of the ADC1 double conversion. Refer to the adc1_double_result_t

ADC1_GetStageStatus()

uint8_t ADC1_GetStageStatus (void )

Returns the ADC1 conversion stage.

Parameters:
None.
Returns:

The result of the ADC1 conversion stage

ADC1_IsConversionDone()

bool ADC1_IsConversionDone (void )

Checks if the ongoing ADC1 conversion is complete.

Parameters:
None.
Return values:
True

- A/D conversion is complete

False

- A/D conversion is ongoing

ADC1_ISR()

void ADC1_ISR (void )

Implements the ADC interrupt (AD1I) service routine for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC1_SetAcquisitionTime()

void ADC1_SetAcquisitionTime (uint8_t acquisitionValue)

Loads the ADC1 Acquisition time by the 8-bit value sent as argument. This routine sets the desired Acquisition time.

Parameters:
acquisitionValue

- 8-bit value to be set in the Acquisition register

Returns:

None.

ADC1_SetInterruptHandler()

void ADC1_SetInterruptHandler (void(*)(void) InterruptHandler)

Sets the callback for the ADC interrupt (AD1I).

Parameters:
InterruptHandler

- Callback function to be called on the interrupt event

Returns:

None.

ADC1_SetPrechargeTime()

void ADC1_SetPrechargeTime (uint8_t prechargeTime)

Loads the ADC1 Precharge register by the 8-bit value sent as argument. This routine sets the desired precharge time to charge.

Parameters:
prechargeTime

- 8-bit value to be set in the Precharge register

Returns:

None.

ADC1_StartConversion()

void ADC1_StartConversion (adc1_channel_t channel)

Allows the selection of an ADC1 channel for conversion. This routine starts the A/D conversion.

Parameters:
channel

- Analog channel number on which the A/D conversion will be applied. Refer to adc1_channel_t for the available channels

Returns:

None.

ADC2_EnableDoubleSampling()

void ADC2_EnableDoubleSampling (void )

This routine is used to enable a double conversion on the same channel on the ADC2. The converted result result will be stored in two different 10-bit result registers.

Parameters:
None.
Returns:

None.

ADC2_GetConversion()

adc_result_t ADC2_GetConversion (adc2_channel_t channel)

Retrieves the result of a single ADC2 conversion on any given channel.

Parameters:
channel

- Analog channel number on which the ADC2 conversion will be applied. Refer to adc2_channel_t for the available channels

Returns:

The result of the ADC2 conversion. Refer to the adc_result_t

ADC2_GetConversionResult()

adc_result_t ADC2_GetConversionResult (void )

Retrieves the result of the latest ADC2 conversion.

Parameters:
None.
Returns:

The result of the ADC2 conversion. Refer to the adc_result_t

ADC2_GetConversionStatus()

uint8_t ADC2_GetConversionStatus (void )

Returns the ADC2 conversion status.

Parameters:
None.
Returns:

The result of the ADC2 conversion status

ADC2_GetDoubleConversionResult()

adc2_double_result_t ADC2_GetDoubleConversionResult (void )

Returns the ADC2 double conversion result. This routine is used to get the analog-to-digital converted values. The converted result will be stored in two different 10-bit result registers.

Parameters:
None.
Returns:

The result of the ADC2 double conversion. Refer to the adc2_double_result_t

ADC2_GetStageStatus()

uint8_t ADC2_GetStageStatus (void )

Returns the ADC2 conversion stage.

Parameters:
None.
Returns:

The result of ADC2 conversion stage

ADC2_IsConversionDone()

bool ADC2_IsConversionDone (void )

Checks if the ongoing ADC2 conversion is complete.

Parameters:
None.
Return values:
True

- A/D conversion is complete

False

- A/D conversion is ongoing

ADC2_ISR()

void ADC2_ISR (void )

Implements the ADC interrupt (AD2I) service routine for the interrupt-driven implementations.

Parameters:
None.
Returns:

None.

ADC2_SetAcquisitionTime()

void ADC2_SetAcquisitionTime (uint8_t acquisitionValue)

Loads the ADC2 Acquisition time by the 8-bit value sent as argument. This routine sets the desired Acquisition time.

Parameters:
acquisitionValue

- 8-bit value to be set in the Acquisition register

Returns:

None.

ADC2_SetInterruptHandler()

void ADC2_SetInterruptHandler (void(*)(void) InterruptHandler)

Sets the callback for the ADC interrupt (AD2I).

Parameters:
InterruptHandler

- Callback function to be called on the interrupt event

Returns:

None.

ADC2_SetPrechargeTime()

void ADC2_SetPrechargeTime (uint8_t prechargeTime)

Loads the ADC2 Precharge register by the 8-bit value sent as argument. This routine sets the desired precharge time to charge.

Parameters:
prechargeTime

- 8-bit value to be set in the Precharge register

Returns:

None.

ADC2_StartConversion()

void ADC2_StartConversion (adc2_channel_t channel)

Allows the selection of an ADC2 channel for conversion. This routine starts the A/D conversion.

Parameters:
channel

- Analog channel number on which the A/D conversion will be applied. Refer to adc2_channel_t for the available channels

Returns:

None.

ADC_GetSyncConversion()

adc_sync_result_t ADC_GetSyncConversion (adc1_channel_t adc1Channel, adc2_channel_t adc2Channel)

Retrieves the result of a synchronized conversion on any given channel.

Parameters:
adc1Channel

- Analog channel number on which the ADC1 conversion will be applied. Refer to adc1_channel_t for the available channels

adc2Channel

- Analog channel number on which the ADC2 conversion will be applied. Refer to adc2_channel_t for the available channels

Returns:

The result of synchronized conversion. Refer to the adc_sync_result_t

ADC_GetSyncConversionResult()

adc_sync_result_t ADC_GetSyncConversionResult (void )

Retrieves the result of the latest synchronized conversion.

Parameters:
None.
Returns:

The result of the synchronized conversion. Refer to the adc_sync_result_t

ADC_Initialize()

void ADC_Initialize (void )

Initializes the ADC module. This routine is called before any other ADC routine.

Parameters:
None.
Returns:

None.

ADC_IsSyncConversionDone()

bool ADC_IsSyncConversionDone (void )

Checks if the ongoing synchronized conversion is complete.

Parameters:
None.
Return values:
True

- synchronized conversion is complete

False

- synchronized conversion is ongoing

ADC_StartSyncConversion()

void ADC_StartSyncConversion (adc1_channel_t channelADC1, adc2_channel_t channelADC2)

Allows the selection of two channels for synchronized conversion. This routine starts the A/D synchronized conversion.

Parameters:
channelADC1

- ADC1 analog channel number on which the A/D conversion will be applied. Refer to adc1_channel_t for the available channels

channelADC2

- ADC2 analog channel number on which the A/D conversion will be applied. Refer to adc2_channel_t for the available channels

Returns:

None.

ADC_TemperatureAcquisitionDelay()

void ADC_TemperatureAcquisitionDelay (void )

Adds the acquisition delay for the temperature sensor.

Precondition:

This function is called when a temperature sensor is used.

Parameters:
None.
Returns:

None.

Enumeration Type Documentation

adc1_channel_t

enum adc1_channel_t

Contains the available ADC1 channels.

channel_VREFH_adc1
channel_Temp_adc1
channel_FVR_adc1
adc2_channel_t

enum adc2_channel_t

Contains the available ADC2 channels.

channel_VREFH_adc2
channel_Temp_adc2
channel_FVR_adc2

3.1.1.3.5 Class Documentation

adc1_double_result_t Struct Reference

#include <adc.h>

Member Data Documentation

The documentation for this struct was generated from the following file:

source/

adc.h

adc1Result1

adc_result_t adc1Result1

adc1Result2

adc_result_t adc1Result2

adc2_double_result_t Struct Reference

#include <adc.h>

Member Data Documentation

The documentation for this struct was generated from the following file:

source/

adc.h

adc2Result1

adc_result_t adc2Result1

adc2Result2

adc_result_t adc2Result2

adc_sync_result_t Struct Reference

#include <adc.h>

Member Data Documentation

The documentation for this struct was generated from the following file:

source/

adc.h

adc1Result

adc_result_t adc1Result

adc2Result

adc_result_t adc2Result

Used Struct Reference

Detailed Description

result for a synchronized ADC conversion value.

result for a Double ADC1 conversion value.

result for a Double ADC2 conversion value.

The documentation for this struct was generated from the following file:

source/

adc.h

3.1.1.3.6 File Documentation

source/adc.c File Reference

This file contains the API implementations for the ADC module.

#include <xc.h>
#include "../adc.h"
#include "../../system/clock.h"

Functions

Detailed Description

This file contains the API implementations for the ADC module.

ADC Generated Driver File

Version: ADC Driver Version 1.0.0

Function Documentation

ADC_DefaultInterruptHandler()

static void ADC_DefaultInterruptHandler (void )[static]

Macro Definition Documentation

ACQ_US_DELAY

#define ACQ_US_DELAY 5

Variable Documentation

ADC1_InterruptHandler

void(* ADC1_InterruptHandler) (void)

ADC2_InterruptHandler

void(* ADC2_InterruptHandler) (void)

source/adc.h File Reference

#include <xc.h>
#include <stdint.h>
#include <stdbool.h>

Functions

Macros

Typedefs

  • typedef uint16_t adc_result_t

    Used for the result of the Analog-to-Digital (A/D) conversion.

Detailed Description

ADC Generated Driver API Header File