See Quick start guide for XMEGA DAC.
This is a driver for versions 1 and 2, introduced with the XMEGA AU family, of the AVR XMEGA DAC. It provides functions for enabling, disabling and configuring the DAC and its channels.
Note that functions for configuring refresh interval and conversion timing are not present for version 2 of the DAC, since it does not need those settings. The symbols XMEGA_DAC_VERSION_1 and XMEGA_DAC_VERSION_2 can be used to tell, at compile time, which DAC the driver is compiled for.
The API functions and definitions can be divided in two groups:
The API makes use of a structure that contains the configuration. This structure must be set up before the configuration is written to a DAC module.
After the DAC has been configured, it must be enabled before any conversions can be done or any of its channel values be changed.
This driver depends on the following modules:
Modules | |
Related Project(s) | |
In this section you can find all the projects related to the Digital to Analog Converter (DAC). | |
Quick Start Guide(s) | |
In this section you can find a list of all Quick Start guides related to the Digital to Analog Converter (DAC). | |
Data Structures | |
struct | dac_config |
DAC configuration. More... | |
Macros | |
#define | XMEGA_DAC_VERSION_1 true |
Enumerations | |
enum | dac_adjust { DAC_ADJ_RIGHT, DAC_ADJ_LEFT = DAC_LEFTADJ_bm } |
DAC value adjust settings. More... | |
enum | dac_reference { DAC_REF_BANDGAP = DAC_REFSEL_INT1V_gc, DAC_REF_AVCC = DAC_REFSEL_AVCC_gc, DAC_REF_AREFA = DAC_REFSEL_AREFA_gc, DAC_REF_AREFB = DAC_REFSEL_AREFB_gc } |
DAC reference settings. More... | |
static void | dac_enable_clock (DAC_t *dac) |
Enable peripheral clock for DAC. More... | |
static void | dac_disable_clock (DAC_t *dac) |
Disable peripheral clock for DAC. More... | |
DAC channel masks | |
#define | DAC_CH0 (1 << 0) |
DAC channel 0. More... | |
#define | DAC_CH1 (1 << 1) |
DAC channel 1. More... | |
DAC module and channel management | |
void | dac_enable (DAC_t *dac) |
Enable DAC. More... | |
void | dac_disable (DAC_t *dac) |
Disable DAC. More... | |
bool | dac_is_enabled (DAC_t *dac) |
Check if DAC is enabled. More... | |
static __always_inline uint8_t | dac_get_calibration_data (enum dac_calibration_data cal) |
Get calibration data. More... | |
static __always_inline void | dac_set_channel_value (DAC_t *dac, uint8_t ch_mask, uint16_t val) |
Set value of DAC channel. More... | |
static __always_inline uint16_t | dac_get_channel_value (DAC_t *dac, uint8_t ch_mask) |
Get value of DAC channel. More... | |
static __always_inline bool | dac_channel_is_ready (DAC_t *dac, uint8_t ch_mask) |
Check whether DAC channel(s) are ready for data. More... | |
static __always_inline void | dac_wait_for_channel_ready (DAC_t *dac, uint8_t ch_mask) |
Wait for DAC channel(s) to get ready for data. More... | |
DAC module and channel configuration | |
void | dac_write_configuration (DAC_t *dac, struct dac_config *conf) |
Write configuration to DAC. More... | |
void | dac_read_configuration (DAC_t *dac, struct dac_config *conf) |
Read configuration from DAC. More... | |
static __always_inline void | dac_set_active_channel (struct dac_config *conf, uint8_t ch_mask, uint8_t int_out_ch_mask) |
Set active DAC channel(s) and output(s) More... | |
static __always_inline void | dac_set_refresh_interval (struct dac_config *conf, uint8_t us) |
Set automatic refresh timing interval. More... | |
static __always_inline void | dac_set_conversion_interval (struct dac_config *conf, uint8_t us) |
Set conversion timing interval. More... | |
static __always_inline void | dac_set_conversion_parameters (struct dac_config *conf, enum dac_reference ref, enum dac_adjust adj) |
Set DA conversion parameters. More... | |
static __always_inline void | dac_set_conversion_trigger (struct dac_config *conf, uint8_t ch_mask, uint8_t ev_ch) |
Set DA conversions triggers. More... | |
#define DAC_CH0 (1 << 0) |
DAC channel 0.
Referenced by dac_set_active_channel(), main(), run_differential_12bit_conversion_test(), run_differential_12bit_with_gain_conversion_test(), run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), run_single_channel_8bit_conversion_test(), run_single_ended_12bit_conversion_test(), and run_single_ended_8bit_conversion_test().
#define DAC_CH1 (1 << 1) |
DAC channel 1.
Referenced by dac_set_active_channel(), main(), run_differential_12bit_conversion_test(), run_differential_12bit_with_gain_conversion_test(), run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_ended_12bit_conversion_test(), and run_single_ended_8bit_conversion_test().
#define XMEGA_DAC_VERSION_1 true |
enum dac_adjust |
enum dac_reference |
|
static |
Check whether DAC channel(s) are ready for data.
Checks if the data registers for all of the masked DAC channels are ready for a new value. This indicates that a conversion with the current value has been completed.
dac | Pointer to DAC module. |
ch_mask | Mask of DAC channel(s) to check whether are ready:
|
true | if DAC channels are ready. |
false | if a DAC channel is not ready. |
References Assert.
Referenced by dac_wait_for_channel_ready().
void dac_disable | ( | DAC_t * | dac | ) |
Disable DAC.
Disables the DAC, stopping all conversions.
dac | Pointer to DAC module. |
References cpu_irq_restore(), cpu_irq_save(), dac_disable_clock(), SLEEPMGR_IDLE, and sleepmgr_unlock_mode().
|
static |
Disable peripheral clock for DAC.
Disables the peripheral clock for the specified DAC, unless the enable count indicates that it should be left enabled.
dac | Pointer to DAC module. |
References Assert, SYSCLK_DAC, sysclk_disable_module(), SYSCLK_PORT_A, and SYSCLK_PORT_B.
Referenced by dac_disable(), dac_read_configuration(), and dac_write_configuration().
void dac_enable | ( | DAC_t * | dac | ) |
Enable DAC.
Enables the DAC for conversions, and locks the sleep mode needed for the DAC to operate.
dac | Pointer to DAC module. |
References cpu_irq_restore(), cpu_irq_save(), dac_enable_clock(), SLEEPMGR_IDLE, and sleepmgr_lock_mode().
Referenced by main(), run_differential_12bit_conversion_test(), run_differential_12bit_with_gain_conversion_test(), run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), run_single_channel_8bit_conversion_test(), run_single_ended_12bit_conversion_test(), run_single_ended_8bit_conversion_test(), and sound_init().
|
static |
Enable peripheral clock for DAC.
Enables the peripheral clock for the specified DAC, unless it is already enabled.
dac | Pointer to DAC module. |
References Assert, SYSCLK_DAC, sysclk_enable_module(), SYSCLK_PORT_A, and SYSCLK_PORT_B.
Referenced by dac_enable(), dac_read_configuration(), and dac_write_configuration().
|
static |
Get calibration data.
Returns the specified calibration data from the production signature row.
cal | Identifier for calibration data to get. |
References nvm_read_production_signature_row().
Referenced by dac_write_configuration().
|
static |
Get value of DAC channel.
dac | Pointer to DAC module. |
ch_mask | Mask of DAC channel from which to retrieve the value:
|
References Assert, cpu_irq_restore(), cpu_irq_save(), and ilog2().
bool dac_is_enabled | ( | DAC_t * | dac | ) |
void dac_read_configuration | ( | DAC_t * | dac, |
struct dac_config * | conf | ||
) |
Read configuration from DAC.
Reads out the current configuration of the DAC to the specified buffer.
dac | Pointer to DAC module. |
conf | Pointer to DAC configuration. |
References cpu_irq_restore(), cpu_irq_save(), dac_config::ctrla, dac_config::ctrlb, dac_config::ctrlc, dac_disable_clock(), dac_enable_clock(), and dac_config::evctrl.
Referenced by main(), run_differential_12bit_conversion_test(), run_differential_12bit_with_gain_conversion_test(), run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), run_single_channel_8bit_conversion_test(), run_single_ended_12bit_conversion_test(), and run_single_ended_8bit_conversion_test().
|
static |
Set active DAC channel(s) and output(s)
Enables the masked DAC channels and configures their output. Either of the channels may be configured for internal output, but not both. Implicitly, channels that are not masked for internal output are configured for output on their respective pins.
conf | Pointer to DAC configuration. |
ch_mask | Mask of DAC channel(s) to enable:
|
int_out_ch_mask | Mask of DAC channel to connect to internal output:
|
References Assert, dac_config::ctrla, dac_config::ctrlb, DAC_CH0, DAC_CH1, and ilog2().
Referenced by main(), run_differential_12bit_conversion_test(), run_differential_12bit_with_gain_conversion_test(), run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), run_single_channel_8bit_conversion_test(), run_single_ended_12bit_conversion_test(), run_single_ended_8bit_conversion_test(), and sound_init().
|
static |
Set value of DAC channel.
dac | Pointer to DAC module. |
ch_mask | Mask of DAC channel for which to set the value:
|
val | 12-bit value to set. (Must be adjusted as configured in the conversion parameters with dac_set_conversion_parameters.) |
References Assert, cpu_irq_restore(), cpu_irq_save(), and ilog2().
Referenced by main(), run_differential_12bit_conversion_test(), run_differential_12bit_with_gain_conversion_test(), run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), run_single_channel_8bit_conversion_test(), run_single_ended_12bit_conversion_test(), run_single_ended_8bit_conversion_test(), and sample_callback().
|
static |
Set conversion timing interval.
Sets the timing interval from a conversion is completed until a new one can be started. This settings depends on whether single- or dual-channel mode is used, and so the channels should be configured before this function is called to ensure the proper configuration.
This interval is rounded downward to the closest setting.
conf | Pointer to DAC configuration. |
us | Microseconds between conversions:
|
References Assert, dac_config::ctrlb, ilog2(), and sysclk_get_per_hz().
Referenced by main(), run_differential_12bit_conversion_test(), run_differential_12bit_with_gain_conversion_test(), run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), run_single_channel_8bit_conversion_test(), run_single_ended_12bit_conversion_test(), run_single_ended_8bit_conversion_test(), and sound_init().
|
static |
Set DA conversion parameters.
Sets up the voltage reference and channel value adjust, i.e., whether the 12-bit value is shifted to the most significant (left) or least significant (right) bits in the channels' 16-bit data registers.
conf | Pointer to DAC configuration. |
ref | DAC voltage reference setting. |
adj | DAC value adjust setting. |
References dac_config::ctrlc.
Referenced by main(), run_differential_12bit_conversion_test(), run_differential_12bit_with_gain_conversion_test(), run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), run_single_channel_8bit_conversion_test(), run_single_ended_12bit_conversion_test(), run_single_ended_8bit_conversion_test(), and sound_init().
|
static |
Set DA conversions triggers.
Sets up event-triggering of conversions on the masked channels, and manual triggering on the others. Conversions are manually triggered by setting new channel values, while events only trigger new conversions if a new channel value was set since the last conversion.
conf | Pointer to DAC configuration. |
ev_ch | Event channel to use. |
ch_mask | Mask of DAC channel(s) to use event-triggering on:
|
References Assert, dac_config::ctrlb, and dac_config::evctrl.
Referenced by main(), run_differential_12bit_conversion_test(), run_differential_12bit_with_gain_conversion_test(), run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), run_single_channel_8bit_conversion_test(), run_single_ended_12bit_conversion_test(), run_single_ended_8bit_conversion_test(), and sound_init().
|
static |
Set automatic refresh timing interval.
Sets or disables the automatic refresh timing interval for dual-channel mode of the DAC. If it is disabled, the DAC channels must be manually refreshed by updating the channel values and triggering new conversions.
This interval is rounded downward to the closest setting.
conf | Pointer to DAC configuration. |
us | Microseconds between channel refresh:
|
References Assert, ilog2(), and sysclk_get_per_hz().
Referenced by main(), run_differential_12bit_conversion_test(), run_differential_12bit_with_gain_conversion_test(), run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), run_single_channel_8bit_conversion_test(), run_single_ended_12bit_conversion_test(), and run_single_ended_8bit_conversion_test().
|
static |
Wait for DAC channel(s) to get ready for data.
Busy-waits for all of the masked DAC channels' data registers to become ready for new values.
dac | Pointer to DAC module. |
ch_mask | Mask of DAC channel(s) to wait for data ready:
|
References Assert, and dac_channel_is_ready().
Referenced by main(), run_differential_12bit_conversion_test(), run_differential_12bit_with_gain_conversion_test(), run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), run_single_channel_8bit_conversion_test(), run_single_ended_12bit_conversion_test(), and run_single_ended_8bit_conversion_test().
void dac_write_configuration | ( | DAC_t * | dac, |
struct dac_config * | conf | ||
) |
Write configuration to DAC.
Disables the DAC before writing the specified configuration and factory calibration values to it. If the DAC was enabled upon entry of the function, it is enabled upon function return.
dac | Pointer to DAC module. |
conf | Pointer to DAC configuration. |
References Assert, cpu_irq_restore(), cpu_irq_save(), dac_config::ctrla, dac_config::ctrlb, dac_config::ctrlc, dac_disable_clock(), dac_enable_clock(), dac_get_calibration_data(), dac_config::evctrl, and UNUSED.
Referenced by main(), run_differential_12bit_conversion_test(), run_differential_12bit_with_gain_conversion_test(), run_dual_channel_12bit_conversion_test(), run_dual_channel_8bit_conversion_test(), run_single_channel_12bit_conversion_test(), run_single_channel_8bit_conversion_test(), run_single_ended_12bit_conversion_test(), run_single_ended_8bit_conversion_test(), and sound_init().