RA Flexible Software Package Documentation  Release v5.7.0

 
DAC8 (r_dac8)

Functions

fsp_err_t R_DAC8_Open (dac_ctrl_t *const p_ctrl, dac_cfg_t const *const p_cfg)
 
fsp_err_t R_DAC8_Write (dac_ctrl_t *const p_ctrl, uint16_t value)
 
fsp_err_t R_DAC8_Start (dac_ctrl_t *const p_ctrl)
 
fsp_err_t R_DAC8_Stop (dac_ctrl_t *const p_ctrl)
 
fsp_err_t R_DAC8_Close (dac_ctrl_t *const p_ctrl)
 

Detailed Description

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

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:

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

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_dac8_0 Module name.
ChannelValue must be an integer greater than or equal to 00 Specify the hardware channel.
D/A A/D Synchronous ConversionMCU Specific OptionsSynchronize the DAC8 update with the ADC to reduce interference with A/D conversions.
DAC ModeMCU Specific OptionsSelect the DAC operating mode
Real-time Trigger EventMCU Specific OptionsSpecify 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 OptionsEnable 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

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.

dac_cfg_t g_dac8_cfg =
{
.channel = 0U,
.ad_da_synchronized = false,
.p_extend = &g_dac8_cfg_extend
};
void basic_example (void)
{
fsp_err_t err;
uint16_t value;
/* Pin configuration: Output enable DA8_0(RA2A1) as Analog. */
/* Initialize the DAC8 channel */
err = R_DAC8_Open(&g_dac8_ctrl, &g_dac8_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
value = (uint8_t) DAC8_EXAMPLE_VALUE_ABC;
/* Write value to DAC module */
err = R_DAC8_Write(&g_dac8_ctrl, value);
assert(FSP_SUCCESS == err);
/* Start DAC8 conversion */
err = R_DAC8_Start(&g_dac8_ctrl);
assert(FSP_SUCCESS == err);
}

Data Structures

struct  dac8_instance_ctrl_t
 
struct  dac8_extended_cfg_t
 

Enumerations

enum  dac8_mode_t
 

Data Structure Documentation

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

Enumeration Type Documentation

◆ dac8_mode_t

Enumerator
DAC8_MODE_NORMAL 

DAC Normal mode.

DAC8_MODE_REAL_TIME 

DAC Real-time (event link) mode.

Function Documentation

◆ R_DAC8_Open()

fsp_err_t R_DAC8_Open ( dac_ctrl_t *const  p_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. 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_ASSERTIONOne or both of the following parameters may be NULL: p_ctrl or p_cfg
FSP_ERR_ALREADY_OPENThe instance control structure has already been opened.
FSP_ERR_IP_CHANNEL_NOT_PRESENTAn invalid channel was requested.
FSP_ERR_NOT_ENABLEDSetting 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()

fsp_err_t R_DAC8_Write ( dac_ctrl_t *const  p_ctrl,
uint16_t  value 
)

Write data to the D/A converter.

Return values
FSP_SUCCESSData is successfully written to the D/A Converter.
FSP_ERR_ASSERTIONp_ctrl is NULL.
FSP_ERR_NOT_OPENChannel associated with p_instance_ctrl has not been opened.
FSP_ERR_OVERFLOWData overflow when data value exceeds 8-bit limit.

◆ R_DAC8_Start()

fsp_err_t R_DAC8_Start ( dac_ctrl_t *const  p_ctrl)

Start the D/A conversion output.

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

◆ R_DAC8_Stop()

fsp_err_t R_DAC8_Stop ( dac_ctrl_t *const  p_ctrl)

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

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

◆ R_DAC8_Close()

fsp_err_t R_DAC8_Close ( dac_ctrl_t *const  p_ctrl)

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

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