3.1.1.4 12-bit ADC
12-bit Analog-to-Digital Converter
3.1.1.4.1 Introduction
This Analog-to-Digital Converter (ADC) allows conversion of single-ended and differential analog input signals to a 12-bit binary representation of that signal. The analog inputs are multiplexed into a single Sample-and-Hold circuit. The converter then generates a 12-bit binary result via successive approximation and stores the conversion result into the ADC result registers.
3.1.1.4.2 Supported Device Families
PIC16(L)F178x |
3.1.1.4.3 Required Header Files:
#include "mcc_generated_files/adc/adc.h"
3.1.1.4.4 Module Documentation
ADC
This file contains the API prototypes and data types for the ADC driver.
Module description
This file contains the API prototypes and data types for the ADC driver.
Typedefs
typedef uint16_t adc_result_t
Used for the result of the Analog-to-Digital (A/D) conversion.
Definitions
#define ADC_Initialize ADC_Initialize
Defines the Custom Name for the ADC_Initialize API.
#define ADC_SetPositiveChannel ADC_SetPositiveChannel
Defines the Custom Name for the ADC_SetPositiveChannel API.
#define ADC_SetNegativeChannel ADC_SetNegativeChannel
Defines the Custom Name for the ADC_SetNegativeChannel API.
#define ADC_StartConversion ADC_StartConversion
Defines the Custom Name for the ADC_StartConversion API.
#define ADC_IsConversionDone ADC_IsConversionDone
Defines the Custom Name for the ADC_IsConversionDone API.
#define ADC_GetConversionResult ADC_GetConversionResult
Defines the Custom Name for the ADC_GetConversionResult API.
#define ADC_GetConversion ADC_GetConversion
Defines the Custom Name for the ADC_GetConversion API.
#define ADC_TemperatureAcquisitionDelay ADC_TemperatureAcquisitionDelay
Defines the Custom Name for the ADC_TemperatureAcquisitionDelay API.
#define ADC_ISR ADC_ISR
Defines the Custom Name for the ADC_ISR API.
#define ADC_SetInterruptHandler ADC_SetInterruptHandler
Defines the Custom Name for the ADC_SetInterruptHandler API.
Enumerations
enum adc_posChannel_t { posChannel_DAC4 = 0x18, posChannel_DAC3 = 0x19, posChannel_DAC2 = 0x1c, posChannel_Temperature = 0x1d, posChannel_DAC1 = 0x1e, posChannel_FVR = 0x1f, posChannel_AN0 = 0x0, posChannel_AN1 = 0x1, posChannel_AN2 = 0x2 }
Contains the available positive ADC channels.
enum adc_negChannel_t { negChannel_ADNREF = 0xf, negChannel_AN0 = 0x0, negChannel_AN1 = 0x1, negChannel_AN2 = 0x2 }
Contains the available negative ADC channels.
Functions
void ADC_Initialize (void)
Initializes the ADC module. This routine is called before any other ADC routine.
void ADC_SetPositiveChannel (adc_posChannel_t channel)
Sets the positive channel for the A/D conversion.
void ADC_SetNegativeChannel (adc_negChannel_t channel)
Sets the negative channel for the A/D conversion.
void ADC_StartConversion (void)
Starts the A/D conversion.
bool ADC_IsConversionDone (void)
Checks if the A/D conversion is complete.
adc_result_t ADC_GetConversionResult (void)
Retrieves the result of the latest A/D conversion.
adc_result_t ADC_GetConversion (adc_posChannel_t posChannel, adc_negChannel_t negChannel)
Retrieves the result of a single A/D conversion on the selected channels.
void ADC_TemperatureAcquisitionDelay (void)
Adds the acquisition delay for the temperature sensor.
void ADC_ISR (void)
Implements the ADC Interrupt (ADI) service routine for the interrupt-driven implementations.
void ADC_SetInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Interrupt (ADI).
Definition Documentation
ADC_GetConversion
#define ADC_GetConversion ADC_GetConversion
Defines the Custom Name for the ADC_GetConversion API.
ADC_GetConversionResult
#define ADC_GetConversionResult ADC_GetConversionResult
Defines the Custom Name for the ADC_GetConversionResult API.
ADC_Initialize
#define ADC_Initialize ADC_Initialize
Defines the Custom Name for the ADC_Initialize API.
ADC_IsConversionDone
#define ADC_IsConversionDone ADC_IsConversionDone
Defines the Custom Name for the ADC_IsConversionDone API.
ADC_ISR
#define ADC_ISR ADC_ISR
Defines the Custom Name for the ADC_ISR API.
ADC_SetInterruptHandler
#define ADC_SetInterruptHandler ADC_SetInterruptHandler
Defines the Custom Name for the ADC_SetInterruptHandler API.
ADC_SetNegativeChannel
#define ADC_SetNegativeChannel ADC_SetNegativeChannel
Defines the Custom Name for the ADC_SetNegativeChannel API.
ADC_SetPositiveChannel
#define ADC_SetPositiveChannel ADC_SetPositiveChannel
Defines the Custom Name for the ADC_SetPositiveChannel API.
ADC_StartConversion
#define ADC_StartConversion ADC_StartConversion
Defines the Custom Name for the ADC_StartConversion 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
ADC_GetConversion()
adc_result_t ADC_GetConversion (adc_posChannel_t posChannel, adc_negChannel_t negChannel)
Retrieves the result of a single A/D conversion on the selected channels.
posChannel |
- Postive analog channel number on which the A/D conversion will be applied. Refer to adc_posChannel_t for the available channels. |
negChannel |
- Negative analog channel number on which the A/D conversion will be applied. Refer to adc_negChannel_t for the available channels. |
The result of the A/D conversion. Refer to the adc_result_t. |
ADC_GetConversionResult()
adc_result_t ADC_GetConversionResult (void )
Retrieves the result of the latest A/D conversion.
None. |
The result of the A/D conversion. Refer to the adc_result_t. |
ADC_Initialize()
void ADC_Initialize (void )
Initializes the ADC module. This routine is called before any other ADC routine.
None. |
None. |
ADC_IsConversionDone()
bool ADC_IsConversionDone (void )
Checks if the A/D conversion is complete.
None. |
True |
- A/D conversion is complete |
False |
- A/D conversion is ongoing |
ADC_ISR()
void ADC_ISR (void )
Implements the ADC Interrupt (ADI) service routine for the interrupt-driven implementations.
None. |
None. |
ADC_SetInterruptHandler()
void ADC_SetInterruptHandler (void(*)(void) InterruptHandler)
Sets the callback for the ADC Interrupt (ADI).
InterruptHandler |
- Callback function to be called on the interrupt event |
None. |
ADC_SetNegativeChannel()
void ADC_SetNegativeChannel (adc_negChannel_t channel)
Sets the negative channel for the A/D conversion.
channel |
- Analog channel number on which the A/D conversion will be applied. Refer to adc_negChannel_t for the available channels. |
None. |
ADC_SetPositiveChannel()
void ADC_SetPositiveChannel (adc_posChannel_t channel)
Sets the positive channel for the A/D conversion.
channel |
- Analog channel number on which the A/D conversion will be applied. Refer to adc_posChannel_t for the available channels. |
None. |
ADC_StartConversion()
void ADC_StartConversion (void )
Starts the A/D conversion.
None. |
None. |
ADC_TemperatureAcquisitionDelay()
void ADC_TemperatureAcquisitionDelay (void )
Adds the acquisition delay for the temperature sensor.
Call this function when using the temperature sensor. |
None. |
None. |
Enumeration Type Documentation
adc_negChannel_t
enum adc_negChannel_t
Contains the available negative ADC channels.
negChannel_ADNREF | |
negChannel_AN0 | |
negChannel_AN1 | |
negChannel_AN2 |
adc_posChannel_t
enum adc_posChannel_t
Contains the available positive ADC channels.
posChannel_DAC4 | |
posChannel_DAC3 | |
posChannel_DAC2 | |
posChannel_Temperature | |
posChannel_DAC1 | |
posChannel_FVR | |
posChannel_AN0 | |
posChannel_AN1 | |
posChannel_AN2 |
3.1.1.4.5 Class Documentation
adc_sync_double_result_t Struct Reference
#include <adc.h>
Public Attributes
Member Data Documentation
adcResult1
adc_result_t adcResult1
adcResult2
adc_result_t adcResult2
Used Struct Reference
Detailed Description
result for a Double ADC conversion value.
The documentation for this struct was generated from the following file:
source/
3.1.1.4.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
static void ADC_DefaultInterruptHandler (void)
void ADC_Initialize (void)
Initializes the ADC module. This routine is called before any other ADC routine.
void ADC_SetPositiveChannel (adc_posChannel_t channel)
Sets the positive channel for the A/D conversion.
void ADC_SetNegativeChannel (adc_negChannel_t channel)
Sets the negative channel for the A/D conversion.
void ADC_StartConversion (void)
Starts the A/D conversion.
bool ADC_IsConversionDone (void)
Checks if the A/D conversion is complete.
adc_result_t ADC_GetConversionResult (void)
Retrieves the result of the latest A/D conversion.
adc_result_t ADC_GetConversion (adc_posChannel_t posChannel, adc_negChannel_t negChannel)
Retrieves the result of a single A/D conversion on the selected channels.
void ADC_TemperatureAcquisitionDelay (void)
Adds the acquisition delay for the temperature sensor.
void ADC_ISR (void)
Implements the ADC Interrupt (ADI) service routine for the interrupt-driven implementations.
void ADC_SetInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Interrupt (ADI).
Macros
#define ACQ_US_DELAY 5
Variables
static void(* ADC_InterruptHandler )(void)
Detailed Description
This file contains the API implementations for the ADC module.
ADC Generated Driver File
Function Documentation
ADC_DefaultInterruptHandler()
static void ADC_DefaultInterruptHandler (void )[static]
Macro Definition Documentation
ACQ_US_DELAY
#define ACQ_US_DELAY 5
Variable Documentation
ADC_InterruptHandler
void(* ADC_InterruptHandler) (void)[static]
source/adc.h File Reference
#include <xc.h> #include <stdint.h> #include <stdbool.h>
Data structures
struct adc_sync_double_result_t
Functions
void ADC_Initialize (void)
Initializes the ADC module. This routine is called before any other ADC routine.
void ADC_SetPositiveChannel (adc_posChannel_t channel)
Sets the positive channel for the A/D conversion.
void ADC_SetNegativeChannel (adc_negChannel_t channel)
Sets the negative channel for the A/D conversion.
void ADC_StartConversion (void)
Starts the A/D conversion.
bool ADC_IsConversionDone (void)
Checks if the A/D conversion is complete.
adc_result_t ADC_GetConversionResult (void)
Retrieves the result of the latest A/D conversion.
adc_result_t ADC_GetConversion (adc_posChannel_t posChannel, adc_negChannel_t negChannel)
Retrieves the result of a single A/D conversion on the selected channels.
void ADC_TemperatureAcquisitionDelay (void)
Adds the acquisition delay for the temperature sensor.
void ADC_ISR (void)
Implements the ADC Interrupt (ADI) service routine for the interrupt-driven implementations.
void ADC_SetInterruptHandler (void(*InterruptHandler)(void))
Sets the callback for the ADC Interrupt (ADI).
Macros
#define ADC_Initialize ADC_Initialize
Defines the Custom Name for the ADC_Initialize API.
#define ADC_SetPositiveChannel ADC_SetPositiveChannel
Defines the Custom Name for the ADC_SetPositiveChannel API.
#define ADC_SetNegativeChannel ADC_SetNegativeChannel
Defines the Custom Name for the ADC_SetNegativeChannel API.
#define ADC_StartConversion ADC_StartConversion
Defines the Custom Name for the ADC_StartConversion API.
#define ADC_IsConversionDone ADC_IsConversionDone
Defines the Custom Name for the ADC_IsConversionDone API.
#define ADC_GetConversionResult ADC_GetConversionResult
Defines the Custom Name for the ADC_GetConversionResult API.
#define ADC_GetConversion ADC_GetConversion
Defines the Custom Name for the ADC_GetConversion API.
#define ADC_TemperatureAcquisitionDelay ADC_TemperatureAcquisitionDelay
Defines the Custom Name for the ADC_TemperatureAcquisitionDelay API.
#define ADC_ISR ADC_ISR
Defines the Custom Name for the ADC_ISR API.
#define ADC_SetInterruptHandler ADC_SetInterruptHandler
Defines the Custom Name for the ADC_SetInterruptHandler API.
Typedefs
typedef uint16_t adc_result_t
Used for the result of the Analog-to-Digital (A/D) conversion.
Enumerations
enum adc_posChannel_t { posChannel_DAC4 = 0x18, posChannel_DAC3 = 0x19, posChannel_DAC2 = 0x1c, posChannel_Temperature = 0x1d, posChannel_DAC1 = 0x1e, posChannel_FVR = 0x1f, posChannel_AN0 = 0x0, posChannel_AN1 = 0x1, posChannel_AN2 = 0x2 }
Contains the available positive ADC channels.
enum adc_negChannel_t { negChannel_ADNREF = 0xf, negChannel_AN0 = 0x0, negChannel_AN1 = 0x1, negChannel_AN2 = 0x2 }
Contains the available negative ADC channels.