Driver for the DAC8 peripheral on RA MCUs. This module implements the DAC Interface.
Overview
Features
The DAC8 module outputs one of 256 voltage levels between the positive and negative reference voltages. DAC8 on selected MCUs have below features
- Charge pump control
- Synchronization with the Analog-to-Digital Converter (ADC) module
- Multiple Operation Modes
- Normal
- Real-Time (Event Link)
Configuration
- Note
- For MCUs supporting more than one channel, the following configuration options are shared by all the DAC8 channels:
- Synchronize with ADC
- Charge Pump
Build Time Configurations for r_dac8
The following build time configurations are defined in fsp_cfg/r_dac8_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 > DAC8 (r_dac8)
This module can be added to the Stacks tab via New Stack > Analog > DAC8 (r_dac8).
Configuration | Options | Default | Description |
Name | Name must be a valid C symbol | g_dac8_0 | Module name. |
Channel | Value must be an integer greater than or equal to 0 | 0 | Specify the hardware channel. |
D/A A/D Synchronous Conversion | MCU Specific Options | | Synchronize the DAC8 update with the ADC to reduce interference with A/D conversions. |
DAC Mode | MCU Specific Options | | Select the DAC operating mode |
Real-time Trigger Event | MCU Specific Options | | Specify the event used to trigger conversion in Real-time mode. This setting is only valid when Real-time mode is enabled. |
Charge Pump (Requires MOCO active) | MCU Specific Options | | Enable the DAC charge pump. |
Clock Configuration
The DAC8 peripheral module uses the PCLKB as its clock source.
Pin Configuration
The DA8_n pins are used as analog outputs. Each DAC8 channel has one output pin.
The AVCC0 and AVSS0 pins are power and ground supply and reference pins for the DAC8.
Usage Notes
Charge Pump
The charge pump must be enabled when using DAC8 pin output while operating at AVCC < 2.7V.
- Note
- The MOCO must be running to use the charge pump.
-
If DAC8 output is to be routed to an internal signal, do not enable the charge pump.
Synchronization with ADC
When ADC synchronization is enabled and an ADC conversion is in progress, if a DAC8 conversion is started it will automatically be delayed until after the ADC conversion is complete.
Real-time Mode
When Real-time mode is selected, the DAC8 will perform a conversion each time the selected ELC event is received.
Limitations
- Synchronization between DAC8 and ADC is activated when calling R_DAC8_Open. At this point synchronization cannot be deactivated by the driver. In order to desynchronize DAC8 with ADC, manually clear DACADSCR.DACADST to 0 while the ADCSR.ADST bit is 0 and the ADC is halted.
- For MCUs having more than 1 DAC8 channel, both channels are synchronized with ADC if synchronization is enabled.
Examples
Basic Example
This is a basic example of minimal use of the R_DAC8 in an application. This example shows how this driver can be used for basic 8 bit Digital to Analog Conversion operations.
{
.ad_da_synchronized = false,
.p_extend = &g_dac8_cfg_extend
};
void basic_example (void)
{
uint16_t value;
assert(FSP_SUCCESS == err);
value = (uint8_t) DAC8_EXAMPLE_VALUE_ABC;
assert(FSP_SUCCESS == err);
assert(FSP_SUCCESS == err);
}
◆ dac8_instance_ctrl_t
struct dac8_instance_ctrl_t |
DAC8 instance control block. DO NOT INITIALIZE.
◆ dac8_extended_cfg_t
struct dac8_extended_cfg_t |
DAC8 extended configuration
Data Fields |
bool |
enable_charge_pump |
Enable DAC charge pump. |
dac8_mode_t |
dac_mode |
DAC mode. |
◆ dac8_mode_t
Enumerator |
---|
DAC8_MODE_NORMAL | DAC Normal mode.
|
DAC8_MODE_REAL_TIME | DAC Real-time (event link) mode.
|
◆ R_DAC8_Open()
Perform required initialization described in hardware manual.
Implements dac_api_t::open.
Configures a single DAC channel. 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 | One or both of the following parameters may be NULL: p_ctrl or p_cfg |
FSP_ERR_ALREADY_OPEN | The instance control structure has already been opened. |
FSP_ERR_IP_CHANNEL_NOT_PRESENT | An invalid channel was requested. |
FSP_ERR_NOT_ENABLED | Setting DACADSCR is not enabled when ADCSR.ADST = 0. |
- Note
- This function is reentrant for different channels. It is not reentrant for the same channel.
◆ R_DAC8_Write()
Write data to the D/A converter.
- Return values
-
FSP_SUCCESS | Data is successfully written to the D/A Converter. |
FSP_ERR_ASSERTION | p_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Channel associated with p_instance_ctrl has not been opened. |
FSP_ERR_OVERFLOW | Data overflow when data value exceeds 8-bit limit. |
◆ R_DAC8_Start()
Start the D/A conversion output.
- Return values
-
FSP_SUCCESS | The channel is started successfully. |
FSP_ERR_ASSERTION | p_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Channel associated with p_instance_ctrl has not been opened. |
FSP_ERR_IN_USE | Attempt to re-start a channel. |
◆ R_DAC8_Stop()
Stop the D/A conversion and disable the output signal.
- Return values
-
FSP_SUCCESS | The control is successfully stopped. |
FSP_ERR_ASSERTION | p_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Channel associated with p_instance_ctrl has not been opened. |
◆ R_DAC8_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_ctrl is NULL. |
FSP_ERR_NOT_OPEN | Channel associated with p_instance_ctrl has not been opened. |