This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's Analog-to-Digital Converter functionality, for the conversion of analog voltages into a corresponding digital form.
The following driver Application Programming Interface (API) modes are covered by this manual:
The following peripheral is used by this module:
The following devices can use this module:
The outline of this documentation is as follows:
There are no prerequisites for this module.
This driver provides an interface for the Analog-to-Digital conversion functions on the device, to convert analog voltages to a corresponding digital value. The ADC has up to 12-bit resolution, and is capable of converting up to 500K samples per second (KSPS).
The ADC has a compare function for accurate monitoring of user defined thresholds with minimum software intervention required. The ADC may be configured for 8-, 10-, or 12-bit result, reducing the conversion time. ADC conversion results are provided left or right adjusted which eases calculation when the result is represented as a signed integer.
The input selection is flexible, and both single-ended and differential measurements can be made. For differential measurements, an optional gain stage is available to increase the dynamic range. In addition, several internal signal inputs are available. The ADC can provide both signed and unsigned results.
The ADC measurements can either be started by application software or an incoming event from another peripheral in the device, and both internal and external reference voltages can be selected.
A simplified block diagram of the ADC can be seen in the figure below.
The ADC features a prescaler, which enables conversion at lower clock rates than the input Generic Clock to the ADC module. This feature can be used to lower the synchronization time of the digital interface to the ADC module via a high speed Generic Clock frequency, while still allowing the ADC sampling rate to be reduced.
The ADC supports full 8-, 10-, or 12-bit resolution. Hardware oversampling and decimation can be used to increase the effective resolution at the expense of throughput. Using oversampling and decimation mode the ADC resolution is increased from 12-bit to an effective 13-, 14-, 15-, or 16-bit. In these modes the conversion rate is reduced, as a greater number of samples is used to achieve the increased resolution. The available resolutions and effective conversion rate is listed in the table below.
Resolution | Effective conversion rate |
---|---|
13-bit | Conversion rate divided by 4 |
14-bit | Conversion rate divided by 16 |
15-bit | Conversion rate divided by 64 |
16-bit | Conversion rate divided by 256 |
ADC conversions can be software triggered on demand by the user application, if continuous sampling is not required. It is also possible to configure the ADC in free running mode, where new conversions are started as soon as the previous conversion is completed, or configure the ADC to scan across a number of input pins (see Pin Scan).
The ADC has two conversion modes; differential and single-ended. When measuring signals where the positive input pin is always at a higher voltage than the negative input pin, the single-ended conversion mode should be used in order to achieve a full 12-bit output resolution.
If however the positive input pin voltage may drop below the negative input pin the signed differential mode should be used.
The sample time for each ADC conversion is configurable as a number of half prescaled ADC clock cycles (depending on the prescaler value), allowing the user application to achieve faster or slower sampling depending on the source impedance of the ADC input channels. For applications with high impedance inputs the sample time can be increased to give the ADC an adequate time to sample and convert the input channel.
The resulting sampling time is given by the following equation:
\[ t_{SAMPLE} = (sample\_length+1) \times \frac{ADC_{CLK}} {2} \]
The ADC can be configured to trade conversion speed for accuracy by averaging multiple samples in hardware. This feature is suitable when operating in noisy conditions.
You can specify any number of samples to accumulate (up to 1024) and the divide ratio to use (up to divide by 128). To modify these settings the ADC_RESOLUTION_CUSTOM needs to be set as the resolution. When this is set the number of samples to accumulate and the division ratio can be set by the configuration struct members adc_config::accumulate_samples and adc_config::divide_result. When using this mode the ADC result register will be set to be 16-bit wide to accommodate the larger result sizes produced by the accumulator.
The effective ADC conversion rate will be reduced by a factor of the number of accumulated samples; however, the effective resolution will be increased according to the table below.
Number of samples | Final result |
---|---|
1 | 12-bit |
2 | 13-bit |
4 | 14-bit |
8 | 15-bit |
16 | 16-bit |
32 | 16-bit |
64 | 16-bit |
128 | 16-bit |
256 | 16-bit |
512 | 16-bit |
1024 | 16-bit |
Inherent gain and offset errors affect the absolute accuracy of the ADC.
The offset error is defined as the deviation of the ADC's actual transfer function from ideal straight line at zero input voltage.
The gain error is defined as the deviation of the last output step's midpoint from the ideal straight line, after compensating for offset error.
The offset correction value is subtracted from the converted data before the result is ready. The gain correction value is multiplied with the offset corrected value.
The equation for both offset and gain error compensation is shown below:
\[ ADC_{RESULT} = (VALUE_{CONV} + CORR_{OFFSET}) \times CORR_{GAIN} \]
When enabled, a given set of offset and gain correction values can be applied to the sampled data in hardware, giving a corrected stream of sample data to the user application at the cost of an increased sample latency.
In single conversion, a latency of 13 ADC Generic Clock cycles is added for the final sample result availability. As the correction time is always less than the propagation delay, in free running mode this latency appears only during the first conversion. After the first conversion is complete, future conversion results are available at the defined sampling rate.
In pin scan mode, the first ADC conversion will begin from the configured positive channel, plus the requested starting offset. When the first conversion is completed, the next conversion will start at the next positive input channel and so on, until all requested pins to scan have been sampled and converted. SAM L21/L22 has automatic sequences feature instead of pin scan mode. In automatic sequence mode, all of 32 positives inputs can be included in a sequence. The sequence starts from the lowest input, and go to the next enabled input automatically.
Pin scanning gives a simple mechanism to sample a large number of physical input channel samples, using a single physical ADC channel.
The ADC module window monitor function can be used to automatically compare the conversion result against a preconfigured pair of upper and lower threshold values.
The threshold values are evaluated differently, depending on whether differential or single-ended mode is selected. In differential mode, the upper and lower thresholds are evaluated as signed values for the comparison, while in single-ended mode the comparisons are made as a set of unsigned values.
The significant bits of the lower window monitor threshold and upper window monitor threshold values are user-configurable, and follow the overall ADC sampling bit precision set when the ADC is configured by the user application. For example, only the eight lower bits of the window threshold values will be compared to the sampled data whilst the ADC is configured in 8-bit mode. In addition, if using differential mode, the 8th bit will be considered as the sign bit even if bit 9 is zero.
Event generation and event actions are configurable in the ADC.
The ADC has two actions that can be triggered upon event reception:
The ADC can generate two events:
If the event actions are enabled in the configuration, any incoming event will trigger the action.
If the window monitor event is enabled, an event will be generated when the configured window condition is detected.
If the result ready event is enabled, an event will be generated when a conversion is completed.
An integrated analog temperature sensor is available for use with the ADC. The bandgap voltage, as well as the scaled I/O and core voltages can also be measured by the ADC. For internal ADC inputs, the internal source(s) may need to be manually enabled by the user application before they can be measured.
For extra information, see Extra Information for ADC Driver. This includes:
For a list of examples related to this driver, see Examples for ADC Driver.
Data Structures | |
struct | adc_config |
ADC configuration structure. More... | |
struct | adc_correction_config |
Gain and offset correction configuration structure. More... | |
struct | adc_events |
ADC event enable/disable structure. More... | |
struct | adc_module |
ADC software device instance structure. More... | |
struct | adc_window_config |
Window monitor configuration structure. More... | |
Macros | |
#define | FEATURE_ADC_SUPPORT_MASTER_SLAVE |
Output Driver Strength Selection feature support. More... | |
Typedefs | |
typedef void(* | adc_callback_t )(struct adc_module *const module) |
Type of the callback functions. More... | |
Enumerations | |
enum | adc_accumulate_samples { ADC_ACCUMULATE_DISABLE = ADC_AVGCTRL_SAMPLENUM_1, ADC_ACCUMULATE_SAMPLES_2 = ADC_AVGCTRL_SAMPLENUM_2, ADC_ACCUMULATE_SAMPLES_4 = ADC_AVGCTRL_SAMPLENUM_4, ADC_ACCUMULATE_SAMPLES_8 = ADC_AVGCTRL_SAMPLENUM_8, ADC_ACCUMULATE_SAMPLES_16 = ADC_AVGCTRL_SAMPLENUM_16, ADC_ACCUMULATE_SAMPLES_32 = ADC_AVGCTRL_SAMPLENUM_32, ADC_ACCUMULATE_SAMPLES_64 = ADC_AVGCTRL_SAMPLENUM_64, ADC_ACCUMULATE_SAMPLES_128 = ADC_AVGCTRL_SAMPLENUM_128, ADC_ACCUMULATE_SAMPLES_256 = ADC_AVGCTRL_SAMPLENUM_256, ADC_ACCUMULATE_SAMPLES_512 = ADC_AVGCTRL_SAMPLENUM_512, ADC_ACCUMULATE_SAMPLES_1024 = ADC_AVGCTRL_SAMPLENUM_1024 } |
ADC number of accumulated samples enum. More... | |
enum | adc_callback { ADC_CALLBACK_READ_BUFFER, ADC_CALLBACK_WINDOW, ADC_CALLBACK_ERROR } |
ADC callback enum. More... | |
enum | adc_clock_prescaler { ADC_CLOCK_PRESCALER_DIV2 = ADC_CTRLB_PRESCALER_DIV2, ADC_CLOCK_PRESCALER_DIV4 = ADC_CTRLB_PRESCALER_DIV4, ADC_CLOCK_PRESCALER_DIV8 = ADC_CTRLB_PRESCALER_DIV8, ADC_CLOCK_PRESCALER_DIV16 = ADC_CTRLB_PRESCALER_DIV16, ADC_CLOCK_PRESCALER_DIV32 = ADC_CTRLB_PRESCALER_DIV32, ADC_CLOCK_PRESCALER_DIV64 = ADC_CTRLB_PRESCALER_DIV64, ADC_CLOCK_PRESCALER_DIV128 = ADC_CTRLB_PRESCALER_DIV128, ADC_CLOCK_PRESCALER_DIV256 = ADC_CTRLB_PRESCALER_DIV256 } |
ADC clock prescaler enum. More... | |
enum | adc_divide_result { ADC_DIVIDE_RESULT_DISABLE = 0, ADC_DIVIDE_RESULT_2 = 1, ADC_DIVIDE_RESULT_4 = 2, ADC_DIVIDE_RESULT_8 = 3, ADC_DIVIDE_RESULT_16 = 4, ADC_DIVIDE_RESULT_32 = 5, ADC_DIVIDE_RESULT_64 = 6, ADC_DIVIDE_RESULT_128 = 7 } |
ADC possible dividers for the result register. More... | |
enum | adc_dual_mode_trigger_selection { ADC_DUAL_MODE_BOTH = ADC_CTRLC_DUALSEL_BOTH, ADC_DUAL_MODE_INTERLEAVE = ADC_CTRLC_DUALSEL_INTERLEAVE } |
Enum for the trigger selection in dual mode. More... | |
enum | adc_event_action { ADC_EVENT_ACTION_DISABLED = 0, ADC_EVENT_ACTION_FLUSH_START_CONV = ADC_EVCTRL_FLUSHEI, ADC_EVENT_ACTION_START_CONV = ADC_EVCTRL_STARTEI } |
ADC event action enum. More... | |
enum | adc_interrupt_flag { ADC_INTERRUPT_RESULT_READY = ADC_INTFLAG_RESRDY, ADC_INTERRUPT_WINDOW = ADC_INTFLAG_WINMON, ADC_INTERRUPT_OVERRUN = ADC_INTFLAG_OVERRUN } |
Enum for the possible ADC interrupt flags. More... | |
enum | adc_job_type { ADC_JOB_READ_BUFFER } |
Enum for the possible types of ADC asynchronous jobs that may be issued to the driver. More... | |
enum | adc_negative_input { ADC_NEGATIVE_INPUT_PIN0 = ADC_INPUTCTRL_MUXNEG_AIN0, ADC_NEGATIVE_INPUT_PIN1 = ADC_INPUTCTRL_MUXNEG_AIN1, ADC_NEGATIVE_INPUT_PIN2 = ADC_INPUTCTRL_MUXNEG_AIN2, ADC_NEGATIVE_INPUT_PIN3 = ADC_INPUTCTRL_MUXNEG_AIN3, ADC_NEGATIVE_INPUT_PIN4 = ADC_INPUTCTRL_MUXNEG_AIN4, ADC_NEGATIVE_INPUT_PIN5 = ADC_INPUTCTRL_MUXNEG_AIN5, ADC_NEGATIVE_INPUT_GND = ADC_INPUTCTRL_MUXNEG(0x18u) } |
ADC negative MUX input selection enum. More... | |
enum | adc_oversampling_and_decimation { ADC_OVERSAMPLING_AND_DECIMATION_DISABLE = 0, ADC_OVERSAMPLING_AND_DECIMATION_1BIT, ADC_OVERSAMPLING_AND_DECIMATION_2BIT, ADC_OVERSAMPLING_AND_DECIMATION_3BIT, ADC_OVERSAMPLING_AND_DECIMATION_4BIT } |
ADC oversampling and decimation enum. More... | |
enum | adc_positive_input { ADC_POSITIVE_INPUT_PIN0 = ADC_INPUTCTRL_MUXPOS_AIN0, ADC_POSITIVE_INPUT_PIN1 = ADC_INPUTCTRL_MUXPOS_AIN1, ADC_POSITIVE_INPUT_PIN2 = ADC_INPUTCTRL_MUXPOS_AIN2, ADC_POSITIVE_INPUT_PIN3 = ADC_INPUTCTRL_MUXPOS_AIN3, ADC_POSITIVE_INPUT_PIN4 = ADC_INPUTCTRL_MUXPOS_AIN4, ADC_POSITIVE_INPUT_PIN5 = ADC_INPUTCTRL_MUXPOS_AIN5, ADC_POSITIVE_INPUT_PIN6 = ADC_INPUTCTRL_MUXPOS_AIN6, ADC_POSITIVE_INPUT_PIN7 = ADC_INPUTCTRL_MUXPOS_AIN7, ADC_POSITIVE_INPUT_PIN8 = ADC_INPUTCTRL_MUXPOS_AIN8, ADC_POSITIVE_INPUT_PIN9 = ADC_INPUTCTRL_MUXPOS_AIN9, ADC_POSITIVE_INPUT_PIN10 = ADC_INPUTCTRL_MUXPOS_AIN10, ADC_POSITIVE_INPUT_PIN11 = ADC_INPUTCTRL_MUXPOS_AIN11, ADC_POSITIVE_INPUT_BANDGAP = ADC_INPUTCTRL_MUXPOS_BANDGAP, ADC_POSITIVE_INPUT_SCALEDCOREVCC = ADC_INPUTCTRL_MUXPOS_SCALEDCOREVCC, ADC_POSITIVE_INPUT_SCALEDIOVCC = ADC_INPUTCTRL_MUXPOS_SCALEDIOVCC } |
ADC positive MUX input selection enum. More... | |
enum | adc_reference { ADC_REFERENCE_INTREF = ADC_REFCTRL_REFSEL_INTREF, ADC_REFERENCE_INTVCC0 = ADC_REFCTRL_REFSEL_INTVCC0, ADC_REFERENCE_INTVCC1 = ADC_REFCTRL_REFSEL_INTVCC1, ADC_REFERENCE_AREFA = ADC_REFCTRL_REFSEL_AREFA, ADC_REFERENCE_INTVCC2 = ADC_REFCTRL_REFSEL_INTVCC2 } |
ADC reference voltage enum. More... | |
enum | adc_resolution { ADC_RESOLUTION_12BIT = ADC_CTRLC_RESSEL_12BIT, ADC_RESOLUTION_16BIT = ADC_CTRLC_RESSEL_16BIT, ADC_RESOLUTION_10BIT = ADC_CTRLC_RESSEL_10BIT, ADC_RESOLUTION_8BIT = ADC_CTRLC_RESSEL_8BIT, ADC_RESOLUTION_13BIT, ADC_RESOLUTION_14BIT, ADC_RESOLUTION_15BIT, ADC_RESOLUTION_CUSTOM } |
ADC resolution enum. More... | |
enum | adc_window_mode { ADC_WINDOW_MODE_DISABLE = ADC_CTRLC_WINMODE_DISABLE, ADC_WINDOW_MODE_ABOVE_LOWER = ADC_CTRLC_WINMODE_MODE1, ADC_WINDOW_MODE_BELOW_UPPER = ADC_CTRLC_WINMODE_MODE2, ADC_WINDOW_MODE_BETWEEN = ADC_CTRLC_WINMODE_MODE3, ADC_WINDOW_MODE_BETWEEN_INVERTED = ADC_CTRLC_WINMODE_MODE4 } |
ADC window monitor mode enum. More... | |
Functions | |
static void | adc_set_master_slave_mode (struct adc_module *const master_inst, struct adc_module *const slave_inst, enum adc_dual_mode_trigger_selection dualsel) |
Set ADC master and slave mode. More... | |
Module Status Flags | |
ADC status flags, returned by adc_get_status() and cleared by adc_clear_status(). | |
#define | ADC_STATUS_RESULT_READY (1UL << 0) |
ADC result ready. More... | |
#define | ADC_STATUS_WINDOW (1UL << 1) |
Window monitor match. More... | |
#define | ADC_STATUS_OVERRUN (1UL << 2) |
ADC result overwritten before read. More... | |
Driver Initialization and Configuration | |
enum status_code | adc_init (struct adc_module *const module_inst, Adc *hw, struct adc_config *config) |
Initializes the ADC. More... | |
void | adc_get_config_defaults (struct adc_config *const config) |
Initializes an ADC configuration structure to defaults. More... | |
Status Management | |
static uint32_t | adc_get_status (struct adc_module *const module_inst) |
Retrieves the current module status. More... | |
static void | adc_clear_status (struct adc_module *const module_inst, const uint32_t status_flags) |
Clears a module status flag. More... | |
Enable, Disable, and Reset ADC Module, Start Conversion and Read Result | |
static enum status_code | adc_enable (struct adc_module *const module_inst) |
Enables the ADC module. More... | |
static enum status_code | adc_disable (struct adc_module *const module_inst) |
Disables the ADC module. More... | |
static enum status_code | adc_reset (struct adc_module *const module_inst) |
Resets the ADC module. More... | |
static void | adc_enable_events (struct adc_module *const module_inst, struct adc_events *const events) |
Enables an ADC event input or output. More... | |
static void | adc_disable_events (struct adc_module *const module_inst, struct adc_events *const events) |
Disables an ADC event input or output. More... | |
static void | adc_start_conversion (struct adc_module *const module_inst) |
Starts an ADC conversion. More... | |
static enum status_code | adc_read (struct adc_module *const module_inst, uint16_t *result) |
Reads the ADC result. More... | |
Runtime Changes of ADC Module | |
static void | adc_flush (struct adc_module *const module_inst) |
Flushes the ADC pipeline. More... | |
void | adc_set_window_mode (struct adc_module *const module_inst, const enum adc_window_mode window_mode, const int16_t window_lower_value, const int16_t window_upper_value) |
Sets the ADC window mode. More... | |
static void | adc_set_positive_input (struct adc_module *const module_inst, const enum adc_positive_input positive_input) |
Sets positive ADC input pin. More... | |
static void | adc_set_negative_input (struct adc_module *const module_inst, const enum adc_negative_input negative_input) |
Sets negative ADC input pin for differential mode. More... | |
Enable and Disable Interrupts | |
static void | adc_enable_interrupt (struct adc_module *const module_inst, enum adc_interrupt_flag interrupt) |
Enable interrupt. More... | |
static void | adc_disable_interrupt (struct adc_module *const module_inst, enum adc_interrupt_flag interrupt) |
Disable interrupt. More... | |
Callback Management | |
void | adc_register_callback (struct adc_module *const module, adc_callback_t callback_func, enum adc_callback callback_type) |
Registers a callback. More... | |
void | adc_unregister_callback (struct adc_module *module, enum adc_callback callback_type) |
Unregisters a callback. More... | |
static void | adc_enable_callback (struct adc_module *const module, enum adc_callback callback_type) |
Enables callback. More... | |
static void | adc_disable_callback (struct adc_module *const module, enum adc_callback callback_type) |
Disables callback. More... | |
Job Management | |
enum status_code | adc_read_buffer_job (struct adc_module *const module_inst, uint16_t *buffer, uint16_t samples) |
Read multiple samples from ADC. More... | |
enum status_code | adc_get_job_status (struct adc_module *module_inst, enum adc_job_type type) |
Gets the status of a job. More... | |
void | adc_abort_job (struct adc_module *module_inst, enum adc_job_type type) |
Aborts an ongoing job. More... | |
Positive Input Sequence | |
static void | adc_enable_positive_input_sequence (struct adc_module *const module_inst, uint32_t positive_input_sequence_mask_enable) |
Enable positive input sequence mask for conversion. More... | |
static void | adc_disable_positive_input_sequence (struct adc_module *const module_inst) |
Disable positive input in the sequence. More... | |
static void | adc_get_sequence_status (struct adc_module *const module_inst, bool *is_sequence_busy, uint8_t *sequence_state) |
Get ADC sequence status. More... | |
#define ADC_STATUS_OVERRUN (1UL << 2) |
ADC result overwritten before read.
Referenced by adc_clear_status(), adc_get_status(), and adc_read().
#define ADC_STATUS_RESULT_READY (1UL << 0) |
ADC result ready.
Referenced by adc_clear_status(), adc_get_status(), and adc_read().
#define ADC_STATUS_WINDOW (1UL << 1) |
Window monitor match.
Referenced by adc_clear_status(), and adc_get_status().
#define FEATURE_ADC_SUPPORT_MASTER_SLAVE |
Output Driver Strength Selection feature support.
typedef void(* adc_callback_t)(struct adc_module *const module) |
Type of the callback functions.
ADC number of accumulated samples enum.
Enum for the possible numbers of ADC samples to accumulate. This setting is only used when the ADC_RESOLUTION_CUSTOM resolution setting is used.
enum adc_callback |
enum adc_clock_prescaler |
ADC clock prescaler enum.
Enum for the possible clock prescaler values for the ADC.
enum adc_divide_result |
ADC possible dividers for the result register.
Enum for the possible division factors to use when accumulating multiple samples. To keep the same resolution for the averaged result and the actual input value, the division factor must be equal to the number of samples accumulated. This setting is only used when the ADC_RESOLUTION_CUSTOM resolution setting is used.
enum adc_event_action |
enum adc_interrupt_flag |
enum adc_job_type |
enum adc_negative_input |
ADC negative MUX input selection enum.
Enum for the possible negative MUX input selections for the ADC.
ADC oversampling and decimation enum.
Enum for the possible numbers of bits resolution can be increased by when using oversampling and decimation.
enum adc_positive_input |
ADC positive MUX input selection enum.
Enum for the possible positive MUX input selections for the ADC.
enum adc_reference |
ADC reference voltage enum.
Enum for the possible reference voltages for the ADC.
enum adc_resolution |
ADC resolution enum.
Enum for the possible resolution values for the ADC.
Enumerator | |
---|---|
ADC_RESOLUTION_12BIT |
ADC 12-bit resolution. |
ADC_RESOLUTION_16BIT |
ADC 16-bit resolution using oversampling and decimation. |
ADC_RESOLUTION_10BIT |
ADC 10-bit resolution. |
ADC_RESOLUTION_8BIT |
ADC 8-bit resolution. |
ADC_RESOLUTION_13BIT |
ADC 13-bit resolution using oversampling and decimation. |
ADC_RESOLUTION_14BIT |
ADC 14-bit resolution using oversampling and decimation. |
ADC_RESOLUTION_15BIT |
ADC 15-bit resolution using oversampling and decimation. |
ADC_RESOLUTION_CUSTOM |
ADC 16-bit result register for use with averaging. When using this mode the ADC result register will be set to 16-bit wide, and the number of samples to accumulate and the division factor is configured by the adc_config::accumulate_samples and adc_config::divide_result members in the configuration struct. |
enum adc_window_mode |
ADC window monitor mode enum.
Enum for the possible window monitor modes for the ADC.
void adc_abort_job | ( | struct adc_module * | module_inst, |
enum adc_job_type | type | ||
) |
Aborts an ongoing job.
Aborts an ongoing job.
[in] | module_inst | Pointer to the ADC software instance struct |
[in] | type | Type of job to abort |
References adc_disable_interrupt(), ADC_INTERRUPT_RESULT_READY, ADC_JOB_READ_BUFFER, Assert, and STATUS_ABORTED.
|
inlinestatic |
Clears a module status flag.
Clears the given status flag of the module.
[in] | module_inst | Pointer to the ADC software instance struct |
[in] | status_flags | Bitmask of ADC_STATUS_* flags to clear |
References ADC_STATUS_OVERRUN, ADC_STATUS_RESULT_READY, ADC_STATUS_WINDOW, and Assert.
Referenced by adc_read().
|
inlinestatic |
Disables the ADC module.
Disables an ADC module that was previously enabled.
[in] | module_inst | Pointer to the ADC software instance struct |
References _adc_get_inst_index(), Assert, STATUS_OK, system_interrupt_disable(), and SYSTEM_INTERRUPT_MODULE_ADC.
Referenced by adc_reset().
|
inlinestatic |
Disables callback.
Disables the callback function registered by the adc_register_callback.
[in] | module | Pointer to ADC software instance struct |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | If operation was completed |
STATUS_ERR_INVALID | If operation was not completed, due to invalid callback_type |
References ADC_CALLBACK_ERROR, ADC_CALLBACK_WINDOW, adc_disable_interrupt(), ADC_INTERRUPT_OVERRUN, ADC_INTERRUPT_WINDOW, and Assert.
|
inlinestatic |
Disables an ADC event input or output.
Disables one or more input or output events to or from the ADC module. See Struct adc_events for a list of events this module supports.
[in] | module_inst | Software instance for the ADC peripheral |
[in] | events | Struct containing flags of events to disable |
References Assert, adc_events::generate_event_on_conversion_done, and adc_events::generate_event_on_window_monitor.
|
inlinestatic |
Disable interrupt.
Disable the given interrupt request from the ADC module.
[in] | module_inst | Pointer to the ADC software instance struct |
[in] | interrupt | Interrupt to disable |
References Assert.
Referenced by _adc_interrupt_handler(), adc_abort_job(), and adc_disable_callback().
|
inlinestatic |
Disable positive input in the sequence.
Disable positive input in the sequence.
[in] | module_inst | Pointer to the ADC software instance struct |
References Assert.
|
inlinestatic |
Enables the ADC module.
Enables an ADC module that has previously been configured. If any internal reference is selected it will be enabled.
[in] | module_inst | Pointer to the ADC software instance struct |
References _adc_get_inst_index(), Assert, STATUS_OK, system_interrupt_enable(), and SYSTEM_INTERRUPT_MODULE_ADC.
Referenced by configure_adc().
|
inlinestatic |
Enables callback.
Enables the callback function registered by adc_register_callback. The callback function will be called from the interrupt handler when the conditions for the callback type are met.
[in] | module | Pointer to ADC software instance struct |
[in] | callback_type | Callback type given by an enum |
STATUS_OK | If operation was completed |
STATUS_ERR_INVALID | If operation was not completed, due to invalid callback_type |
References ADC_CALLBACK_ERROR, ADC_CALLBACK_WINDOW, adc_enable_interrupt(), ADC_INTERRUPT_OVERRUN, ADC_INTERRUPT_WINDOW, and Assert.
|
inlinestatic |
Enables an ADC event input or output.
Enables one or more input or output events to or from the ADC module. See Struct adc_events for a list of events this module supports.
[in] | module_inst | Software instance for the ADC peripheral |
[in] | events | Struct containing flags of events to enable |
References Assert, adc_events::generate_event_on_conversion_done, and adc_events::generate_event_on_window_monitor.
|
inlinestatic |
Enable interrupt.
Enable the given interrupt request from the ADC module.
[in] | module_inst | Pointer to the ADC software instance struct |
[in] | interrupt | Interrupt to enable |
References Assert.
Referenced by adc_enable_callback(), and adc_read_buffer_job().
|
inlinestatic |
Enable positive input sequence mask for conversion.
The sequence start from the lowest input, and go to the next enabled input automatically when the conversion is done. If no bits are set the sequence is disabled.
[in] | module_inst | Pointer to the ADC software instance struct |
[in] | eanble_seq_mask | Sequence mask |
References Assert.
|
inlinestatic |
Flushes the ADC pipeline.
Flushes the pipeline and restarts the ADC clock on the next peripheral clock edge. All conversions in progress will be lost. When flush is complete, the module will resume where it left off.
[in] | module_inst | Pointer to the ADC software instance struct |
References Assert.
void adc_get_config_defaults | ( | struct adc_config *const | config | ) |
Initializes an ADC configuration structure to defaults.
Initializes a given ADC configuration struct to a set of known default values. This function should be called on any new instance of the configuration struct before being modified by the user application.
The default configuration is as follows:
[out] | config | Pointer to configuration struct to initialize to default values |
References adc_config::accumulate_samples, ADC_ACCUMULATE_DISABLE, ADC_CLOCK_PRESCALER_DIV2, ADC_DIVIDE_RESULT_DISABLE, ADC_EVENT_ACTION_DISABLED, ADC_NEGATIVE_INPUT_GND, ADC_POSITIVE_INPUT_PIN1, ADC_POSITIVE_INPUT_PIN6, ADC_REFERENCE_INTREF, ADC_RESOLUTION_12BIT, ADC_WINDOW_MODE_DISABLE, Assert, adc_config::clock_prescaler, adc_config::clock_source, adc_config::correction, adc_correction_config::correction_enable, adc_config::differential_mode, adc_config::divide_result, adc_config::event_action, adc_config::freerunning, adc_correction_config::gain_correction, GCLK_GENERATOR_0, adc_config::left_adjust, adc_config::negative_input, adc_correction_config::offset_correction, adc_config::on_demand, adc_config::positive_input, adc_config::positive_input_sequence_mask_enable, adc_config::reference, adc_config::reference_compensation_enable, adc_config::resolution, adc_config::run_in_standby, adc_config::sample_length, adc_config::sampling_time_compensation_enable, adc_config::window, adc_window_config::window_lower_value, adc_window_config::window_mode, and adc_window_config::window_upper_value.
Referenced by configure_adc().
enum status_code adc_get_job_status | ( | struct adc_module * | module_inst, |
enum adc_job_type | type | ||
) |
Gets the status of a job.
Gets the status of an ongoing or the last job.
[in] | module_inst | Pointer to the ADC software instance struct |
[in] | type | Type of to get status |
References ADC_JOB_READ_BUFFER, Assert, and STATUS_ERR_INVALID_ARG.
|
inlinestatic |
Get ADC sequence status.
Check if a sequence is done and get last conversion done in the sequence.
[in] | module_inst | Pointer to the ADC software instance struct |
[out] | is_sequence_busy | Sequence busy status |
[out] | sequence_state | This value identifies the last conversion done in the sequence |
References Assert.
|
inlinestatic |
Retrieves the current module status.
Retrieves the status of the module, giving overall state information.
[in] | module_inst | Pointer to the ADC software instance struct |
ADC_STATUS_*
flags.ADC_STATUS_RESULT_READY | ADC result is ready to be read |
ADC_STATUS_WINDOW | ADC has detected a value inside the set window range |
ADC_STATUS_OVERRUN | ADC result has overrun |
References ADC_STATUS_OVERRUN, ADC_STATUS_RESULT_READY, ADC_STATUS_WINDOW, and Assert.
Referenced by adc_read().
enum status_code adc_init | ( | struct adc_module *const | module_inst, |
Adc * | hw, | ||
struct adc_config * | config | ||
) |
Initializes the ADC.
Initializes the ADC device struct and the hardware module based on the given configuration struct values.
[out] | module_inst | Pointer to the ADC software instance struct |
[in] | hw | Pointer to the ADC module instance |
[in] | config | Pointer to the configuration struct |
STATUS_OK | The initialization was successful |
STATUS_ERR_INVALID_ARG | Invalid argument(s) were provided |
STATUS_BUSY | The module is busy with a reset operation |
STATUS_ERR_DENIED | The module is enabled |
References _adc_get_inst_index(), _adc_instances, _adc_set_config(), ADC_EVENT_ACTION_DISABLED, ADC_REFERENCE_INTREF, Assert, adc_config::event_action, adc_config::freerunning, adc_config::reference, STATUS_BUSY, STATUS_ERR_DENIED, STATUS_OK, system_apb_clock_set_mask(), SYSTEM_CLOCK_APB_APBC, SYSTEM_CLOCK_APB_APBD, system_voltage_reference_enable(), and SYSTEM_VOLTAGE_REFERENCE_OUTPUT.
Referenced by configure_adc().
|
inlinestatic |
Reads the ADC result.
Reads the result from an ADC conversion that was previously started.
[in] | module_inst | Pointer to the ADC software instance struct |
[out] | result | Pointer to store the result value in |
STATUS_OK | The result was retrieved successfully |
STATUS_BUSY | A conversion result was not ready |
STATUS_ERR_OVERFLOW | The result register has been overwritten by the ADC module before the result was read by the software |
References adc_clear_status(), adc_get_status(), ADC_STATUS_OVERRUN, ADC_STATUS_RESULT_READY, Assert, STATUS_BUSY, STATUS_ERR_OVERFLOW, and STATUS_OK.
enum status_code adc_read_buffer_job | ( | struct adc_module *const | module_inst, |
uint16_t * | buffer, | ||
uint16_t | samples | ||
) |
Read multiple samples from ADC.
Read samples
from the ADC into the buffer
. If there is no hardware trigger defined (event action) the driver will retrigger the ADC conversion whenever a conversion is complete until samples
has been acquired. To avoid jitter in the sampling frequency using an event trigger is advised.
[in] | module_inst | Pointer to the ADC software instance struct |
[in] | samples | Number of samples to acquire |
[out] | buffer | Buffer to store the ADC samples |
STATUS_OK | The conversion job was started successfully and is in progress |
STATUS_BUSY | The ADC is already busy with another job |
References adc_enable_interrupt(), ADC_INTERRUPT_RESULT_READY, adc_start_conversion(), Assert, STATUS_BUSY, and STATUS_OK.
void adc_register_callback | ( | struct adc_module *const | module, |
adc_callback_t | callback_func, | ||
enum adc_callback | callback_type | ||
) |
Registers a callback.
Registers a callback function which is implemented by the user.
[in] | module | Pointer to ADC software instance struct |
[in] | callback_func | Pointer to callback function |
[in] | callback_type | Callback type given by an enum |
References Assert.
|
inlinestatic |
Resets the ADC module.
Resets an ADC module, clearing all module state, and registers to their default values.
[in] | module_inst | Pointer to the ADC software instance struct |
References adc_disable(), Assert, and STATUS_OK.
|
inlinestatic |
Set ADC master and slave mode.
Enable ADC module Master-Slave Operation and select dual mode trigger.
[in] | master_inst | Pointer to the master ADC software instance struct |
[in] | slave_inst | Pointer to the slave ADC software instance struct |
[in] | dualsel | Dual mode trigger selection |
References Assert.
|
inlinestatic |
Sets negative ADC input pin for differential mode.
Sets the negative ADC input pin, when the ADC is configured in differential mode.
[in] | module_inst | Pointer to the ADC software instance struct |
[in] | negative_input | Negative input pin |
References Assert.
|
inlinestatic |
Sets positive ADC input pin.
Sets the positive ADC input pin selection.
[in] | module_inst | Pointer to the ADC software instance struct |
[in] | positive_input | Positive input pin |
References Assert.
void adc_set_window_mode | ( | struct adc_module *const | module_inst, |
const enum adc_window_mode | window_mode, | ||
const int16_t | window_lower_value, | ||
const int16_t | window_upper_value | ||
) |
Sets the ADC window mode.
Sets the ADC window mode to a given mode and value range.
[in] | module_inst | Pointer to the ADC software instance struct |
[in] | window_mode | Window monitor mode to set |
[in] | window_lower_value | Lower window monitor threshold value |
[in] | window_upper_value | Upper window monitor threshold value |
References Assert.
|
inlinestatic |
Starts an ADC conversion.
Starts a new ADC conversion.
[in] | module_inst | Pointer to the ADC software instance struct |
References Assert.
Referenced by _adc_interrupt_handler(), and adc_read_buffer_job().
void adc_unregister_callback | ( | struct adc_module *const | module, |
enum adc_callback | callback_type | ||
) |
Unregisters a callback.
Unregisters a callback function which is implemented by the user.
[in] | module | Pointer to ADC software instance struct |
[in] | callback_type | Callback type given by an enum |
References Assert.