RA Flexible Software Package Documentation  Release v6.0.0

 
DAC_B (r_dac_b)

Functions

fsp_err_t R_DAC_B_Open (dac_ctrl_t *p_api_ctrl, dac_cfg_t const *const p_cfg)
 
fsp_err_t R_DAC_B_Write (dac_ctrl_t *p_api_ctrl, uint16_t value)
 
fsp_err_t R_DAC_B_Start (dac_ctrl_t *p_api_ctrl)
 
fsp_err_t R_DAC_B_Stop (dac_ctrl_t *p_api_ctrl)
 
fsp_err_t R_DAC_B_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_B module outputs one of 4096 voltage levels between the positive and negative reference voltages.

Build Time Configurations for r_dac_b

The following build time configurations are defined in fsp_cfg/r_dac_b_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_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.

ConfigurationOptionsDefaultDescription
NameName must be a valid C symbolg_dac_b0 Module name.
ChannelValue must be an integer greater than or equal to 00 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 OutputMCU Specific OptionsEnable DAC output to internal modules.
ELC Trigger SourceMCU Specific OptionsELC 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)
{
fsp_err_t err;
uint16_t value;
/* Pin configuration: Output enable DA0 as Analog. */
/* Initialize the DAC channel */
err = R_DAC_B_Open(&g_dac_b_ctrl, &g_dac_b_cfg);
/* Handle any errors. This function should be defined by the user. */
assert(FSP_SUCCESS == err);
value = (uint16_t) DAC_EXAMPLE_VALUE;
err = R_DAC_B_Write(&g_dac_b_ctrl, value);
assert(FSP_SUCCESS == err);
err = R_DAC_B_Start(&g_dac_b_ctrl);
assert(FSP_SUCCESS == err);
}

Data Structures

struct  dac_b_instance_ctrl_t
 
struct  dac_b_extended_cfg_t
 

Enumerations

enum  dac_b_vrefh_t
 

Data Structure Documentation

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

Enumeration Type Documentation

◆ dac_b_vrefh_t

DAC Vref Type

Enumerator
DAC_B_VREFH_NORMAL 

VREFH >= 2.7v.

DAC_B_VREFH_LOW 

VREFH < 2.7v.

Function Documentation

◆ R_DAC_B_Open()

fsp_err_t R_DAC_B_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
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_B_Write()

fsp_err_t R_DAC_B_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_B_Start()

fsp_err_t R_DAC_B_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_B_Stop()

fsp_err_t R_DAC_B_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_B_Close()

fsp_err_t R_DAC_B_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.