Driver for the DAC12 peripheral on RA MCUs. This module implements the DAC Interface.
Overview
Features
The DAC_B 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
Build Time Configurations for r_dac_b
The following build time configurations are defined in fsp_cfg/r_dac_b_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_b)
This module can be added to the Stacks tab via New Stack > Analog > DAC (r_dac_b). 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_dac_b0 | Module name. |
Channel | Value must be an integer greater than or equal to 0 | 0 | Specify the hardware channel. |
DAC Operating Voltage Mode |
-
Normal voltage mode (VREFH >= 2.7v)
-
Low voltage mode (VREFH < 2.7v)
| Normal voltage mode (VREFH >= 2.7v) | Select VREFH voltage for optimization of DAC output. |
Data Format |
-
Right Justified
-
Left Justified
| Right Justified | Specify the DAC data format. |
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. |
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
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.
This functionality must be enabled during configuration using dac_b_extended_cfg_t::internal_output_enabled. When internal output is enabled, the DAC output will be routed to internal modules. If the internal output is disabled, the output will be routed to the DAC output pin (DAn).
Examples
Basic Example
This is a basic example of minimal use of the R_DAC_B 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;
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
}
◆ dac_b_instance_ctrl_t
struct dac_b_instance_ctrl_t |
DAC instance control block.
◆ dac_b_extended_cfg_t
struct dac_b_extended_cfg_t |
DAC extended configuration
Data Fields |
bool |
internal_output_enabled |
Internal output enable available on selected MCUs. |
dac_data_format_t |
data_format |
Data format. |
dac_b_vrefh_t |
vrefh |
High voltage reference range. |
◆ dac_b_vrefh_t
DAC Vref Type
Enumerator |
---|
DAC_B_VREFH_NORMAL | VREFH >= 2.7v.
|
DAC_B_VREFH_LOW | VREFH < 2.7v.
|
◆ R_DAC_B_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
|
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_B_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_B_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_B_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_B_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. |