3.1 ADC Driver
Overview
The High Speed 12-bit Analog-to-Digital Converter (ADC) features low conversion latency, high resolution and oversampling capabilities to improve performance in AC/DC, DC/DC power converters.
Features
- Multiple single channel dedicated ADC cores (depending on the specific device implementation) which allows for simultaneous sampling.
- One shared (common) ADC core with sequential sampling.
- Voltage reference of AVdd for positive reference and AVss for negative reference is supported.
- Up to 3.5 Msps Conversion Rate per Channel at 12-Bit Resolution.
- Low-Latency Conversion.
- Up to 24 (Depending on the hardware capability) Analog Input Channels, with a Separate 16-Bit Conversion Result Register for each Input.
- Conversion Result Formatted as UnsignedData on a per Channel basis.
- Multiple Conversion Trigger Options for each Core.
- Up to Four Integrated Digital Comparators with Dedicated Interrupts and multiple comparison options assignable to specific analog inputs.
- The adc channels are configurable from the table in the GUI.
- Users can configure the comparators selected in the channel table via the Comparator Table.
- The Clock and Divider settings for ADC can be configured in the PLIB dependency of the driver module.
3.1.1 How to use the ADC Usecases
The ADC 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.
Instructions common for all code snippets can be found here: 3.1.5.1.1 ADC Use Case Code Snippet Instructions
- 3.1.5.1.2 ADC Use Case 1: ADC in Basic_mode with Printf of ADC Result An ADC conversion is taken every 100 ms, on the selected analog channel. After each ADC conversion a LED is toggled and the ADC Result is sent to the PC terminal using printf.
- 3.1.5.1.3 ADC Use Case 2: ADC Samples Visualized with the Data Streamer An ADC conversion is taken, on the selected analog channel, every 100 ms. ADC converstions are triggerd by an timer overflow callback, where the Data Streamer variables, adcResult, and adcSampleCount are updated.
3.1.2 Module Documentation
3.1.2.1 ADC Driver
12-bit Analog-to-Digital Converters (ADC) that feature low conversion latency, high resolution and oversampling capabilities to improve performance.
3.1.2.1.1 Module description
12-bit Analog-to-Digital Converters (ADC) that feature low conversion latency, high resolution and oversampling capabilities to improve performance.
Data structures
struct ADC_INTERFACE
Structure containing the function pointers of ADC driver.
struct ADC_MULTICORE
Structure containing the function pointers of ADC driver.
Definitions
#define ADC1_RESOLUTION 12
Defines the ADC Resolution.
#define ADC_POWER_ENABLE_FEATURE_AVAILABLE 1
This macro defines the ADC core power enable functionality.
#define ADC_CALIBRATION_FEATURE_AVAILABLE 1
This macro defines the macro associated with ADC core calibration.
#define ADC_INDIVIDUAL_CHANNEL_INTERRUPT_FEATURE_AVAILABLE 1
Defines the macro associated with ADC indvidual channel interrupts.
#define ADC_COMPARATOR_FEATURE_AVAILABLE 1
Defines the macro associated with ADC comparator feature.
#define ADC_INDIVIDUAL_SOFTWARE_TRIGGER_FEATURE_AVAILABLE 1
Defines the macro associated with individual channel software trigger feature.
#define ADC_SECONDARY_ACCUMULATOR_FEATURE_AVAILABLE 1
Defines the macro associated with secondary accumulator feature.
Enumerations
enum ADC1_CHANNEL { ADC1_Channel0, ADC1_Channel1, ADC1_Channel2, ADC1_Channel19, ADC1_MAX_CHANNELS = 4 }
Defines the ADC channles that are selected from the MCC Melody User Interface for the ADC conversions.
enum ADC_DEDICATED_CORE { ADC_MAX_DEDICATED_CORES = 0 }
Defines the ADC cores that are available for the module to use.
enum ADC_RESOLUTION_TYPE { ADC_12_BIT_RESOLUTION }
Defines the supported ADC resolution types.
enum ADC_PWM_INSTANCE { ADC_PWM_GENERATOR_4, ADC_PWM_GENERATOR_3 }
Defines the ADC PWM trigger sources that are available for the module to use.
enum ADC_PWM_TRIGGERS { ADC_PWM_TRIGGER_1 = 1, ADC_PWM_TRIGGER_2 = 2 }
Defines the PWM triggers that are available in each individual PWM.
Functions
void ADC1_Initialize (void)
Initializes ADC1 module, using the given initialization data This function must be called before any other ADC1 function is called.
void ADC1_Deinitialize (void)
Deinitializes the ADC1 to POR values.
static void ADC1_Enable (void)
This inline function enables the ADC1 module.
static void ADC1_Disable (void)
This inline function disables the ADC1 module.
static void ADC1_SoftwareTriggerEnable (void)
This inline function sets software common trigger.
static void ADC1_SoftwareTriggerDisable (void)
This inline function resets software common trigger.
static void ADC1_ChannelSoftwareTriggerEnable (const enum ADC1_CHANNEL channel)
This inline function sets individual software trigger.
static void ADC1_ChannelSoftwareTriggerDisable (const enum ADC1_CHANNEL channel)
This inline function clears individual software trigger.
static uint16_t ADC1_SampleCountGet (const enum ADC1_CHANNEL channel)
This inline function returns the requested conversion count.
static uint16_t ADC1_SampleCountStatusGet (const enum ADC1_CHANNEL channel)
This inline function returns the status of completed conversion count.
static uint32_t ADC1_ConversionResultGet (const enum ADC1_CHANNEL channel)
Returns the conversion value for the channel selected.
static uint32_t ADC1_SecondaryAccumulatorGet (const enum ADC1_CHANNEL channel)
Returns secondary accumulator conversion value for the channel selected.
static bool ADC1_IsConversionComplete (const enum ADC1_CHANNEL channel)
This inline function returns the status of conversion.This function is used to determine if conversion is completed. When conversion is complete the function returns true otherwise false.
static void ADC1_IndividualChannelInterruptEnable (const enum ADC1_CHANNEL channel)
This inline function enables individual channel interrupt.
static void ADC1_IndividualChannelInterruptDisable (const enum ADC1_CHANNEL channel)
This inline function disables individual channel interrupt.
static void ADC1_IndividualChannelInterruptFlagClear (const enum ADC1_CHANNEL channel)
This inline function clears individual channel interrupt flag.
static void ADC1_IndividualChannelInterruptPrioritySet (const enum ADC1_CHANNEL channel, enum INTERRUPT_PRIORITY priorityValue)
This inline function allows selection of priority for individual channel interrupt.
void ADC1_ChannelCallbackRegister (void(*callback)(const enum ADC1_CHANNEL channel, uint16_t adcVal))
This function can be used to override default callback ADC1_ChannelCallback and to define custom callback for ADC1 Channel event. Read the conversion result of the corresponding channel in the custom callback.
void ADC1_ChannelCallback (const enum ADC1_CHANNEL channel, uint16_t adcVal)
This is the default callback function for all the analog channels. This callback is triggered once the channel conversion is done for a channel and to read the conversion result of the corresponding channel.
void ADC1_Result32BitChannelCallbackRegister (void(*callback)(const enum ADC1_CHANNEL channel, uint32_t adcVal))
This function can be used to override default callback ADC1_Result32BitChannelCallback and to define custom callback for ADC1 Channel event.
void ADC1_Result32BitChannelCallback (const enum ADC1_CHANNEL channel, uint32_t adcVal)
This is the default callback function for all the analog channels. This callback is triggered once the channel conversion is done for a channel and to read the conversion result of the corresponding channel.
void ADC1_ComparatorCallbackRegister (void(*callback)(const enum ADC1_CMP comparator))
This function can be used to override default callback and to define custom callback for ADC1_Comparator event.
void ADC1_ComparatorCallback (const enum ADC1_CMP comparator)
Comparator callback function.
void ADC1_ChannelTasks (const enum ADC1_CHANNEL channel)
This function call used only in polling mode, if channel conversion is done for requested channel, the calls the respective callback function.
void ADC1_ComparatorTasks (const enum ADC1_CMP comparator)
Used to implement the tasks for polled implementations of Comparators.
void ADC1_SharedCorePowerEnable (void)
Enables power for ADC1 Core This function is used to set the analog and digital power for ADC1 shared Core.
void ADC1_SharedCoreCalibration (void)
Calibrates the ADC1 Core.
void ADC1_PWMTriggerSourceSet (const enum ADC1_CHANNEL channel, enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber)
Sets PWM trigger source for corresponding analog input.
Variables
const struct ADC_INTERFACE ADC1
Structure object of type ADC_INTERFACE with the custom name given by the user in the Melody Driver User interface. The default name e.g. ADC1 can be changed by the user in the ADC user interface. This allows defining a structure with application specific name using the 'Custom Name' field. Application specific name allows the API Portability.
3.1.2.1.2 Definition Documentation
ADC1_RESOLUTION
#define ADC1_RESOLUTION 12
Defines the ADC Resolution.
ADC_CALIBRATION_FEATURE_AVAILABLE
#define ADC_CALIBRATION_FEATURE_AVAILABLE 1
This macro defines the macro associated with ADC core calibration.
APIs Supported:
void ADCx_CoreCalibration (enum ADC_CHANNEL channel); void ADC_SharedCoreCalibration (void);x denotes instance of ADC in ADCx, channel denotes dedicated Core. Refer to device specific datasheet to check number of cores and ADC module instance. Refer driver header file for detailed description of the APIs.
ADC_COMPARATOR_FEATURE_AVAILABLE
#define ADC_COMPARATOR_FEATURE_AVAILABLE 1
Defines the macro associated with ADC comparator feature.
APIs Supported:
void ADCx_ComparatorEnable(void); void ADCx_ComparatorDisable(void); void ADCx_ComparatorLowThresholdSet(uint16_t threshold ); void ADCx_ComparatorHighThresholdSet(uint16_t threshold ); uint16_t ADCx_ComparatorEventStatusGet(void); uint16_t ADCx_ComparatorEventChannelGet(void);x denotes instance of ADC in ADCx. Refer to device specific datasheet to check number of comparators and ADC module instance. Refer driver header file for detailed description of the APIs.
ADC_INDIVIDUAL_CHANNEL_INTERRUPT_FEATURE_AVAILABLE
#define ADC_INDIVIDUAL_CHANNEL_INTERRUPT_FEATURE_AVAILABLE 1
Defines the macro associated with ADC indvidual channel interrupts.
APIs Supported:
void ADCx_IndividualChannelInterruptEnable (enum ADC_CHANNEL channel); void ADCx_IndividualChannelInterruptDisable (enum ADC_CHANNEL channel); void ADCx_IndividualChannelInterruptFlagClear (enum ADC_CHANNEL channel);x denotes instance of ADC, channel denotes dedicated ADC channel. Refer to device specific datasheet to check number of cores and ADC module instance. Refer driver header file for detailed description of the APIs.
ADC_INDIVIDUAL_SOFTWARE_TRIGGER_FEATURE_AVAILABLE
#define ADC_INDIVIDUAL_SOFTWARE_TRIGGER_FEATURE_AVAILABLE 1
Defines the macro associated with individual channel software trigger feature.
APIs Supported:
void ADCx_ChannelSoftwareTriggerEnable(enum ADC_CHANNEL channel); void ADCx_ChannelSoftwareTriggerDisable(enum ADC_CHANNEL channel);x denotes instance of ADC in ADCx. Refer to device specific datasheet to check number of comparators and ADC module instance. Refer driver header file for detailed description of the APIs.
ADC_POWER_ENABLE_FEATURE_AVAILABLE
#define ADC_POWER_ENABLE_FEATURE_AVAILABLE 1
This macro defines the ADC core power enable functionality.
APIs Supported:
void ADCx_CorePowerEnable (enum ADC_CHANNEL channel); void ADC_SharedCorePowerEnable (void);x denotes instance of ADC in ADCx, channel denotes dedicated Core. Refer to device specific datasheet to check number of cores and ADC module instance. Refer driver header file for detailed description of the APIs.
ADC_SECONDARY_ACCUMULATOR_FEATURE_AVAILABLE
#define ADC_SECONDARY_ACCUMULATOR_FEATURE_AVAILABLE 1
Defines the macro associated with secondary accumulator feature.
APIs Supported:
void ADCx_SecondaryAccumulatorGet(enum ADC_CHANNEL channel);x denotes instance of ADC in ADCx. Refer to device specific datasheet to check number of comparators and ADC module instance. Refer driver header file for detailed description of the APIs.
3.1.2.1.3 Function Documentation
ADC1_ChannelCallback()
void ADC1_ChannelCallback (const enum ADC1_CHANNEL channel, uint16_t adcVal)
This is the default callback function for all the analog channels. This callback is triggered once the channel conversion is done for a channel and to read the conversion result of the corresponding channel.
none |
in | channel |
- conversion completed channel |
in | adcVal |
- conversion result of channel |
none |
ADC1_ChannelCallbackRegister()
void ADC1_ChannelCallbackRegister (void(*)(const enum ADC1_CHANNEL channel, uint16_t adcVal) callback)
This function can be used to override default callback ADC1_ChannelCallback and to define custom callback for ADC1 Channel event. Read the conversion result of the corresponding channel in the custom callback.
none |
in | callback |
- Address of the callback function. |
none |
ADC1_ChannelSoftwareTriggerDisable()
inline static void ADC1_ChannelSoftwareTriggerDisable (const enum ADC1_CHANNEL channel)
This inline function clears individual software trigger.
none |
in | channel |
- Channel for conversion |
none |
ADC1_ChannelSoftwareTriggerEnable()
inline static void ADC1_ChannelSoftwareTriggerEnable (const enum ADC1_CHANNEL channel)
This inline function sets individual software trigger.
none |
in | channel |
- Channel for conversion none |
none |
ADC1_ChannelTasks()
void ADC1_ChannelTasks (const enum ADC1_CHANNEL channel)
This function call used only in polling mode, if channel conversion is done for requested channel, the calls the respective callback function.
ADC1_Initialize() function should have been called before calling this function. |
in | channel |
- Selected channel. |
none |
This function has to be polled to notify channel callbacks and clear the channel interrupt flags in non-interrupt mode of ADC
ADC1_ComparatorCallback()
void ADC1_ComparatorCallback (const enum ADC1_CMP comparator)
Comparator callback function.
none |
in | comparator |
- comparator in which compare event occurred |
none |
ADC1_ComparatorCallbackRegister()
void ADC1_ComparatorCallbackRegister (void(*)(const enum ADC1_CMP comparator) callback)
This function can be used to override default callback and to define custom callback for ADC1_Comparator event.
none |
in | callback |
- Address of the callback function. |
none |
ADC1_ComparatorTasks()
void ADC1_ComparatorTasks (const enum ADC1_CMP comparator)
Used to implement the tasks for polled implementations of Comparators.
ADC1_Initialize() function should have been called before calling this function. |
in | comparator |
- Selected Comparator. |
none |
ADC1_ConversionResultGet()
inline static uint32_t ADC1_ConversionResultGet (const enum ADC1_CHANNEL channel)
Returns the conversion value for the channel selected.
This inline function returns the conversion value only after the conversion is complete. Conversion completion status can be checked using ADC1_IsConversionComplete(channel) function. |
in | channel |
- Selected channel |
Returns the analog to digital converted value |
ADC1_Deinitialize()
void ADC1_Deinitialize (void )
Deinitializes the ADC1 to POR values.
none |
none |
ADC1_Disable()
inline static void ADC1_Disable (void )
This inline function disables the ADC1 module.
none |
none |
none |
ADC1_Enable()
inline static void ADC1_Enable (void )
This inline function enables the ADC1 module.
none |
none |
none |
ADC1_IndividualChannelInterruptDisable()
inline static void ADC1_IndividualChannelInterruptDisable (const enum ADC1_CHANNEL channel)
This inline function disables individual channel interrupt.
none |
in | channel |
- Selected channel |
none |
ADC1_IndividualChannelInterruptEnable()
inline static void ADC1_IndividualChannelInterruptEnable (const enum ADC1_CHANNEL channel)
This inline function enables individual channel interrupt.
none |
in | channel |
- Selected channel |
none |
ADC1_IndividualChannelInterruptFlagClear()
inline static void ADC1_IndividualChannelInterruptFlagClear (const enum ADC1_CHANNEL channel)
This inline function clears individual channel interrupt flag.
The flag is not cleared without reading the data from buffer. Hence call ADC1_ConversionResultGet() function to read data before calling this function |
in | channel |
- Selected channel |
none |
ADC1_IndividualChannelInterruptPrioritySet()
inline static void ADC1_IndividualChannelInterruptPrioritySet (const enum ADC1_CHANNEL channel, enum INTERRUPT_PRIORITY priorityValue)
This inline function allows selection of priority for individual channel interrupt.
none |
in | channel |
- Selected channel |
in | priorityValue |
- The numerical value of interrupt priority |
none |
ADC1_Initialize()
void ADC1_Initialize (void )
Initializes ADC1 module, using the given initialization data This function must be called before any other ADC1 function is called.
none |
none |
ADC1_IsConversionComplete()
inline static bool ADC1_IsConversionComplete (const enum ADC1_CHANNEL channel)
This inline function returns the status of conversion.This function is used to determine if conversion is completed. When conversion is complete the function returns true otherwise false.
ADC1_SoftwareTriggerEnable() function should have been called before calling this function. |
in | channel |
- Selected channel |
true - Conversion is complete. false - Conversion is not complete. |
ADC1_PWMTriggerSourceSet()
void ADC1_PWMTriggerSourceSet (const enum ADC1_CHANNEL channel, enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber)
Sets PWM trigger source for corresponding analog input.
in | channel |
- Selected channel |
in | pwmInstance |
- PWM instance for the trigger source |
in | triggerNumber |
- 1, for PWMx Trigger 1 |
in | triggerNumber |
- 2, for PWMx Trigger 2 |
none |
Configure PWM trigger value using PWM_TriggerACompareValueSet, PWM_TriggerBCompareValueSet or PWM_TriggerCCompareValueSet before calling this funcion and enable corresponding PWM trigger using PWM_Trigger1Enable or PWM_Trigger2Enable post calling it.
ADC1_Result32BitChannelCallback()
void ADC1_Result32BitChannelCallback (const enum ADC1_CHANNEL channel, uint32_t adcVal)
This is the default callback function for all the analog channels. This callback is triggered once the channel conversion is done for a channel and to read the conversion result of the corresponding channel.
none |
in | channel |
- conversion completed channel |
in | adcVal |
- conversion result of channel |
none |
ADC1_Result32BitChannelCallbackRegister()
void ADC1_Result32BitChannelCallbackRegister (void(*)(const enum ADC1_CHANNEL channel, uint32_t adcVal) callback)
This function can be used to override default callback ADC1_Result32BitChannelCallback and to define custom callback for ADC1 Channel event.
none Read the conversion result of the corresponding channel in the custom callback. |
in | callback |
- Address of the callback function. |
none |
ADC1_SampleCountGet()
inline static uint16_t ADC1_SampleCountGet (const enum ADC1_CHANNEL channel)
This inline function returns the requested conversion count.
none |
in | channel |
- Channel for conversion |
requested number of conversions |
This function is applicable in Window mode and Integration conversion mode only
ADC1_SampleCountStatusGet()
inline static uint16_t ADC1_SampleCountStatusGet (const enum ADC1_CHANNEL channel)
This inline function returns the status of completed conversion count.
none |
in | channel |
- Channel for conversion |
number of conversions completed |
This function is applicable in Window mode and Integration conversion mode only
ADC1_SecondaryAccumulatorGet()
inline static uint32_t ADC1_SecondaryAccumulatorGet (const enum ADC1_CHANNEL channel)
Returns secondary accumulator conversion value for the channel selected.
This inline function returns the conversion value only after the conversion is complete. Conversion completion status can be checked using ADC1_IsConversionComplete(channel) function. |
in | channel |
- Selected channel |
Returns the analog to digital converted value |
Not all channels support secondary accumulator. Refer to device datasheet for more information.
ADC1_SharedCoreCalibration()
void ADC1_SharedCoreCalibration (void )
Calibrates the ADC1 Core.
none |
none |
none |
ADC1_SharedCorePowerEnable()
void ADC1_SharedCorePowerEnable (void )
Enables power for ADC1 Core This function is used to set the analog and digital power for ADC1 shared Core.
none |
none |
none |
ADC1_SoftwareTriggerDisable()
inline static void ADC1_SoftwareTriggerDisable (void )
This inline function resets software common trigger.
none |
none |
none |
ADC1_SoftwareTriggerEnable()
inline static void ADC1_SoftwareTriggerEnable (void )
This inline function sets software common trigger.
none |
none |
none |
3.1.2.1.4 Enumeration Type Documentation
ADC1_CHANNEL
enum ADC1_CHANNEL
Defines the ADC channles that are selected from the MCC Melody User Interface for the ADC conversions.
The enum list in the Help document might be just a reference to show the analog channel list. Generated enum list is based on the configuration done by user in the MCC Melody user interface.
ADC1_Channel0 |
Channel Name:Channel_0 connected to ADC1_AN0 |
ADC1_Channel1 |
Channel Name:Channel_1 connected to ADC1_AN0 |
ADC1_Channel2 |
Channel Name:Channel_2 connected to ADC1_AN0 |
ADC1_Channel19 |
Channel Name:Channel_19 connected to ADC1_AN0 |
ADC1_MAX_CHANNELS |
Maximum number of channels configured by user for ADC1 |
ADC_DEDICATED_CORE
enum ADC_DEDICATED_CORE
Defines the ADC cores that are available for the module to use.
The enum list in the Help document might be just a reference to to show the dedicated core list. Generated enum list is based on the configuration done by user in the MCC Melody user interface.
ADC_MAX_DEDICATED_CORES |
No dedicated cores available |
ADC_PWM_INSTANCE
enum ADC_PWM_INSTANCE
Defines the ADC PWM trigger sources that are available for the module to use.
Refer PWM_GENERATOR enum for mapping between custom name and instance
ADC_PWM_GENERATOR_4 |
PWM name:PWM_GENERATOR_4 |
ADC_PWM_GENERATOR_3 |
PWM name:PWM_GENERATOR_3 |
ADC_PWM_TRIGGERS
enum ADC_PWM_TRIGGERS
Defines the PWM triggers that are available in each individual PWM.
ADC_PWM_TRIGGER_1 |
PWM TRIGGER 1 |
ADC_PWM_TRIGGER_2 |
PWM TRIGGER 2 |
ADC_RESOLUTION_TYPE
enum ADC_RESOLUTION_TYPE
Defines the supported ADC resolution types.
ADC_12_BIT_RESOLUTION |
ADC Resolution of 12 bit |
3.1.2.1.5 Variable Documentation
ADC1
const struct ADC_INTERFACE ADC1
Structure object of type ADC_INTERFACE with the custom name given by the user in the Melody Driver User interface. The default name e.g. ADC1 can be changed by the user in the ADC user interface. This allows defining a structure with application specific name using the 'Custom Name' field. Application specific name allows the API Portability.
3.1.3 Data Structure Documentation
3.1.3.1 ADC_INTERFACE Struct Reference
Structure containing the function pointers of ADC driver.
3.1.3.1.1 Detailed Description
Structure containing the function pointers of ADC driver.
#include <adc_interface.h>
Data Fields
void(* Initialize )(void)
Pointer to ADCx_Initialize e.g. ADC1_Initialize.
void(* Deinitialize )(void)
Pointer to ADCx_Deinitialize e.g. ADC1_Deinitialize.
void(* Enable )(void)
Pointer to ADCx_Enable e.g. ADC1_Enable.
void(* Disable )(void)
Pointer to ADCx_Disable e.g. ADC1_Disable.
void(* SoftwareTriggerEnable )(void)
Pointer to ADCx_SoftwareTriggerEnable e.g. ADC1_SoftwareTriggerEnable.
void(* SoftwareTriggerDisable )(void)
Pointer to ADCx_SoftwareTriggerDisable e.g. ADC1_SoftwareTriggerDisable.
void(* ChannelSelect )(const unsigned channel)
Pointer to ADCx_ChannelSelect e.g. ADC1_ChannelSelect.
uint32_t(* ConversionResultGet )(const unsigned channel)
Pointer to ADCx_ConversionResultGet e.g. ADC1_ConversionResultGet.
uint32_t(* SecondaryAccumulatorGet )(const unsigned channel)
Pointer to ADCx_SecondaryAccumulatorGet e.g. ADC1_SecondaryAccumulatorGet.
bool(* IsConversionComplete )(const unsigned channel)
Pointer to ADCx_IsConversionComplete e.g. ADC1_IsConversionComplete.
void(* ResolutionSet )(enum ADC_RESOLUTION_TYPE resolution)
Pointer to ADCx_ResolutionSet e.g. ADC1_ResolutionSet.
void(* InterruptEnable )(void)
Pointer to ADCx_InterruptEnable e.g. ADC1_InterruptEnable.
void(* InterruptDisable )(void)
Pointer to ADCx_InterruptDisable e.g. ADC1_InterruptDisable.
void(* InterruptFlagClear )(void)
Pointer to ADCx_InterruptFlagClear e.g. ADC1_InterruptFlagClear.
void(* InterruptPrioritySet )(uint16_t priorityValue)
Pointer to ADCx_InterruptPrioritySet e.g. ADC1_InterruptPrioritySet.
void(* CommonCallbackRegister )(void(*callback)(void))
Pointer to ADCx_CommonCallbackRegister e.g. ADC1_CommonCallbackRegister.
void(* Tasks )(void)
Pointer to ADCx_Tasks e.g. ADC1_Tasks (Supported only in polling mode)
const struct ADC_MULTICORE * adcMulticoreInterface
Pointer to ADC_MULTICORE.
3.1.3.1.2 Field Documentation
adcMulticoreInterface
const struct ADC_MULTICORE* adcMulticoreInterface
Pointer to ADC_MULTICORE.
ChannelSelect
void(* ChannelSelect) (const unsigned channel)
Pointer to ADCx_ChannelSelect e.g. ADC1_ChannelSelect.
CommonCallbackRegister
void(* CommonCallbackRegister) (void(*callback)(void))
Pointer to ADCx_CommonCallbackRegister e.g. ADC1_CommonCallbackRegister.
ConversionResultGet
uint32_t(* ConversionResultGet) (const unsigned channel)
Pointer to ADCx_ConversionResultGet e.g. ADC1_ConversionResultGet.
Deinitialize
void(* Deinitialize) (void)
Pointer to ADCx_Deinitialize e.g. ADC1_Deinitialize.
Disable
void(* Disable) (void)
Pointer to ADCx_Disable e.g. ADC1_Disable.
Enable
void(* Enable) (void)
Pointer to ADCx_Enable e.g. ADC1_Enable.
Initialize
void(* Initialize) (void)
Pointer to ADCx_Initialize e.g. ADC1_Initialize.
InterruptDisable
void(* InterruptDisable) (void)
Pointer to ADCx_InterruptDisable e.g. ADC1_InterruptDisable.
InterruptEnable
void(* InterruptEnable) (void)
Pointer to ADCx_InterruptEnable e.g. ADC1_InterruptEnable.
InterruptFlagClear
void(* InterruptFlagClear) (void)
Pointer to ADCx_InterruptFlagClear e.g. ADC1_InterruptFlagClear.
InterruptPrioritySet
void(* InterruptPrioritySet) (uint16_t priorityValue)
Pointer to ADCx_InterruptPrioritySet e.g. ADC1_InterruptPrioritySet.
IsConversionComplete
bool(* IsConversionComplete) (const unsigned channel)
Pointer to ADCx_IsConversionComplete e.g. ADC1_IsConversionComplete.
ResolutionSet
void(* ResolutionSet) (enum ADC_RESOLUTION_TYPE resolution)
Pointer to ADCx_ResolutionSet e.g. ADC1_ResolutionSet.
SecondaryAccumulatorGet
uint32_t(* SecondaryAccumulatorGet) (const unsigned channel)
Pointer to ADCx_SecondaryAccumulatorGet e.g. ADC1_SecondaryAccumulatorGet.
SoftwareTriggerDisable
void(* SoftwareTriggerDisable) (void)
Pointer to ADCx_SoftwareTriggerDisable e.g. ADC1_SoftwareTriggerDisable.
SoftwareTriggerEnable
void(* SoftwareTriggerEnable) (void)
Pointer to ADCx_SoftwareTriggerEnable e.g. ADC1_SoftwareTriggerEnable.
Tasks
void(* Tasks) (void)
Pointer to ADCx_Tasks e.g. ADC1_Tasks (Supported only in polling mode)
3.1.3.2 ADC_MULTICORE Struct Reference
Structure containing the function pointers of ADC driver.
3.1.3.2.1 Detailed Description
Structure containing the function pointers of ADC driver.
#include <adc_interface.h>
Data Fields
void(* ChannelSoftwareTriggerEnable )(const unsigned channel)
Pointer to ADCx_ChannelSoftwareTriggerEnable e.g. ADC1_ChannelSoftwareTriggerEnable.
void(* ChannelSoftwareTriggerDisable )(const unsigned channel)
Pointer to ADCx_ChannelSoftwareTriggerDisable e.g. ADC1_ChannelSoftwareTriggerDisable.
uint16_t(* SampleCountGet )(const unsigned channel)
Pointer to ADCx_SampleCountGet e.g. ADC1_SampleCountGet.
uint16_t(* SampleCountStatusGet )(const unsigned channel)
Pointer to ADCx_SampleCountStatusGet e.g. ADC1_SampleCountStatusGet.
void(* ChannelCallbackRegister )(void(*callback)(const unsigned channel, uint16_t adcVal))
Pointer to ADCx_ChannelCallbackRegister e.g. ADC1_ChannelCallbackRegister.
void(* Result32BitChannelCallbackRegister )(void(*callback)(const unsigned channel, uint32_t adcVal))
Pointer to ADCx_Result32BitChannelCallbackRegister e.g. ADC1_Result32BitChannelCallbackRegister.
void(* ComparatorCallbackRegister )(void(*callback)(const unsigned comparator))
Pointer to ADCx_ComparatorCallbackRegister e.g. ADC1_ComparatorCallbackRegister.
void(* ChannelTasks )(const unsigned channel)
Pointer to ADCx_ChannelTasks e.g. ADC1_ChannelTasks.
void(* ComparatorTasks )(const unsigned comparator)
Pointer to ADCx_ComparatorTasks e.g. ADC1_ComparatorTasks.
void(* IndividualChannelInterruptEnable )(const unsigned channel)
Pointer to ADCx_IndividualChannelInterruptEnable e.g. ADC1_IndividualChannelInterruptEnable.
void(* IndividualChannelInterruptDisable )(const unsigned channel)
Pointer to ADCx_IndividualChannelInterruptDisable e.g. ADC1_IndividualChannelInterruptDisable.
void(* IndividualChannelInterruptFlagClear )(const unsigned channel)
Pointer to ADCx_IndividualChannelInterruptFlagClear e.g. ADC1_IndividualChannelInterruptFlagClear.
void(* IndividualChannelInterruptPrioritySet )(const unsigned channel, enum INTERRUPT_PRIORITY priorityValue)
Pointer to ADCx_IndividualChannelInterruptPrioritySet e.g. ADC1_IndividualChannelInterruptPrioritySet.
void(* CorePowerEnable )(enum ADC_DEDICATED_CORE core)
Pointer to ADCx_CorePowerEnable e.g. ADC1_CorePowerEnable.
void(* SharedCorePowerEnable )(void)
Pointer to ADCx_SharedCorePowerEnable e.g. ADC1_SharedCorePowerEnable.
void(* CoreCalibration )(enum ADC_DEDICATED_CORE core)
Pointer to ADCx_CoreCalibration e.g. ADC1_CoreCalibration.
void(* SharedCoreCalibration )(void)
Pointer to ADCx_SharedCoreCalibration e.g. ADC1_SharedCoreCalibration.
void(* PWMTriggerSourceSet )(const unsigned channel, enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber)
Pointer to ADCx_PWMTriggerSourceSet e.g. ADC1_PWMTriggerSourceSet.
3.1.3.2.2 Field Documentation
ChannelCallbackRegister
void(* ChannelCallbackRegister) (void(*callback)(const unsigned channel, uint16_t adcVal))
Pointer to ADCx_ChannelCallbackRegister e.g. ADC1_ChannelCallbackRegister.
ChannelSoftwareTriggerDisable
void(* ChannelSoftwareTriggerDisable) (const unsigned channel)
Pointer to ADCx_ChannelSoftwareTriggerDisable e.g. ADC1_ChannelSoftwareTriggerDisable.
ChannelSoftwareTriggerEnable
void(* ChannelSoftwareTriggerEnable) (const unsigned channel)
Pointer to ADCx_ChannelSoftwareTriggerEnable e.g. ADC1_ChannelSoftwareTriggerEnable.
ChannelTasks
void(* ChannelTasks) (const unsigned channel)
Pointer to ADCx_ChannelTasks e.g. ADC1_ChannelTasks.
ComparatorCallbackRegister
void(* ComparatorCallbackRegister) (void(*callback)(const unsigned comparator))
Pointer to ADCx_ComparatorCallbackRegister e.g. ADC1_ComparatorCallbackRegister.
ComparatorTasks
void(* ComparatorTasks) (const unsigned comparator)
Pointer to ADCx_ComparatorTasks e.g. ADC1_ComparatorTasks.
CoreCalibration
void(* CoreCalibration) (enum ADC_DEDICATED_CORE core)
Pointer to ADCx_CoreCalibration e.g. ADC1_CoreCalibration.
CorePowerEnable
void(* CorePowerEnable) (enum ADC_DEDICATED_CORE core)
Pointer to ADCx_CorePowerEnable e.g. ADC1_CorePowerEnable.
IndividualChannelInterruptDisable
void(* IndividualChannelInterruptDisable) (const unsigned channel)
Pointer to ADCx_IndividualChannelInterruptDisable e.g. ADC1_IndividualChannelInterruptDisable.
IndividualChannelInterruptEnable
void(* IndividualChannelInterruptEnable) (const unsigned channel)
Pointer to ADCx_IndividualChannelInterruptEnable e.g. ADC1_IndividualChannelInterruptEnable.
IndividualChannelInterruptFlagClear
void(* IndividualChannelInterruptFlagClear) (const unsigned channel)
Pointer to ADCx_IndividualChannelInterruptFlagClear e.g. ADC1_IndividualChannelInterruptFlagClear.
IndividualChannelInterruptPrioritySet
void(* IndividualChannelInterruptPrioritySet) (const unsigned channel, enum INTERRUPT_PRIORITY priorityValue)
Pointer to ADCx_IndividualChannelInterruptPrioritySet e.g. ADC1_IndividualChannelInterruptPrioritySet.
PWMTriggerSourceSet
void(* PWMTriggerSourceSet) (const unsigned channel, enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber)
Pointer to ADCx_PWMTriggerSourceSet e.g. ADC1_PWMTriggerSourceSet.
Result32BitChannelCallbackRegister
void(* Result32BitChannelCallbackRegister) (void(*callback)(const unsigned channel, uint32_t adcVal))
Pointer to ADCx_Result32BitChannelCallbackRegister e.g. ADC1_Result32BitChannelCallbackRegister.
SampleCountGet
uint16_t(* SampleCountGet) (const unsigned channel)
Pointer to ADCx_SampleCountGet e.g. ADC1_SampleCountGet.
SampleCountStatusGet
uint16_t(* SampleCountStatusGet) (const unsigned channel)
Pointer to ADCx_SampleCountStatusGet e.g. ADC1_SampleCountStatusGet.
SharedCoreCalibration
void(* SharedCoreCalibration) (void)
Pointer to ADCx_SharedCoreCalibration e.g. ADC1_SharedCoreCalibration.
SharedCorePowerEnable
void(* SharedCorePowerEnable) (void)
Pointer to ADCx_SharedCorePowerEnable e.g. ADC1_SharedCorePowerEnable.
3.1.4 File Documentation
3.1.4.1 source/adc1.h File Reference
This is the generated driver header file for the ADC1 driver
#include <xc.h> #include <stdbool.h> #include <stdint.h> #include "adc_types.h" #include "adc_interface.h"
3.1.4.1.1 Functions
void ADC1_Initialize (void)
Initializes ADC1 module, using the given initialization data This function must be called before any other ADC1 function is called.
void ADC1_Deinitialize (void)
Deinitializes the ADC1 to POR values.
static void ADC1_Enable (void)
This inline function enables the ADC1 module.
static void ADC1_Disable (void)
This inline function disables the ADC1 module.
static void ADC1_SoftwareTriggerEnable (void)
This inline function sets software common trigger.
static void ADC1_SoftwareTriggerDisable (void)
This inline function resets software common trigger.
static void ADC1_ChannelSoftwareTriggerEnable (const enum ADC1_CHANNEL channel)
This inline function sets individual software trigger.
static void ADC1_ChannelSoftwareTriggerDisable (const enum ADC1_CHANNEL channel)
This inline function clears individual software trigger.
static uint16_t ADC1_SampleCountGet (const enum ADC1_CHANNEL channel)
This inline function returns the requested conversion count.
static uint16_t ADC1_SampleCountStatusGet (const enum ADC1_CHANNEL channel)
This inline function returns the status of completed conversion count.
static uint32_t ADC1_ConversionResultGet (const enum ADC1_CHANNEL channel)
Returns the conversion value for the channel selected.
static uint32_t ADC1_SecondaryAccumulatorGet (const enum ADC1_CHANNEL channel)
Returns secondary accumulator conversion value for the channel selected.
static bool ADC1_IsConversionComplete (const enum ADC1_CHANNEL channel)
This inline function returns the status of conversion.This function is used to determine if conversion is completed. When conversion is complete the function returns true otherwise false.
static void ADC1_IndividualChannelInterruptEnable (const enum ADC1_CHANNEL channel)
This inline function enables individual channel interrupt.
static void ADC1_IndividualChannelInterruptDisable (const enum ADC1_CHANNEL channel)
This inline function disables individual channel interrupt.
static void ADC1_IndividualChannelInterruptFlagClear (const enum ADC1_CHANNEL channel)
This inline function clears individual channel interrupt flag.
static void ADC1_IndividualChannelInterruptPrioritySet (const enum ADC1_CHANNEL channel, enum INTERRUPT_PRIORITY priorityValue)
This inline function allows selection of priority for individual channel interrupt.
void ADC1_ChannelCallbackRegister (void(*callback)(const enum ADC1_CHANNEL channel, uint16_t adcVal))
This function can be used to override default callback ADC1_ChannelCallback and to define custom callback for ADC1 Channel event. Read the conversion result of the corresponding channel in the custom callback.
void ADC1_ChannelCallback (const enum ADC1_CHANNEL channel, uint16_t adcVal)
This is the default callback function for all the analog channels. This callback is triggered once the channel conversion is done for a channel and to read the conversion result of the corresponding channel.
void ADC1_Result32BitChannelCallbackRegister (void(*callback)(const enum ADC1_CHANNEL channel, uint32_t adcVal))
This function can be used to override default callback ADC1_Result32BitChannelCallback and to define custom callback for ADC1 Channel event.
void ADC1_Result32BitChannelCallback (const enum ADC1_CHANNEL channel, uint32_t adcVal)
This is the default callback function for all the analog channels. This callback is triggered once the channel conversion is done for a channel and to read the conversion result of the corresponding channel.
void ADC1_ComparatorCallbackRegister (void(*callback)(const enum ADC1_CMP comparator))
This function can be used to override default callback and to define custom callback for ADC1_Comparator event.
void ADC1_ComparatorCallback (const enum ADC1_CMP comparator)
Comparator callback function.
void ADC1_ChannelTasks (const enum ADC1_CHANNEL channel)
This function call used only in polling mode, if channel conversion is done for requested channel, the calls the respective callback function.
void ADC1_ComparatorTasks (const enum ADC1_CMP comparator)
Used to implement the tasks for polled implementations of Comparators.
void ADC1_SharedCorePowerEnable (void)
Enables power for ADC1 Core This function is used to set the analog and digital power for ADC1 shared Core.
void ADC1_SharedCoreCalibration (void)
Calibrates the ADC1 Core.
void ADC1_PWMTriggerSourceSet (const enum ADC1_CHANNEL channel, enum ADC_PWM_INSTANCE pwmInstance, enum ADC_PWM_TRIGGERS triggerNumber)
Sets PWM trigger source for corresponding analog input.
3.1.4.1.2 Macros
#define ADC1_RESOLUTION 12
Defines the ADC Resolution.
3.1.4.1.3 Enumerations
enum ADC1_CHANNEL { ADC1_Channel0, ADC1_Channel1, ADC1_Channel2, ADC1_Channel19, ADC1_MAX_CHANNELS = 4 }
Defines the ADC channles that are selected from the MCC Melody User Interface for the ADC conversions.
enum ADC1_CMP { ADC1_CMP0, ADC1_CMP1, ADC1_MAX_CMPS = 2 }
3.1.4.1.4 Variables
const struct ADC_INTERFACE ADC1
Structure object of type ADC_INTERFACE with the custom name given by the user in the Melody Driver User interface. The default name e.g. ADC1 can be changed by the user in the ADC user interface. This allows defining a structure with application specific name using the 'Custom Name' field. Application specific name allows the API Portability.
3.1.4.1.5 Detailed Description
This is the generated driver header file for the ADC1 driver
ADC1 Generated Driver Header File
3.1.4.1.6 Enumeration Type Documentation
ADC1_CMP
enum ADC1_CMP
ADC1_CMP0 |
Comparator name:ADC1_CMP0 connected to ADC1_AN0 |
ADC1_CMP1 |
Comparator name:ADC1_CMP1 connected to ADC1_AN0 |
ADC1_MAX_CMPS |
Maximum Comparators configured by user for ADC1 |
3.1.4.2 source/adc_features.h File Reference
This is the generated module feature header file for ADC driver This file provides module feature list available on the selected device. The macros defined in this file provides the flexibility to easily migrate the user application to other device which might have varied feature list. The content in this file is strictly "read only" and should not be altered.
3.1.4.2.1 Macros
#define ADC_POWER_ENABLE_FEATURE_AVAILABLE 1
This macro defines the ADC core power enable functionality.
#define ADC_CALIBRATION_FEATURE_AVAILABLE 1
This macro defines the macro associated with ADC core calibration.
#define ADC_INDIVIDUAL_CHANNEL_INTERRUPT_FEATURE_AVAILABLE 1
Defines the macro associated with ADC indvidual channel interrupts.
#define ADC_COMPARATOR_FEATURE_AVAILABLE 1
Defines the macro associated with ADC comparator feature.
#define ADC_INDIVIDUAL_SOFTWARE_TRIGGER_FEATURE_AVAILABLE 1
Defines the macro associated with individual channel software trigger feature.
#define ADC_SECONDARY_ACCUMULATOR_FEATURE_AVAILABLE 1
Defines the macro associated with secondary accumulator feature.
3.1.4.2.2 Detailed Description
This is the generated module feature header file for ADC driver This file provides module feature list available on the selected device. The macros defined in this file provides the flexibility to easily migrate the user application to other device which might have varied feature list. The content in this file is strictly "read only" and should not be altered.
ADC Generated Feature Header File
3.1.4.3 source/adc_interface.h File Reference
#include <stdint.h> #include <stdbool.h> #include "adc_types.h" #include "../system/interrupt_types.h"
3.1.4.3.1 Data structures
struct ADC_INTERFACE
Structure containing the function pointers of ADC driver.
struct ADC_MULTICORE
Structure containing the function pointers of ADC driver.
3.1.4.3.2 Detailed Description
ADC Generated Driver Interface Header File
3.1.4.4 source/adc_types.h File Reference
This is the generated driver types header file for the ADC driver
3.1.4.4.1 Enumerations
enum ADC_DEDICATED_CORE { ADC_MAX_DEDICATED_CORES = 0 }
Defines the ADC cores that are available for the module to use.
enum ADC_RESOLUTION_TYPE { ADC_12_BIT_RESOLUTION }
Defines the supported ADC resolution types.
enum ADC_PWM_INSTANCE { ADC_PWM_GENERATOR_4, ADC_PWM_GENERATOR_3 }
Defines the ADC PWM trigger sources that are available for the module to use.
enum ADC_PWM_TRIGGERS { ADC_PWM_TRIGGER_1 = 1, ADC_PWM_TRIGGER_2 = 2 }
Defines the PWM triggers that are available in each individual PWM.
3.1.4.4.2 Detailed Description
This is the generated driver types header file for the ADC driver
ADC Generated Driver Types Header File
3.1.5 Module Documentation
3.1.5.1 ADC Use Cases
3.1.5.1.1 ADC Use Case Code Snippet Instructions
For new users it is recommended to start with the Timer0, UART and Data Streamer, since these components are used to support other use cases.
-
Add ADC to the project
-
Configure:
-
The ADC as described in the example.
-
Any other peripherals or pins needed for the use case.
-
-
Generate the code
-
Add the code snippet(s) to the application code
-
Program the board
3.1.5.1.2 ADC Use Case 1: ADC in Basic_mode with Printf of ADC Result
An ADC conversion is taken every 100 ms, on the selected analog channel. After each ADC conversion a LED is toggled and the ADC Result is sent to PC terminal using printf.
Note: Before each conversion is started, the sample capacitor is first discharged, by connecting it to the ground potential of the microcontroller.
-
Add ADC
-
Add UART
-
Channel Configuration:
-
Enable an ANx channel
-
Select Trigger Source for the same channel as Software Trigger initiated using ADnSWTRG register
-
-
Mode Configuration:
-
Operating Mode: Single Conversion (Default)
-
-
Configuration Settings:
-
Redirect Printf to UART: Yes.
-
-
Dependency Selector:
-
UART PLIB Selector: Select any PLIB
-
Redirect STDIO to UART (for printf support): Yes
-
-
Clock Configuration: Default (1 MHz)
-
Pins: (For all pins check board schematics)
-
Pin Grid View: Select an ANx.
-
Pin Grid View: Select pin for UART Transmit - Tx.
-
Pin Grid View: Select LED pin as output.
-
Pins: Rename Custom Name to "LED".
-
After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:
/* Required header files for ADC Example 1 */ #include "mcc_generated_files/system/system.h" #include "mcc_generated_files/system/clock.h" #define FCY CLOCK_StandardPeripheralFrequencyGet() #include <libpic30.h> #include "mcc_generated_files/adc/adc1.h" #include "mcc_generated_files/uart/uart1.h" #include "mcc_generated_files/system/pins.h" const struct ADC_INTERFACE *adc = &ADC1; const struct UART_INTERFACE *UartSerial = &UART1_Drv;
int main(void) { SYSTEM_Initialize(); uint16_t volatile adcResult; while(1) { adc->SoftwareTriggerEnable(); //Trigger the ADC conversion via software __delay_ms(100); adcResult = adc->ConversionResultGet(ADC1_Channel0); //Get ADC converted result for Channel_AN0 printf("The ADC Result is: %d\r\n",adcResult); LED_Toggle(); } }
3.1.5.1.3 ADC Use Case 2: ADC Samples Visualized with the Data Streamer
-
ADC converstions are triggerd by an timer overflow callback, where the Data Streamer variables adcResult and adcSampleCount are updated.
-
After each ADC conversion a LED is toggled and SEND_FRAME is set to true, so that a frame is sent to the Data Visualizer from the main while loop.
-
Add ADC
-
Add Timer (Use Case: 100 ms Timer)
-
Add Data Streamer (Use Case: Send Frames at a Period Set by the Timer)
-
Channel Configuration:
-
Enable an ANx channel
-
Select Trigger Source for the same channel as Software Trigger initiated using ADnSWTRG register
-
-
Mode Configuration:
-
Operating Mode: Single Conversion (Default)
-
-
Software Settings:
-
UART Dependency Selection: Select the UART that is connected to Serial/CDC port.
-
-
Data Streamer Table:
-
uint16_t adcResult
-
uint8_t adcSampleCount
-
-
Clock Configuration: Default (1 MHz)
-
Pins: (For all pins check board schematics)
-
Pin Grid View: Select an ANx.
-
Pin Grid View: Select pin for UART Transmit - Tx.
-
Pin Grid View: Select LED pin as output.
-
Pin Grid View: Select Debug GPIO pin.
-
Pins: Rename Custom Names to "LED" and "DebugIO" respectively.
-
After configuring the components as described above, click 'Generate' to generate the code. Then add the following code snippets to your application:
#include "mcc_generated_files/system/system.h" #include "mcc_generated_files/system/clock.h" #define FCY CLOCK_StandardPeripheralFrequencyGet() #include <libpic30.h> #include "mcc_generated_files/timer/tmr1.h" #include "mcc_generated_files/adc/adc1.h" #include "mcc_generated_files/data_streamer/data_streamer.h" #include "mcc_generated_files/system/pins.h" /* Create a pointer of type TIMER_INTERFACE and assign it to the address of the Timer1 TIMER_INTERFACE struct. This enables us to get access the portable API interface, which ensures that it's easy to change the peripheral instance the timer runs on. */ const struct TIMER_INTERFACE *timer = &Timer1; const struct ADC_INTERFACE *adc = &ADC1; volatile bool SEND_FRAME = false;
void Timer_Callback_100ms(void)
{
DataStreamer.adcResult = adc->ConversionResultGet(ADC1_Channel0);
DataStreamer.adcSampleCount++;
LED_Toggle();
SEND_FRAME = true;
adc->SoftwareTriggerEnable(); //Trigger the ADC conversion via software
}
int main(void) { SYSTEM_Initialize(); DataStreamer.adcResult = 0; DataStreamer.adcSampleCount = 0; timer->TimeoutCallbackRegister(Timer_Callback_100ms); //Timer Callback Registry while(1) { if(SEND_FRAME) { WriteFrame(); //DataStreamer write SEND_FRAME = false; } } }