Driver API for ADC (plib_adc0.h) More...
Typedefs | |
| typedef uint32_t | ADC_PRESCALER |
| ADC clock prescaler selection. | |
| typedef uint32_t | ADC_VOLTAGE_REF |
| ADC voltage reference selection. | |
| typedef uint32_t | ADC_RESOLUTION |
| ADC conversion result resolution. | |
| typedef uint32_t | ADC_WIN_MODE |
| ADC window comparator mode selection. | |
| typedef uint32_t | ADC_SAMPLE_NUM |
| ADC sample number accumulation selection. | |
| typedef uint32_t | ADC_POS_CHANNEL |
| ADC positive channel selection. | |
| typedef uint32_t | ADC_NEG_CHANNEL |
| ADC negative channel selection. | |
| typedef uint32_t | ADC_EVENT_OUTPUT |
| ADC event output and input selection. | |
| typedef uint32_t | ADC_INTERRUPT_SOURCE |
| ADC interrupt sources. | |
| typedef void(* | ADC_CALLBACK_HANDLER) (ADC_INTERRUPT_SOURCE source) |
| ADC interrupt callback handler type. | |
Functions | |
| void | ADC0_Calibration (void) |
| Calibrate the ADC0 using factory fuse values. | |
| void | ADC0_SetPrescaler (ADC_PRESCALER pre_scaler) |
| Sets the ADC0 clock prescaler. | |
| void | ADC0_SetReferenceCompensation (bool enable_ref_comp) |
| Enables or disables the reference buffer offset compensation. | |
| void | ADC0_SetVoltageReference (ADC_VOLTAGE_REF ref_sel) |
| Sets the ADC0 voltage reference source. | |
| void | ADC0_SetOffsetCompensation (bool offset_comp) |
| Enables or disables comparator offset compensation. | |
| void | ADC0_SetSampleLength (uint8_t sample_len) |
| Sets the ADC0 sample length. | |
| void | ADC0_SetResolution (ADC_RESOLUTION resolution) |
| Sets the ADC0 conversion result resolution. | |
| void | ADC0_SetWindowMode (ADC_WIN_MODE win_mode) |
| Sets the ADC0 window monitor mode. | |
| void | ADC0_ConfigureWindowMode (uint16_t win_lt, uint16_t win_ut) |
| Configures the ADC0 window monitor upper and lower thresholds. | |
| void | ADC0_SetRailToRail (bool rail_to_rail) |
| Enables or disables rail-to-rail operation. | |
| void | ADC0_SetCorrection (bool correction) |
| Enables or disables digital correction logic. | |
| void | ADC0_SetGainCorrection (uint16_t gain_corr) |
| Sets the ADC0 gain correction value. | |
| void | ADC0_SetOffsetCorrection (uint16_t offset_corr) |
| Sets the ADC0 offset correction value. | |
| void | ADC0_SetFreeRunMode (bool free_run) |
| Enables or disables free running mode. | |
| void | ADC0_SetLeftAdjResult (bool left_adj) |
| Sets result left adjustment. | |
| void | ADC0_SetAveragingResultAdjustment (uint8_t adjres) |
| Sets averaging result adjustment. | |
| void | ADC0_SetSampleAccummulationCount (ADC_SAMPLE_NUM samp_acc_count) |
| Sets the number of samples to accumulate for ADC0 conversion. | |
| void | ADC0_SetOnDemand (bool on_demand) |
| Enables or disables on-demand operation. | |
| void | ADC0_SetRunStandby (bool run_standby) |
| Enables or disables ADC0 operation in standby mode. | |
| void | ADC0_SetDebugRun (bool debug) |
| Enables or disables ADC0 operation during debugging. | |
| void | ADC0_Enable (void) |
| Enables the ADC0 module. | |
| void | ADC0_SelectChannel (ADC_POS_CHANNEL positive_input) |
| Selects the ADC0 input channel (single-ended). | |
| void | ADC0_ConfigureSequence (uint32_t seqmask) |
| Configures the ADC0 input sequence. | |
| bool | ADC0_SequenceIsComplete (void) |
| Checks if the ADC0 input sequence is complete. | |
| uint8_t | ADC0_GetSequenceState (void) |
| Gets the current ADC0 sequence state. | |
| void | ADC0_SetDifferentialMode (bool diff_mode) |
| Enables or disables differential mode. | |
| void | ADC0_SelectDifferentialChannel (ADC_POS_CHANNEL positive_input, ADC_NEG_CHANNEL negative_input) |
| Selects the ADC0 input channels for differential conversion. | |
| void | ADC0_StartConversion (void) |
| Starts an ADC0 conversion or sequence. | |
| uint16_t | ADC0_GetConversionResult (void) |
| Gets the ADC0 conversion result. | |
| void | ADC0_SetEventControl (ADC_EVENT_OUTPUT event, bool enable) |
| Configures ADC0 event control. | |
| void | ADC0_EnableInterrupt (ADC_INTERRUPT_SOURCE interrupt) |
| Enables an ADC0 interrupt source. | |
| void | ADC0_DisableInterrupt (ADC_INTERRUPT_SOURCE interrupt) |
| Disables an ADC0 interrupt source. | |
| void | ADC0_ClearInterruptFlag (ADC_INTERRUPT_SOURCE interrupt) |
| Clears an ADC0 interrupt flag. | |
| bool | ADC0_GetInterruptFlagStatus (ADC_INTERRUPT_SOURCE interrupt) |
| Gets the status of an ADC0 interrupt flag. | |
| void | ADC0_Disable (void) |
| Disables the ADC0 module. | |
| void | ADC0_Flush (void) |
| Flushes the ADC0 pipeline. | |
| void | ADC0_ResetSoftware (void) |
| Resets the ADC0 via software. | |
| void | ADC0_SetCallbackHandler (ADC_CALLBACK_HANDLER callback) |
| Registers an ADC0 interrupt callback handler. | |
Driver API for ADC (plib_adc0.h)
The following example demonstrates typical usage of the ADC peripheral:
| ADC_CALLBACK_HANDLER |
ADC interrupt callback handler type.
Defines the prototype for ADC interrupt callback functions.
| source | ADC interrupt source that triggered the callback. |
ADC event output and input selection.
This type specifies ADC event input and output behavior.
ADC interrupt sources.
This type identifies the ADC interrupt source passed to the callback.
ADC negative channel selection.
This type specifies the ADC negative input channel.
ADC positive channel selection.
This type specifies the ADC positive input channel.
ADC clock prescaler selection.
This type represents the ADC clock prescaler configuration. Valid values are provided as macros defined by the device header
ADC conversion result resolution.
This type specifies the resolution of the ADC conversion result.
ADC sample number accumulation selection.
This type specifies the number of samples accumulated before averaging.
ADC voltage reference selection.
This type specifies the voltage reference source used by the ADC. Valid values are provided as macros defined by the ADC.
ADC window comparator mode selection.
This type specifies the window comparison mode used by the ADC.
| void ADC0_Calibration | ( | void | ) |
Calibrate the ADC0 using factory fuse values.
Loads BIAS and LINEARITY calibration values from NVM software calibration row into the ADC0 CALIB register. This ensures specified accuracy for ADC0 conversions.
| None. |
| void ADC0_ClearInterruptFlag | ( | ADC_INTERRUPT_SOURCE | interrupt | ) |
Clears an ADC0 interrupt flag.
This function clears the specified interrupt flag.
| interrupt | Interrupt flag to clear (see ADC_INTERRUPT_SOURCE for options). |
| void ADC0_ConfigureSequence | ( | uint32_t | seqmask | ) |
Configures the ADC0 input sequence.
This function configures automatic sequencing of conversions for selected input channels.
| seqmask | Bitmask of positive input channels to include in the sequence. |
| void ADC0_ConfigureWindowMode | ( | uint16_t | win_lt, |
| uint16_t | win_ut ) |
Configures the ADC0 window monitor upper and lower thresholds.
This function sets the lower and upper threshold values for the window monitor.
| win_lt | Lower threshold value. |
| win_ut | Upper threshold value. |
| void ADC0_Disable | ( | void | ) |
Disables the ADC0 module.
This function disables the ADC0 peripheral.
| None. |
| void ADC0_DisableInterrupt | ( | ADC_INTERRUPT_SOURCE | interrupt | ) |
Disables an ADC0 interrupt source.
This function disables the specified ADC0 interrupt.
| interrupt | Interrupt source (see ADC_INTERRUPT_SOURCE for options). |
| void ADC0_Enable | ( | void | ) |
Enables the ADC0 module.
This function enables the ADC0 peripheral, allowing conversions to be started.
| None. |
| void ADC0_EnableInterrupt | ( | ADC_INTERRUPT_SOURCE | interrupt | ) |
Enables an ADC0 interrupt source.
This function enables the specified ADC0 interrupt.
| interrupt | Interrupt source (see ADC_INTERRUPT_SOURCE for options). |
| void ADC0_Flush | ( | void | ) |
Flushes the ADC0 pipeline.
This function flushes the ADC0 pipeline which will Abort all conversions in progress and restart the ADC0 clock.
| None. |
| uint16_t ADC0_GetConversionResult | ( | void | ) |
Gets the ADC0 conversion result.
This function returns the latest conversion result from the ADC0 conversion.
| None. |
| bool ADC0_GetInterruptFlagStatus | ( | ADC_INTERRUPT_SOURCE | interrupt | ) |
Gets the status of an ADC0 interrupt flag.
This function checks if the specified interrupt flag is set.
| interrupt | Interrupt source (see ADC_INTERRUPT_SOURCE for options). |
| uint8_t ADC0_GetSequenceState | ( | void | ) |
Gets the current ADC0 sequence state.
Returns the input number of the last conversion done in the sequence.
| None. |
| void ADC0_ResetSoftware | ( | void | ) |
Resets the ADC0 via software.
This function resets the ADC0 to the default state and disables the ADC0.
| None. |
| void ADC0_SelectChannel | ( | ADC_POS_CHANNEL | positive_input | ) |
Selects the ADC0 input channel (single-ended).
This function configures the positive input channel for single-ended conversion.
| positive_input | MUXPOS value for the desired input channel (see ADC_POS_CHANNEL for options). |
| void ADC0_SelectDifferentialChannel | ( | ADC_POS_CHANNEL | positive_input, |
| ADC_NEG_CHANNEL | negative_input ) |
Selects the ADC0 input channels for differential conversion.
This function configures the positive and negative input channels for differential conversion.
| positive_input | MUXPOS value for positive input (see ADC_POS_CHANNEL for options). |
| negative_input | MUXNEG value for negative input (see ADC_NEG_CHANNEL for options). |
| bool ADC0_SequenceIsComplete | ( | void | ) |
Checks if the ADC0 input sequence is complete.
This function checks the current sequence status.
| None. |
| void ADC0_SetAveragingResultAdjustment | ( | uint8_t | adjres | ) |
Sets averaging result adjustment.
This function configures the division coefficient for averaging results.
| adjres | Adjusting result (division coefficient in 2n steps). |
| void ADC0_SetCallbackHandler | ( | ADC_CALLBACK_HANDLER | callback | ) |
Registers an ADC0 interrupt callback handler.
This function sets a user-defined callback function to be invoked when an ADC0 interrupt occurs.
| callback | Pointer to the callback function. |
| void ADC0_SetCorrection | ( | bool | correction | ) |
Enables or disables digital correction logic.
Enabling will correct the ADC0 result for gain and offset based on the gain and offset correction values. Conversion time will be increased when enabled.
| correction | True to enable, false to disable. |
| void ADC0_SetDebugRun | ( | bool | debug | ) |
Enables or disables ADC0 operation during debugging.
When enabled, ADC0 continues operation when CPU is halted by debugger.
| debug | True to enable, false to disable. |
| void ADC0_SetDifferentialMode | ( | bool | diff_mode | ) |
Enables or disables differential mode.
This function configures the ADC0 for differential or single-ended conversion.
| diff_mode | True for differential, false for single-ended. |
| void ADC0_SetEventControl | ( | ADC_EVENT_OUTPUT | event, |
| bool | enable ) |
Configures ADC0 event control.
Enables or disables event input/output features for the ADC0.
| event | Event selection (see ADC_EVENT_OUTPUT for options). |
| enable | True to enable, false to disable. |
| void ADC0_SetFreeRunMode | ( | bool | free_run | ) |
Enables or disables free running mode.
When enabled, ADC0 continuously samples and converts the input channel.
| free_run | True to enable, false to disable. |
| void ADC0_SetGainCorrection | ( | uint16_t | gain_corr | ) |
Sets the ADC0 gain correction value.
This function sets the gain correction value to compensate for gain error in ADC0 results.
| gain_corr | Gain correction value (1-bit integer + 11-bit fraction). |
| void ADC0_SetLeftAdjResult | ( | bool | left_adj | ) |
Sets result left adjustment.
This function configures whether the ADC0 result is left- or right-adjusted in the RESULT register.
| left_adj | True for left-adjusted, false for right-adjusted. |
| void ADC0_SetOffsetCompensation | ( | bool | offset_comp | ) |
Enables or disables comparator offset compensation.
Enabling can reduce temperature or voltage drift offset each sampling period. When enabled, sampling duration is fixed to 4 ADC clock cycles.
| offset_comp | True to enable, false to disable. |
| void ADC0_SetOffsetCorrection | ( | uint16_t | offset_corr | ) |
Sets the ADC0 offset correction value.
This function sets the offset correction value to compensate for offset error in ADC0 results.
| offset_corr | Offset correction value (two's complement format). |
| void ADC0_SetOnDemand | ( | bool | on_demand | ) |
Enables or disables on-demand operation.
When enabled, ADC0 runs only when requested by a peripheral.
| on_demand | True to enable, false to disable. |
| void ADC0_SetPrescaler | ( | ADC_PRESCALER | pre_scaler | ) |
Sets the ADC0 clock prescaler.
This function configures the ADC0 clock division factor relative to the peripheral clock.
| pre_scaler | Prescaler selection (see ADC_PRESCALER for options). |
| void ADC0_SetRailToRail | ( | bool | rail_to_rail | ) |
Enables or disables rail-to-rail operation.
Enabling will extend the allowable range of input common mode voltage. Requires offset compensation and a sampling period of four cycles.
| rail_to_rail | True to enable, false to disable. |
| void ADC0_SetReferenceCompensation | ( | bool | enable_ref_comp | ) |
Enables or disables the reference buffer offset compensation.
Enabling can reduce the gain error but also increase reference startup time.
| enable_ref_comp | True to enable, false to disable. |
| void ADC0_SetResolution | ( | ADC_RESOLUTION | resolution | ) |
Sets the ADC0 conversion result resolution.
This function configures the number of bits in the ADC0 conversion result.
| resolution | Resolution setting (see ADC_RESOLUTION for options) |
| void ADC0_SetRunStandby | ( | bool | run_standby | ) |
Enables or disables ADC0 operation in standby mode.
When enabled, ADC0 continues operation during standby sleep mode.
| standby | True to enable, false to disable. |
| void ADC0_SetSampleAccummulationCount | ( | ADC_SAMPLE_NUM | samp_acc_count | ) |
Sets the number of samples to accumulate for ADC0 conversion.
This function configures the ADC0 to accumulate a specified number of samples for each conversion for averaging or oversampling.
| samp_acc_count | Number of samples to accumulate. |
| void ADC0_SetSampleLength | ( | uint8_t | sample_len | ) |
Sets the ADC0 sample length.
This function configures the number of ADC clock periods used for sampling. Sample length is only available when offset compensation is disabled.
| sample_len | Number of ADC clock periods plus 1 for sampling. |
| void ADC0_SetVoltageReference | ( | ADC_VOLTAGE_REF | ref_sel | ) |
Sets the ADC0 voltage reference source.
This function selects the voltage reference source for the ADC0.
| ref_sel | Voltage reference selection (see ADC_VOLTAGE_REF for options). |
| void ADC0_SetWindowMode | ( | ADC_WIN_MODE | win_mode | ) |
Sets the ADC0 window monitor mode.
This function enables or disables the window monitor and sets its comparison mode.
| win_mode | Window monitor mode. (see ADC_WIN_MODE for options) |
| void ADC0_StartConversion | ( | void | ) |
Starts an ADC0 conversion or sequence.
This function initiates an ADC0 conversion or sequence
| None. |