Driver for the DAC12 peripheral on RA MCUs. This module implements the DAC Interface.
Overview
Features
The DAC module outputs one of 4096 voltage levels between the positive and negative reference voltages.
- Supports setting left-justified or right-justified 12-bit value format for the 16-bit input data registers
- Supports output amplifiers on selected MCUs
- Supports charge pump on selected MCUs
- Supports synchronization with the Analog-to-Digital Converter (ADC) module
Configuration
- Note
- For MCUs supporting more than one channel, the following configuration options are shared by all the DAC channels:
- Synchronize with ADC
- Data Format
- Charge Pump
Build Time Configurations for r_dac
The following build time configurations are defined in fsp_cfg/r_dac_cfg.h:
Configuration | Options | Default | Description |
Parameter Checking |
-
Default (BSP)
-
Enabled
-
Disabled
| Default (BSP) | If selected code for parameter checking is included in the build. |
Configurations for Analog > DAC (r_dac)
This module can be added to the Stacks tab via New Stack > Analog > DAC (r_dac). Non-secure callable guard functions can be generated for this module by right clicking the module in the RA Configuration tool and checking the "Non-secure Callable" box.
Configuration | Options | Default | Description |
Name | Name must be a valid C symbol | g_dac0 | Module name. |
Channel | Value must be an integer greater than or equal to 0 | 0 | Specify the hardware channel. |
Synchronize with ADC | MCU Specific Options | | Enable DA/AD synchronization. |
Data Format |
-
Right Justified
-
Left Justified
| Right Justified | Specify the DAC data format. |
Output Amplifier | MCU Specific Options | | Enable the DAC output amplifier. |
Charge Pump (Requires MOCO active) | MCU Specific Options | | Enable the DAC charge pump. |
Internal Output | MCU Specific Options | | Enable DAC output to internal modules. |
ELC Trigger Source | MCU Specific Options | | ELC event source that will trigger the DAC to start a conversion. |
Reference Voltage | MCU Specific Options | | Select the DAC reference voltage. |
Clock Configuration
The DAC peripheral module uses PCLKB as its clock source.
Pin Configuration
The DAn pins are used as analog outputs. Each DAC channel has one output pin.
The AVCC0 and AVSS0 pins are power and ground supply pins for the DAC and ADC.
The VREFH and VREFL pins are top and ground voltage reference pins for the DAC and ADC.
Usage Notes
Charge Pump
The charge pump must be enabled when using DAC pin output while operating at AVCC < 2.7V.
- Note
- The MOCO must be running to use the charge pump.
-
If the DAC output is to be routed to an internal signal, do not enable the charge pump.
Output to Internal Modules
The DAC output can be used as an analog input to other peripherals on the MCU (eg. ACMPHS, ADC) without outputting the voltage to an external pin.
On some MCUs this functionality must be enabled during configuration using dac_extended_cfg_t::internal_output_enabled. When internal output is enabled, the DAC output will be routed to internal modules. If the DAC output amplifier is enabled or when internal output is disabled, the output will be routed to the DAC output pin (DAn).
Synchronization with ADC
When ADC synchronization is enabled and an ADC conversion is in progress, if a DAC conversion is started it will automatically be delayed until after the ADC conversion is complete.
Limitations
- For MCUs supporting ADC unit 1:
- Once synchronization between DAC and ADC unit 1 is turned on during R_DAC_Open synchronization cannot be turned off by the driver. In order to desynchronize DAC with ADC unit 1, manually clear DAADSCR.DAADST to 0 when the ADCSR.ADST bit is 0 and ADC unit 1 is halted.
- The DAC module can only be synchronized with ADC unit 1.
- For MCUs having more than 1 DAC channel, both channels are synchronized with ADC unit 1 if synchronization is enabled.
Examples
Basic Example
This is a basic example of minimal use of the R_DAC in an application. This example shows how this driver can be used for basic Digital to Analog Conversion operations.
void basic_example (void)
{
uint16_t value;
assert(FSP_SUCCESS == err);
value = (uint16_t) DAC_EXAMPLE_VALUE_ABC;
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
}
◆ dac_instance_ctrl_t
struct dac_instance_ctrl_t |
DAC instance control block.
◆ dac_extended_cfg_t
struct dac_extended_cfg_t |
DAC extended configuration
Data Fields |
bool |
enable_charge_pump |
Enable DAC charge pump available on selected MCUs. |
bool |
output_amplifier_enabled |
Output amplifier enable available on selected MCUs. |
bool |
internal_output_enabled |
Internal output enable available on selected MCUs. |
dac_data_format_t |
data_format |
Data format. |
dac_ref_volt_sel_t |
ref_volt_sel |
Reference voltage selection. |
◆ dac_ref_volt_sel_t
DAC Reference voltage selection.
Enumerator |
---|
DAC_VREF_NONE | No reference voltage selected.
|
DAC_VREF_AVCC0_AVSS0 | Select AVCC0/AVSS0.
|
DAC_VREF_IVREF_AVSS0 | Select Internal reference voltage/AVSS0.
|
DAC_VREF_VREFH_VREFL | Select VREFH/VREFL.
|
◆ R_DAC_Open()
Perform required initialization described in hardware manual. Implements dac_api_t::open. Configures a single DAC channel, starts the channel, and provides a handle for use with the DAC API Write and Close functions. Must be called once prior to calling any other DAC API functions. After a channel is opened, Open should not be called again for the same channel without calling Close first.
- Return values
-
FSP_SUCCESS | The channel was successfully opened. |
FSP_ERR_ASSERTION | Parameter check failure due to one or more reasons below:
- One or both of the following parameters may be NULL: p_api_ctrl or p_cfg
- data_format value in p_cfg is out of range.
- Extended configuration structure is set to NULL for MCU supporting charge pump.
|
FSP_ERR_IP_CHANNEL_NOT_PRESENT | Channel ID requested in p_cfg may not available on the devices. |
FSP_ERR_ALREADY_OPEN | The control structure is already opened. |
◆ R_DAC_Write()
Write data to the D/A converter and enable the output if it has not been enabled.
- Return values
-
FSP_SUCCESS | Data is successfully written to the D/A Converter. |
FSP_ERR_ASSERTION | p_api_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Channel associated with p_ctrl has not been opened. |
◆ R_DAC_Start()
Start the D/A conversion output if it has not been started.
- Return values
-
FSP_SUCCESS | The channel is started successfully. |
FSP_ERR_ASSERTION | p_api_ctrl is NULL. |
FSP_ERR_IN_USE | Attempt to re-start a channel. |
FSP_ERR_NOT_OPEN | Channel associated with p_ctrl has not been opened. |
◆ R_DAC_Stop()
Stop the D/A conversion and disable the output signal.
- Return values
-
FSP_SUCCESS | The control is successfully stopped. |
FSP_ERR_ASSERTION | p_api_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Channel associated with p_ctrl has not been opened. |
◆ R_DAC_Close()
Stop the D/A conversion, stop output, and close the DAC channel.
- Return values
-
FSP_SUCCESS | The channel is successfully closed. |
FSP_ERR_ASSERTION | p_api_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Channel associated with p_ctrl has not been opened. |