This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's SDADC functionality.
Support and FAQ: visit Microchip Support
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.
The Sigma-Delta Analog-to-Digital Converter (SDADC) converts analog signals to digital values. The sigma-delta architecture of the SDADC implies a filtering and a decimation of the bitstream at the output of the SDADC. The input selection is up to three input analog channels.
The SDADC provides up to 16-bit resolution at about 1000 samples per second (1KSPS) and sized 24 bits signed result to handle filtering and gain correction without overflow. The SDADC measurements can be started by either application software or an incoming event from another peripheral in the device.
The conversion is performed on a full range between 0V and the reference voltage. Both internal and external reference voltages can be selected. The reference range must be set to match the voltage of the reference used. Analog inputs between these voltages convert to values based on a linear conversion.
A generic clock (GCLK_SDADC) is required to generate the CLK_SDADC to the SDADC module. The SDADC features a prescaler, which enables conversion at lower clock rates than the input Generic Clock to the SDADC module.
The SDADC data sampling frequency (CLK_SDADC_FS) in the SDADC module is the CLK_SDADC/4, the reduction comes from the phase generator between the prescaler and the SDADC.
OSR is the Over Sampling Ratio, which can be modified to change the output data rate. The conversion time depends on the selected OSR and the sampling frequency of the SDADC. The conversion time can be described with:
\[ t_{SAMPLE} = \frac {22 + 3 \times OSR} {CLK \_ SDADC \_ FS} \]
A specific offset, gain, and shift can be applied to each source of the SDADC by performing the following operation:
\[ Data = (Data_{0} + OFFSET) \times \frac {GAIN}{2^{SHIFT}} \]
The SDADC module window monitor function can be used to automatically compare the conversion result against a predefined pair of upper and lower threshold values.
Event generation and event actions are configurable in the SDADC.
The SDADC has two actions that can be triggered upon event reception:
The SDADC can generate two kinds of 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.
There are no special considerations for this module.
For extra information see Extra Information for SDADC Driver. This includes:
For a list of examples related to this driver, see Examples for SDADC Driver.
Modules | |
Quick Start Guide(s) | |
In this section you can find a list of all Quick Start guides related to the SAM Sigma-Delta Analog-to-Digital Converter (SDADC) Driver. | |
Data Structures | |
struct | sdadc_config |
SDADC configuration structure. More... | |
struct | sdadc_correction_config |
SDADC correction configuration structure. More... | |
struct | sdadc_events |
SDADC event enable/disable structure. More... | |
struct | sdadc_module |
SDADC software device instance structure. More... | |
struct | sdadc_reference |
Reference configuration structure. More... | |
struct | sdadc_window_config |
Window monitor configuration structure. More... | |
Typedefs | |
typedef void(* | sdadc_callback_t )(const struct sdadc_module *const module) |
Type of the callback functions. More... | |
Enumerations | |
enum | sdadc_callback { SDADC_CALLBACK_READ_BUFFER, SDADC_CALLBACK_WINDOW, SDADC_CALLBACK_ERROR } |
SDADC Callback enum. More... | |
enum | sdadc_event_action { SDADC_EVENT_ACTION_DISABLED = 0, SDADC_EVENT_ACTION_FLUSH_START_CONV = SDADC_EVCTRL_FLUSHEI, SDADC_EVENT_ACTION_START_CONV = SDADC_EVCTRL_STARTEI } |
SDADC event action enum. More... | |
enum | sdadc_interrupt_flag { SDADC_INTERRUPT_RESULT_READY = SDADC_INTFLAG_RESRDY, SDADC_INTERRUPT_OVERRUN = SDADC_INTFLAG_OVERRUN, SDADC_INTERRUPT_WINDOW = SDADC_INTFLAG_WINMON } |
Enum for the possible SDADC interrupt flags. More... | |
enum | sdadc_job_type { SDADC_JOB_READ_BUFFER } |
Enum for the possible types of SDADC asynchronous jobs that may be issued to the driver. More... | |
enum | sdadc_mux_input { SDADC_MUX_INPUT_AIN0 = SDADC_INPUTCTRL_MUXSEL_AIN0, SDADC_MUX_INPUT_AIN1 = SDADC_INPUTCTRL_MUXSEL_AIN1, SDADC_MUX_INPUT_AIN2 = SDADC_INPUTCTRL_MUXSEL_AIN2 } |
SDADC MUX input selection enum. More... | |
enum | sdadc_over_sampling_ratio { SDADC_OVER_SAMPLING_RATIO64 = SDADC_CTRLB_OSR(0), SDADC_OVER_SAMPLING_RATIO128 = SDADC_CTRLB_OSR(1), SDADC_OVER_SAMPLING_RATIO256 = SDADC_CTRLB_OSR(2), SDADC_OVER_SAMPLING_RATIO512 = SDADC_CTRLB_OSR(3), SDADC_OVER_SAMPLING_RATIO1024 = SDADC_CTRLB_OSR(4) } |
SDADC over sampling ratio enum. More... | |
enum | sdadc_reference_range { SDADC_REFRANGE_0 = SDADC_REFCTRL_REFRANGE(0), SDADC_REFRANGE_1 = SDADC_REFCTRL_REFRANGE(1), SDADC_REFRANGE_2 = SDADC_REFCTRL_REFRANGE(2), SDADC_REFRANGE_3 = SDADC_REFCTRL_REFRANGE(3) } |
SDADC reference range enum. More... | |
enum | sdadc_reference_select { SDADC_REFERENCE_INTREF = SDADC_REFCTRL_REFSEL(0), SDADC_REFERENCE_AREFB = SDADC_REFCTRL_REFSEL(1), SDADC_REFERENCE_DACOUT = SDADC_REFCTRL_REFSEL(2), SDADC_REFERENCE_INTVCC = SDADC_REFCTRL_REFSEL(3) } |
SDADC reference voltage enum. More... | |
enum | sdadc_window_mode { SDADC_WINDOW_MODE_DISABLE = SDADC_WINCTRL_WINMODE(0), SDADC_WINDOW_MODE_ABOVE = SDADC_WINCTRL_WINMODE(1), SDADC_WINDOW_MODE_BELOW = SDADC_WINCTRL_WINMODE(2), SDADC_WINDOW_MODE_INSIDE = SDADC_WINCTRL_WINMODE(3), SDADC_WINDOW_MODE_OUTSIDE = SDADC_WINCTRL_WINMODE(4) } |
SDADC window monitor mode enum. More... | |
Callback Management | |
void | sdadc_register_callback (struct sdadc_module *const module, sdadc_callback_t callback_func, enum sdadc_callback callback_type) |
Registers a callback. More... | |
void | sdadc_unregister_callback (struct sdadc_module *module, enum sdadc_callback callback_type) |
Unregisters a callback. More... | |
static void | sdadc_enable_callback (struct sdadc_module *const module, enum sdadc_callback callback_type) |
Enables callback. More... | |
static void | sdadc_disable_callback (struct sdadc_module *const module, enum sdadc_callback callback_type) |
Disables callback. More... | |
Job Management | |
enum status_code | sdadc_read_buffer_job (struct sdadc_module *const module_inst, int32_t *buffer, uint16_t samples) |
Read multiple samples from SDADC. More... | |
enum status_code | sdadc_get_job_status (struct sdadc_module *module_inst, enum sdadc_job_type type) |
Gets the status of a job. More... | |
void | sdadc_abort_job (struct sdadc_module *module_inst, enum sdadc_job_type type) |
Aborts an ongoing job. More... | |
Module Status Flags | |
SDADC status flags, returned by sdadc_get_status() and cleared by sdadc_clear_status(). | |
#define | SDADC_STATUS_RESULT_READY (1UL << 0) |
SDADC result ready. More... | |
#define | SDADC_STATUS_OVERRUN (1UL << 1) |
SDADC result overwritten before read. More... | |
#define | SDADC_STATUS_WINDOW (1UL << 2) |
Window monitor match. More... | |
Driver Initialization and Configuration | |
enum status_code | sdadc_init (struct sdadc_module *const module_inst, Sdadc *hw, struct sdadc_config *config) |
Initializes the SDADC. More... | |
static void | sdadc_get_config_defaults (struct sdadc_config *const config) |
Initializes an SDADC configuration structure to defaults. More... | |
Status Management | |
static uint32_t | sdadc_get_status (struct sdadc_module *const module_inst) |
Retrieves the current module status. More... | |
static void | sdadc_clear_status (struct sdadc_module *const module_inst, const uint32_t status_flags) |
Clears a module status flag. More... | |
static bool | sdadc_get_sequence_status (struct sdadc_module *const module_inst, uint8_t *seq_state) |
Get a module sequence flag. More... | |
Enable, Disable, and Reset SDADC Module, Start Conversion and Read Result | |
static bool | sdadc_is_syncing (struct sdadc_module *const module_inst) |
Determines if the hardware module(s) are currently synchronizing to the bus. More... | |
static enum status_code | sdadc_enable (struct sdadc_module *const module_inst) |
Enables the SDADC module. More... | |
static enum status_code | sdadc_disable (struct sdadc_module *const module_inst) |
Disables the SDADC module. More... | |
static enum status_code | sdadc_reset (struct sdadc_module *const module_inst) |
Resets the SDADC module. More... | |
static void | sdadc_enable_events (struct sdadc_module *const module_inst, struct sdadc_events *const events) |
Enables an SDADC event input or output. More... | |
static void | sdadc_disable_events (struct sdadc_module *const module_inst, struct sdadc_events *const events) |
Disables an SDADC event input or output. More... | |
static void | sdadc_start_conversion (struct sdadc_module *const module_inst) |
Starts an SDADC conversion. More... | |
static enum status_code | sdadc_read (struct sdadc_module *const module_inst, int32_t *result) |
Reads the SDADC result. More... | |
Runtime Changes of SDADC Module | |
static void | sdadc_flush (struct sdadc_module *const module_inst) |
Flushes the SDADC pipeline. More... | |
static void | sdadc_set_window_mode (struct sdadc_module *const module_inst, const enum sdadc_window_mode window_mode, const int16_t window_lower_value, const int16_t window_upper_value) |
Sets the SDADC window mode. More... | |
static void | sdadc_set_mux_input (struct sdadc_module *const module_inst, const enum sdadc_mux_input mux_input) |
Sets MUX SDADC input pin. More... | |
Enable and Disable Interrupts | |
static void | sdadc_enable_interrupt (struct sdadc_module *const module_inst, enum sdadc_interrupt_flag interrupt) |
Enable interrupt. More... | |
static void | sdadc_disable_interrupt (struct sdadc_module *const module_inst, enum sdadc_interrupt_flag interrupt) |
Disable interrupt. More... | |
#define SDADC_STATUS_OVERRUN (1UL << 1) |
SDADC result overwritten before read.
Referenced by sdadc_clear_status(), sdadc_get_status(), and sdadc_read().
#define SDADC_STATUS_RESULT_READY (1UL << 0) |
SDADC result ready.
Referenced by sdadc_clear_status(), sdadc_get_status(), and sdadc_read().
#define SDADC_STATUS_WINDOW (1UL << 2) |
Window monitor match.
Referenced by sdadc_clear_status(), and sdadc_get_status().
typedef void(* sdadc_callback_t)(const struct sdadc_module *const module) |
Type of the callback functions.
enum sdadc_callback |
enum sdadc_event_action |
enum sdadc_interrupt_flag |
enum sdadc_job_type |
enum sdadc_mux_input |
SDADC over sampling ratio enum.
Enum for the over sampling ratio, which change the output data rate.
enum sdadc_window_mode |
SDADC window monitor mode enum.
Enum for the possible window monitor modes for the SDADC.
void sdadc_abort_job | ( | struct sdadc_module * | module_inst, |
enum sdadc_job_type | type | ||
) |
Aborts an ongoing job.
Aborts an ongoing job with given type.
[in] | module_inst | Pointer to the SDADC software instance struct |
[in] | type | Type of job to abort |
References Assert, sdadc_disable_interrupt(), SDADC_INTERRUPT_RESULT_READY, SDADC_JOB_READ_BUFFER, and STATUS_ABORTED.
|
inlinestatic |
Clears a module status flag.
Clears the given status flag of the module.
[in] | module_inst | Pointer to the SDADC software instance struct |
[in] | status_flags | Bitmask of SDADC_STATUS_* flags to clear |
References Assert, SDADC_STATUS_OVERRUN, SDADC_STATUS_RESULT_READY, and SDADC_STATUS_WINDOW.
Referenced by sdadc_read().
|
inlinestatic |
Disables the SDADC module.
Disables an SDADC module that was previously enabled.
[in] | module_inst | Pointer to the SDADC software instance struct |
References Assert, sdadc_is_syncing(), STATUS_OK, and system_interrupt_disable().
Referenced by sdadc_reset().
|
inlinestatic |
Disables callback.
Disables the callback function registered by the sdadc_register_callback.
[in] | module | Pointer to SDADC 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 Assert, SDADC_CALLBACK_ERROR, SDADC_CALLBACK_WINDOW, sdadc_disable_interrupt(), SDADC_INTERRUPT_OVERRUN, and SDADC_INTERRUPT_WINDOW.
|
inlinestatic |
Disables an SDADC event input or output.
Disables one or more input or output events to or from the SDADC module. See sdadc_events for a list of events this module supports.
[in] | module_inst | Software instance for the SDADC peripheral |
[in] | events | Struct containing flags of events to disable |
References Assert, sdadc_events::generate_event_on_conversion_done, and sdadc_events::generate_event_on_window_monitor.
|
inlinestatic |
Disable interrupt.
Disable the given interrupt request from the SDADC module.
[in] | module_inst | Pointer to the SDADC software instance struct |
[in] | interrupt | Interrupt to disable |
References Assert.
Referenced by _sdadc_interrupt_handler(), sdadc_abort_job(), and sdadc_disable_callback().
|
inlinestatic |
Enables the SDADC module.
Enables an SDADC module that has previously been configured. If any internal reference is selected it will be enabled.
[in] | module_inst | Pointer to the SDADC software instance struct |
References Assert, sdadc_is_syncing(), STATUS_OK, and system_interrupt_enable().
Referenced by configure_sdadc().
|
inlinestatic |
Enables callback.
Enables the callback function registered by sdadc_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 SDADC 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 Assert, SDADC_CALLBACK_ERROR, SDADC_CALLBACK_WINDOW, sdadc_enable_interrupt(), SDADC_INTERRUPT_OVERRUN, and SDADC_INTERRUPT_WINDOW.
Referenced by configure_sdadc_callbacks().
|
inlinestatic |
Enables an SDADC event input or output.
Enables one or more input or output events to or from the SDADC module. See sdadc_events for a list of events this module supports.
[in] | module_inst | Software instance for the SDADC peripheral |
[in] | events | Struct containing flags of events to enable |
References Assert, sdadc_events::generate_event_on_conversion_done, and sdadc_events::generate_event_on_window_monitor.
|
inlinestatic |
Enable interrupt.
Enable the given interrupt request from the SDADC module.
[in] | module_inst | Pointer to the SDADC software instance struct |
[in] | interrupt | Interrupt to enable |
References Assert.
Referenced by sdadc_enable_callback(), and sdadc_read_buffer_job().
|
inlinestatic |
Flushes the SDADC pipeline.
Flushes the pipeline and restart the SDADC 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 SDADC software instance struct |
References Assert, and sdadc_is_syncing().
|
inlinestatic |
Initializes an SDADC configuration structure to defaults.
Initializes a given SDADC 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 Assert, sdadc_config::clock_prescaler, sdadc_config::clock_source, sdadc_config::correction, sdadc_config::event_action, sdadc_config::freerunning, sdadc_correction_config::gain_correction, GCLK_GENERATOR_0, sdadc_config::mux_input, sdadc_correction_config::offset_correction, sdadc_config::on_command, sdadc_reference::on_ref_buffer, sdadc_config::osr, sdadc_reference::ref_range, sdadc_reference::ref_sel, sdadc_config::reference, sdadc_config::run_in_standby, SDADC_EVENT_ACTION_DISABLED, SDADC_MUX_INPUT_AIN1, SDADC_OVER_SAMPLING_RATIO64, SDADC_REFERENCE_INTREF, SDADC_REFRANGE_0, SDADC_WINDOW_MODE_DISABLE, sdadc_config::seq_enable, sdadc_correction_config::shift_correction, sdadc_config::skip_count, sdadc_config::window, sdadc_window_config::window_lower_value, sdadc_window_config::window_mode, and sdadc_window_config::window_upper_value.
Referenced by configure_sdadc().
enum status_code sdadc_get_job_status | ( | struct sdadc_module * | module_inst, |
enum sdadc_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 SDADC software instance struct |
[in] | type | Type of job to abort |
References Assert, SDADC_JOB_READ_BUFFER, and STATUS_ERR_INVALID_ARG.
|
inlinestatic |
Get a module sequence flag.
Get the given status flag of the module.
[in] | module_inst | Pointer to the SDADC software instance struct |
[out] | seq_state | Identifies the last conversion done in the sequence |
true | When the sequence start |
false | When the last conversion in a sequence is done |
References Assert.
|
inlinestatic |
Retrieves the current module status.
Retrieves the status of the module, giving overall state information.
[in] | module_inst | Pointer to the SDADC software instance struct |
SDADC_STATUS_*
flags.SDADC_STATUS_RESULT_READY | SDADC result is ready to be read |
SDADC_STATUS_WINDOW | SDADC has detected a value inside the set window range |
SDADC_STATUS_OVERRUN | SDADC result has overrun |
References Assert, SDADC_STATUS_OVERRUN, SDADC_STATUS_RESULT_READY, and SDADC_STATUS_WINDOW.
Referenced by sdadc_read().
enum status_code sdadc_init | ( | struct sdadc_module *const | module_inst, |
Sdadc * | hw, | ||
struct sdadc_config * | config | ||
) |
Initializes the SDADC.
Initializes the SDADC device struct and the hardware module based on the given configuration struct values.
[out] | module_inst | Pointer to the SDADC software instance struct |
[in] | hw | Pointer to the SDADC 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 _sdadc_instances, _sdadc_set_config(), Assert, sdadc_config::event_action, sdadc_config::freerunning, i, module_inst, NULL, sdadc_config::reference, SDADC_EVENT_ACTION_DISABLED, STATUS_BUSY, STATUS_ERR_DENIED, STATUS_OK, system_apb_clock_set_mask(), and SYSTEM_CLOCK_APB_APBC.
Referenced by configure_sdadc().
|
inlinestatic |
Determines if the hardware module(s) are currently synchronizing to the bus.
Checks to see if the underlying hardware peripheral module(s) are currently synchronizing across multiple clock domains to the hardware bus. This function can be used to delay further operations on a module until such time that it is ready, to prevent blocking delays for synchronization in the user application.
[in] | module_inst | Pointer to the SDADC software instance struct |
true | If the module synchronization is ongoing |
false | If the module has completed synchronization |
References Assert.
Referenced by _sdadc_set_config(), sdadc_disable(), sdadc_enable(), sdadc_flush(), sdadc_reset(), sdadc_set_mux_input(), sdadc_set_window_mode(), and sdadc_start_conversion().
|
inlinestatic |
Reads the SDADC result.
Reads the result from an SDADC conversion that was previously started.
[in] | module_inst | Pointer to the SDADC 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 SDADC module before the result was read by the software |
References Assert, sdadc_clear_status(), sdadc_get_status(), SDADC_STATUS_OVERRUN, SDADC_STATUS_RESULT_READY, STATUS_BUSY, STATUS_ERR_OVERFLOW, and STATUS_OK.
Referenced by main().
enum status_code sdadc_read_buffer_job | ( | struct sdadc_module *const | module_inst, |
int32_t * | buffer, | ||
uint16_t | samples | ||
) |
Read multiple samples from SDADC.
Read samples
from the SDADC into the buffer
. If there is no hardware trigger defined (event action) the driver will retrigger the SDADC 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 SDADC software instance struct |
[in] | samples | Number of samples to acquire |
[out] | buffer | Buffer to store the SDADC samples |
STATUS_OK | The conversion job was started successfully and is in progress |
STATUS_BUSY | The SDADC is already busy with another job |
References Assert, buffer, sdadc_enable_interrupt(), SDADC_INTERRUPT_RESULT_READY, sdadc_start_conversion(), STATUS_BUSY, and STATUS_OK.
Referenced by main().
void sdadc_register_callback | ( | struct sdadc_module *const | module, |
sdadc_callback_t | callback_func, | ||
enum sdadc_callback | callback_type | ||
) |
Registers a callback.
Registers a callback function which is implemented by the user.
[in] | module | Pointer to SDADC software instance struct |
[in] | callback_func | Pointer to callback function |
[in] | callback_type | Callback type given by an enum |
References Assert.
Referenced by configure_sdadc_callbacks().
|
inlinestatic |
Resets the SDADC module.
Resets an SDADC module, clearing all module state, and registers to their default values.
[in] | module_inst | Pointer to the SDADC software instance struct |
References Assert, sdadc_disable(), sdadc_is_syncing(), and STATUS_OK.
|
inlinestatic |
Sets MUX SDADC input pin.
Sets the MUX SDADC input pin selection.
[in] | module_inst | Pointer to the SDADC software instance struct |
[in] | mux_input | MUX input pin |
References Assert, and sdadc_is_syncing().
|
inlinestatic |
Sets the SDADC window mode.
Sets the SDADC window mode to a given mode and value range.
[in] | module_inst | Pointer to the SDADC 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, and sdadc_is_syncing().
|
inlinestatic |
Starts an SDADC conversion.
Starts a new SDADC conversion.
[in] | module_inst | Pointer to the SDADC software instance struct |
References Assert, and sdadc_is_syncing().
Referenced by _sdadc_interrupt_handler(), main(), and sdadc_read_buffer_job().
void sdadc_unregister_callback | ( | struct sdadc_module *const | module, |
enum sdadc_callback | callback_type | ||
) |