RA Flexible Software Package Documentation  Release v5.7.0

 
DAC (r_dac)

Functions

fsp_err_t R_DAC_Open (dac_ctrl_t *p_api_ctrl, dac_cfg_t const *const p_cfg)
 
fsp_err_t R_DAC_Write (dac_ctrl_t *p_api_ctrl, uint16_t value)
 
fsp_err_t R_DAC_Start (dac_ctrl_t *p_api_ctrl)
 
fsp_err_t R_DAC_Stop (dac_ctrl_t *p_api_ctrl)
 
fsp_err_t R_DAC_Close (dac_ctrl_t *p_api_ctrl)
 

Detailed Description

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.

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:

ConfigurationOptionsDefaultDescription
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.

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_dac0 Module name.
ChannelValue must be an integer greater than or equal to 00 Specify the hardware channel.
Synchronize with ADCMCU Specific OptionsEnable DA/AD synchronization.
Data Format
  • Right Justified
  • Left Justified
Right Justified Specify the DAC data format.
Output AmplifierMCU Specific OptionsEnable the DAC output amplifier.
Charge Pump (Requires MOCO active)MCU Specific OptionsEnable the DAC charge pump.
Internal OutputMCU Specific OptionsEnable DAC output to internal modules.
ELC Trigger SourceMCU Specific OptionsELC event source that will trigger the DAC to start a conversion.
Reference VoltageMCU Specific OptionsSelect 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

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)
{
fsp_err_t err;
uint16_t value;
/* Pin configuration: Output enable DA0 as Analog. */
/* Initialize the DAC channel */
err = R_DAC_Open(&g_dac_ctrl, &g_dac_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
value = (uint16_t) DAC_EXAMPLE_VALUE_ABC;
err = R_DAC_Write(&g_dac_ctrl, value);
assert(FSP_SUCCESS == err);
err = R_DAC_Start(&g_dac_ctrl);
assert(FSP_SUCCESS == err);
}

Data Structures

struct  dac_instance_ctrl_t
 
struct  dac_extended_cfg_t
 

Enumerations

enum  dac_ref_volt_sel_t
 

Data Structure Documentation

◆ 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.

Enumeration Type Documentation

◆ 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.

Function Documentation

◆ R_DAC_Open()

fsp_err_t R_DAC_Open ( dac_ctrl_t p_api_ctrl,
dac_cfg_t const *const  p_cfg 
)

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_SUCCESSThe channel was successfully opened.
FSP_ERR_ASSERTIONParameter check failure due to one or more reasons below:
  1. One or both of the following parameters may be NULL: p_api_ctrl or p_cfg
  2. data_format value in p_cfg is out of range.
  3. Extended configuration structure is set to NULL for MCU supporting charge pump.
FSP_ERR_IP_CHANNEL_NOT_PRESENTChannel ID requested in p_cfg may not available on the devices.
FSP_ERR_ALREADY_OPENThe control structure is already opened.

◆ R_DAC_Write()

fsp_err_t R_DAC_Write ( dac_ctrl_t p_api_ctrl,
uint16_t  value 
)

Write data to the D/A converter and enable the output if it has not been enabled.

Return values
FSP_SUCCESSData is successfully written to the D/A Converter.
FSP_ERR_ASSERTIONp_api_ctrl is NULL.
FSP_ERR_NOT_OPENChannel associated with p_ctrl has not been opened.

◆ R_DAC_Start()

fsp_err_t R_DAC_Start ( dac_ctrl_t p_api_ctrl)

Start the D/A conversion output if it has not been started.

Return values
FSP_SUCCESSThe channel is started successfully.
FSP_ERR_ASSERTIONp_api_ctrl is NULL.
FSP_ERR_IN_USEAttempt to re-start a channel.
FSP_ERR_NOT_OPENChannel associated with p_ctrl has not been opened.

◆ R_DAC_Stop()

fsp_err_t R_DAC_Stop ( dac_ctrl_t p_api_ctrl)

Stop the D/A conversion and disable the output signal.

Return values
FSP_SUCCESSThe control is successfully stopped.
FSP_ERR_ASSERTIONp_api_ctrl is NULL.
FSP_ERR_NOT_OPENChannel associated with p_ctrl has not been opened.

◆ R_DAC_Close()

fsp_err_t R_DAC_Close ( dac_ctrl_t p_api_ctrl)

Stop the D/A conversion, stop output, and close the DAC channel.

Return values
FSP_SUCCESSThe channel is successfully closed.
FSP_ERR_ASSERTIONp_api_ctrl is NULL.
FSP_ERR_NOT_OPENChannel associated with p_ctrl has not been opened.