3.1.1.1 10-bit ADC
10-bit Analog-to-Digital Converter
3.1.1.1.1 Introduction
The Analog-to-Digital Converter (ADC) allows conversion of single-ended and differential analog input signals 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.
3.1.1.1.2 Supported Device Families
PIC18F-K20 | PIC18(L)F-K22 | PIC18(L)F-K50 |
3.1.1.1.3 Required Header Files:
#include "mcc_generated_files/adc/adc.h"
3.1.1.1.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.
Enumerations
enum adc_channel_t { posChannel_FVR = 0xf }
Contains the available ADC channels.
enum adc_posChannel_t { posChannel_CTMU = 0x1c, posChannel_Temp_diode = 0x1d, posChannel_Vdd_core = 0x1e, posChannel_1_024V_bandgap = 0x1f }
Contains the available ADC channels.
enum adc_negChannel_t { negChannel_AVss = 0x0 }
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_SelectChannel (adc_channel_t channel)
Selects the channel for the A/D conversion.
void ADC_StartConversion (void)
Starts A/D conversion.
bool ADC_IsConversionDone (void)
Checks if ongoing A/D conversion is complete.
adc_result_t ADC_GetConversionResult (void)
Retrieves the result of the latest A/D conversion.
adc_result_t ADC_GetConversion (adc_channel_t channel)
Retrieves the result of a single A/D conversion on any given channel.
void ADC_TemperatureAcquisitionDelay (void)
Adds the acquisition delay for the temperature sensor.
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.
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.
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_channel_t channel)
Retrieves the result of a single A/D conversion on any given channel.
channel |
- Analog channel number on which the A/D conversion will be applied. Refer to adc_channel_t for the available channels. |
The result of A/D conversion. Refer to the adc_result_t. |
ADC_GetConversion() with Negative Channel
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 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. |
None. |
None. |
ADC_IsConversionDone()
bool ADC_IsConversionDone (void )
Checks if ongoing A/D conversion is complete.
None. |
True |
- A/D conversion is complete. |
False |
- A/D conversion is ongoing. |
ADC_SelectChannel()
void ADC_SelectChannel (adc_channel_t channel)
Selects the channel for the A/D conversion.
channel |
- Analog channel number on which the A/D conversion will be applied. Refer to adc_channel_t for the available channels. |
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 A/D conversion.
None. |
None. |
ADC_TemperatureAcquisitionDelay()
void ADC_TemperatureAcquisitionDelay (void )
Adds the acquisition delay for the temperature sensor.
This function is called when temperature sensor is used. |
None. |
None. |
Enumeration Type Documentation
adc_channel_t
enum adc_channel_t
Contains the available ADC channels.
posChannel_FVR |
adc_negChannel_t
enum adc_negChannel_t
Contains the available negative ADC channels.
negChannel_AVss |
adc_posChannel_t
enum adc_posChannel_t
Contains the available ADC channels.
posChannel_CTMU | |
posChannel_Temp_diode | |
posChannel_Vdd_core | |
posChannel_1_024V_bandgap |
3.1.1.1.5 Class Documentation
adc_sync_double_result_t Struct Reference
#include <adc.h>
Public Attributes
Member Data Documentation
The documentation for this struct was generated from the following files:
source/
source/
adcResult1
adc_result_t adcResult1
adcResult2
adc_result_t adcResult2
3.1.1.1.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
void ADC_Initialize (void)
Initializes the ADC module. This routine is called before any other ADC routine.
void ADC_SelectChannel (adc_channel_t channel)
Selects the channel for the A/D conversion.
void ADC_StartConversion (void)
Starts A/D conversion.
bool ADC_IsConversionDone (void)
Checks if ongoing A/D conversion is complete.
adc_result_t ADC_GetConversionResult (void)
Retrieves the result of the latest A/D conversion.
adc_result_t ADC_GetConversion (adc_channel_t channel)
Retrieves the result of a single A/D conversion on any given channel.
void ADC_TemperatureAcquisitionDelay (void)
Adds the acquisition delay for the temperature sensor.
Macros
#define ACQ_US_DELAY 8
Detailed Description
This file contains the API implementations for the ADC module.
ADC Generated Driver File
Macro Definition Documentation
ACQ_US_DELAY
#define ACQ_US_DELAY 8
Section: Included Files Section: Macro Declarations
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_SelectChannel (adc_channel_t channel)
Selects the channel for the A/D conversion.
void ADC_StartConversion (void)
Starts A/D conversion.
bool ADC_IsConversionDone (void)
Checks if ongoing A/D conversion is complete.
adc_result_t ADC_GetConversionResult (void)
Retrieves the result of the latest A/D conversion.
adc_result_t ADC_GetConversion (adc_channel_t channel)
Retrieves the result of a single A/D conversion on any given channel.
void ADC_TemperatureAcquisitionDelay (void)
Adds the acquisition delay for the temperature sensor.
Typedefs
typedef uint16_t adc_result_t
Used for the result of the Analog-to-Digital (A/D) conversion.
Enumerations
enum adc_channel_t { posChannel_FVR = 0xf }
Contains the available ADC channels.
Detailed Description
ADC Generated Driver API Header File
source/adc_wNegChannel.c File Reference
#include <xc.h> #include "../adc.h" #include "../../system/clock.h"
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 A/D conversion.
bool ADC_IsConversionDone (void)
Checks if ongoing A/D conversion is complete.
adc_result_t ADC_GetConversionResult (void)
Retrieves the result of the latest A/D conversion.
adc_result_t ADC_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.
Macros
#define ACQ_US_DELAY 8
Macro Definition Documentation
ACQ_US_DELAY
#define ACQ_US_DELAY 8
Section: Included Files Section: Macro Declarations
source/adc_wNegChannel.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 A/D conversion.
bool ADC_IsConversionDone (void)
Checks if ongoing A/D conversion is complete.
adc_result_t ADC_GetConversionResult (void)
Retrieves the result of the latest A/D conversion.
adc_result_t ADC_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.
Typedefs
typedef uint16_t adc_result_t
Enumerations
enum adc_posChannel_t { posChannel_CTMU = 0x1c, posChannel_Temp_diode = 0x1d, posChannel_Vdd_core = 0x1e, posChannel_1_024V_bandgap = 0x1f }
Contains the available ADC channels.
enum adc_negChannel_t { negChannel_AVss = 0x0 }
Contains the available negative ADC channels.
Typedef Documentation
adc_result_t
typedef uint16_t adc_result_t