Synergy Software Package User's Manual
DAC8 Driver

DAC8 HAL Module Introduction

The DAC8 HAL module provides a high-level API for digital-to-analog conversion applications and supports an 8-bit D/A converter (DAC8) peripheral on Synergy MCUs.

DAC8 HAL Module Features

  • 8-Bit D/A Converter
  • Left-Justified or Right-Justified Input Data Format
  • Synchronization with the Analog-to-Digital Converter (ADC) module
  • Multiple Operation Modes
    • Normal
    • Real-Time (Event Link)
    • Charge Pump Control
DAC8_BD.png
DAC8 HAL Module Block Diagram

DAC8 Hardware support details

The following hardware features are, or are not, supported by SSP for the DAC8.

Legend:

Symbol Meaning
Available (Tested)
Not Available (Not tested/not functional or both)
N/A Not supported by MCU 
MCU
Group
8-Bit 2 Channels
Output
3-Channel
Output
Module-Stop
Function
Event link function through
ELC HAL driver *
S124 N/A N/A N/A N/A N/A
S128
S1JA N/A
S3A1 N/A
S3A3 N/A
S3A6 N/A
S3A7 N/A N/A N/A N/A N/A
S5D3 N/A N/A N/A N/A N/A
S5D5 N/A N/A N/A N/A N/A
S5D9 N/A N/A N/A N/A N/A
S7G2 N/A N/A N/A N/A N/A
  • Note: The ELC event could be used instead of calling the DAC start() interface. This would have to be programmed by the user by setting up the link rather than using the ELC API. 

DAC8 HAL Module APIs Overview

The DAC8 HAL module defines APIs for opening, closing, starting, stopping and writing to the DAC. A complete list of the available APIs, an example API call and a short description of each can be found in the following table. A table of status return values follows the API summary table.

DAC8 HAL Module API Summary

Function Name Example API Call and Description
open g_dac8.p_api->open(g_dac8.p_ctrl, g_dac8.p_cfg
Initial Configuration.
close g_dac8.p_api->close(g_dac8.p_ctrl)
Close the D/A Converter.
write g_dac8.p_api->write(g_dac8.p_ctrl, val)
Write Sample value to the D/A Converter.
start g_dac8.p_api->start(g_dac8.p_ctrl)
Start the D/A Converter if it has not been started yet.
stop g_dac8.p_api->stop(g_dac8.p_ctrl)
Stop the D/A Converter if the converter is running.
versionGet g_dac8.p_api->versionGet(&version)
Retrieve the API version with the version pointer.
Note
For more complete descriptions of operation and definitions for the function data structures, typedefs, defines, API data, API structures, and function variables, review the SSP User's Manual API References for the associated module.

Status Return Values

Name Description
SSP_SUCCESS API Call Successful.
SSP_ERR_HW_LOCKED DAC resource is locked.
SSP_ERR_NOT_OPEN Unit is not open.
SSP_ERR_ASSERTION Wrong parameter.
SSP_ERR_IP_CHANNEL_NOT_PRESENT Wrong channel selected.
Note
Lower-level drivers may return common error codes. Refer to the SSP User's Manual API References for the associated module for a definition of all relevant status return values.

DAC8 HAL Module Operational Overview

The DAC8 HAL module configures the 8-bit D/A converter (DAC8) to output one of 256 voltage levels between positive and negative reference voltages. The driver can be configured to accept the 8-bit output data in left‑or‑right‑justified format in a 16-bit input data. The driver supports two modes for the DAC.

  • Normal mode – The D/A output is updated on writes to the data register.
  • Real-Time (Event Link) – The D/A output is updated on an Event Link event. While in this mode the data register can be written at any time. An Event Link event triggers the start of conversion. Refer to the "ELC Interface" in the SSP User's Manual for more information.

To reduce the noise present in ADC readings the driver can configure synchronous anti-interference mode with the ADC module. This reduces conversion noise by disabling the DAC charge while the ADC is sampling. Check the hardware manual to determine if this feature is supported.

For operation at low AVCC voltage the driver can enable or disable the hardware charge pump.

Real-Time Mode

In real-time mode the output voltage is only changed on a signal from the ELC peripheral. Note when using real time mode the first call to dac_api_t::write() will set the initial output voltage.

As an illustration, the following code shows how to link the DAC8 output on channel 0 to the ELC software event and trigger the output to change.

/* Open DAC8 driver.  */
g_dac8_0.p_api->open(g_dac8_0.p_ctrl, &g_dac8_0.p_cfg);
/* Link DAC8 output 0 to software event 0. 
   In a real application, this feature would be used to link DAC8 output
   to a hardware event. A software event is used here for simplicity. */
g_elc_on_elc.linkSet(ELC_PERIPHERAL_DA80, ELC_EVENT_ELC_SOFTWARE_EVENT_0);
/* Set initial output voltage, the output is immediately updated
   because this is the first write since open. */
g_dac8_0.p_api->write(g_dac8_0.p_ctrl, initial_dac_value);
while (true) {
/* Set the next output value, the output voltage is not updated until
       an ELC event occurs. */
g_dac8_0.p_api->write(g_dac8_0.p_ctrl, next_dac_value);
/* Generate software ELC event to update DAC output. */
R_BSP_SoftwareDelay(10, BSP_DELAY_UNITS_MILLISECONDS);
}

DAC8 HAL Module Important Operational Notes and Limitations

DAC8 HAL Module Operational Notes

DAC8 HAL Module Limitations

  • The DAC8 driver does not configure the ELC peripheral for real-time mode. The user will need to configure the Event Link Controller in addition to enabling real-time mode in the DAC8 module.
  • Refer to the most recent SSP Release Notes for any additional operational limitations for this module.

Including the DAC8 HAL Module in an Application

This section describes how to include the DAC8 HAL Module in an application using the SSP configurator.

Note
This section assumes you are familiar with creating a project, adding threads, adding a stack to a thread and configuring a block within the stack. If you are unfamiliar with any of these items, refer to the first few chapters of the SSP User's Manual to learn how to manage each of these important steps in creating SSP-based applications.

To add the DAC8 Driver to an application, simply add it to a thread using the stacks selection sequence given in the following table. (The default name for the DAC8 Driver is g_dac8_0. This name can be changed in the associated Properties window.)

DAC8 HAL Module Selection Sequence

Resource ISDE Tab Stacks Selection Sequence
g_dac8_0 DAC Driver on r_dac8 Threads New Stack> Driver> Analog> DAC Driver on r_dac8

When the DAC8 Driver on r_dac8 is added to the thread stack as shown in the following figure, the configurator automatically adds any needed lower‑level modules. Any modules needing additional configuration information have the box text highlighted in Red. Modules with a Gray band are individual modules that stand alone. Modules with a Blue band are shared or common; they need only be added once and can be used by multiple stacks. Modules with a Pink band can require the selection of lower-level modules; these are either optional or recommended. (This is indicated in the block with the inclusion of this text.) If the addition of lower-level modules is required, the module description include Add in the text. Clicking on any Pink banded modules brings up the New icon and displays possible choices.

DAC8_MS.png
DAC8 HAL Module Stack

Configuring the DAC8 HAL Module

The DAC8 HAL Module must be configured by the user for the desired operation. The available configuration settings and defaults for all the user-accessible properties are given in the properties tab within the SSP configurator and are shown in the following tables for easy reference. Only properties that can be changed without causing conflicts are available for modification. Other properties are locked and not available for changes and are identified with a lock icon for the locked property in the Properties window in the ISDE. This approach simplifies the configuration process and makes it much less error-prone than previous manual approaches to configuration. The available configuration settings and defaults for all the user-accessible properties are given in the Properties tab within the SSP Configurator and are shown in the following tables for easy reference.

Note
You may want to open your ISDE, create the module and explore the property settings in parallel with looking over the following configuration table settings. This will help orient you and can be a useful 'hands-on' approach to learning the ins and outs of developing with SSP.

Configuration Settings for the DAC8 HAL Module on r_dac8

ISDE Property Value Description
Parameter Checking BSP, Enabled, Disabled

Default: BSP
Enable or disable the parameter error checking.
Name g_dac8_0 Module name.
Channel 0 Channel selection.
Synchronize with ADC Enabled, Disabled

Default: Disabled
Choose whether to sync with the ADC module.
Data Format Right Justified, Left Justified

Default: Right Justified
Data format selection.
DAC Mode Normal Mode, Real-time (Event Link) Mode

Default: Normal Mode
DAC mode selection.
Charge Pump Enabled (Requires MOCO active) Enabled, Disabled

Default: Enabled
Enable or disable the charge pump.
Note
The example settings and defaults are for a project using the Synergy S7G2 MCU Group. Other MCUs may have different default values and available configuration settings.

DAC8 HAL Module Clock Configuration

The DAC8 HAL module does not require a specific clock configuration.

DAC8 HAL Module Pin Configuration

To use the DAC8 HAL module, the port pins for the channels receiving the analog input must be set as analog pins in the pin configurator. The following table illustrates the method for selecting the pins within the SSP configuration window and the subsequent table illustrates an example selection for the DAC pins:

Pin Selection for the DAC8 HAL Module on r_dac8

Resource ISDE Tab Pin selection Sequence
DAC8 Pins Select Peripherals> Analog:DAC8> DAC80.
Note
The selection sequence assumes DAC80 is the desired hardware target for the driver.

Pin Configuration Settings for the DAC8 HAL Module on r_dac8

Property Value Description
Module Name DAC80 DAC Peripheral Module.
Operation Mode Enabled, Disabled

Default: Enabled
DAC Peripheral operation mode.
DA0 None, DA0

Default: None
DAC Output Pin.
DA1 None, DA1

Default: None
DAC Output Pin.
Note
The example settings are for a project using the Synergy S7G2 MCU Group and the SK-S7G2 Kit. Other Synergy MCUs and Synergy Kits may have different available pin configuration settings.

Using the DAC8 HAL Module in an Application

The typical steps in using the DAC8 HAL module in an application are:

  1. Initialize the DAC8 HAL module using the dac_api_t::open API.
  2. Write a value using the dac_api_t::write API.
  3. Start a conversion using the dac_api_t::start API.
  4. Continue writing values as needed using the dac_api_t::write API.
  5. Stop conversion using the dac_api_t::stop API.
  6. Use the dac_api_t::close call to power down the peripheral.

These common steps are illustrated in a typical operational flow diagram in the following figure:

DAC8_TA.png
Flow Diagram of a Typical DAC8 HAL Module Application