Data Structures | Macros | Typedefs | Functions | Variables
DAC.h File Reference

Detailed Description

Digital to Analog Conversion (DAC) Output Driver.


Overview

The DAC driver allows you to manage a Digital to Analog peripheral via simple and portable APIs. This driver supports converting DAC codes into an analog voltage with varying degrees of precision (microvolts or millivolts) depending on the resolution of the DAC.


Usage

This documentation provides a basic usage summary and a set of examples in the form of commented code fragments. Detailed descriptions of the APIs are provided in subsequent sections.

Synopsis

// Import DAC Driver definitions
#include <ti/drivers/DAC.h>
// Define name for DAC channel index
#define VREFERENCE_OUT 0
// One-time init of DAC driver
// Initialize optional DAC parameters
DAC_Params_init(&params);
// Open DAC channels for usage
DAC_Handle dacHandle = DAC_open(VREFERENCE_OUT, &params);
// Enable the DAC channel
DAC_enable(dacHandle);
// Output 800mV using the DAC
DAC_setVoltage(dacHandle, 800000);
// Output a voltage using DAC codes
DAC_setCode(dacHandle, 125);
// Disable the DAC channel
DAC_disable(dacHandle);
// Close the DAC channel
DAC_close(dacHandle);

Examples

Opening a DAC instance

DAC_Params_init(&params);
dac = DAC_open(0, &params);
if (dac == NULL) {
// DAC_open() failed
while (1) {}
}

Using DAC to set a reference voltage

To set a reference voltage first enable the DAC with DAC_enable() and then set the desired output voltage with DAC_setVoltage(). The returned value can be used to check if the call was successful.

int_fast16_t res;
uint32_t outputMicroVolts = 1500000;
res = DAC_setVoltage(dac, outputMicroVolts);
if (res == DAC_STATUS_SUCCESS)
{
printf(outputMicroVolts);
}

Using DAC to set a code

The following example shows how to set a DAC code. The use of DAC_setCode() instead of DAC_setVoltage() comes handy in scenarios such as outputting a data buffer at a particular time rate (e.g. waveform generation). Nevertheless, it's important to remember that DAC codes produce different output voltages depending on the selected voltage reference source.

int_fast16_t res;
uint32_t outputCode = 127;
res = DAC_setCode(dac, outputCode);
if (res == DAC_STATUS_SUCCESS)
{
printf(outputCode);
}

Configuration

Refer to the Driver's Configuration section for driver configuration information.


#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <ti/devices/DeviceFamily.h>
#include <DeviceFamily_constructPath(driverlib/aux_dac.h)>
Include dependency graph for DAC.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  DAC_Config
 DAC Global configuration. More...
 
struct  DAC_Params
 Basic DAC Parameters. More...
 

Macros

#define DAC_STATUS_SUCCESS   (0)
 Successful status code returned by DAC API. More...
 
#define DAC_STATUS_ERROR   (-1)
 Generic error status code returned by DAC API. More...
 
#define DAC_STATUS_INUSE   (-2)
 The DAC is currently in use by another handle or by the sensor controller. More...
 
#define DAC_STATUS_INVALID   (-3)
 The desired output value is outside the DAC's output range. More...
 

Typedefs

typedef DAC_ConfigDAC_Handle
 A handle that is returned from a DAC_open() call. More...
 

Functions

void DAC_init (void)
 Function to initialize the DAC module. More...
 
DAC_Handle DAC_open (uint_least8_t index, DAC_Params *params)
 Function to initialize a given DAC peripheral specified by the particular index value. More...
 
void DAC_close (DAC_Handle handle)
 Function to close a given DAC peripheral specified by the DAC handle. More...
 
int_fast16_t DAC_setVoltage (DAC_Handle handle, uint32_t uVoltOutput)
 Function to set the DAC voltage value in microvolts. More...
 
int_fast16_t DAC_setCode (DAC_Handle handle, uint32_t code)
 Function to set the DAC voltage in terms of a DAC code. More...
 
int_fast16_t DAC_enable (DAC_Handle handle)
 Function to enable the DAC's output. More...
 
int_fast16_t DAC_disable (DAC_Handle handle)
 Function to disable the DAC's output. More...
 
void DAC_Params_init (DAC_Params *params)
 Function to initialize the DAC_Params struct to its defaults. More...
 

Variables

const DAC_Params DAC_defaultParams
 Default DAC_Params structure. More...
 

Macro Definition Documentation

§ DAC_STATUS_SUCCESS

#define DAC_STATUS_SUCCESS   (0)

Successful status code returned by DAC API.

§ DAC_STATUS_ERROR

#define DAC_STATUS_ERROR   (-1)

Generic error status code returned by DAC API.

§ DAC_STATUS_INUSE

#define DAC_STATUS_INUSE   (-2)

The DAC is currently in use by another handle or by the sensor controller.

§ DAC_STATUS_INVALID

#define DAC_STATUS_INVALID   (-3)

The desired output value is outside the DAC's output range.

Typedef Documentation

§ DAC_Handle

A handle that is returned from a DAC_open() call.

Function Documentation

§ DAC_init()

void DAC_init ( void  )

Function to initialize the DAC module.

Precondition
The DAC_config structure must exist and be persistent before this function can be called. This function must also be called before any other DAC driver APIs. This function call does not modify any peripheral registers.

§ DAC_open()

DAC_Handle DAC_open ( uint_least8_t  index,
DAC_Params params 
)

Function to initialize a given DAC peripheral specified by the particular index value.

Precondition
DAC controller has been initialized
Parameters
[in,out]indexLogical peripheral number for the DAC indexed into the DAC_config table
[in]paramsPointer to a parameter block. All the fields in this structure are RO (read-only). Providing a NULL pointer cannot open the module.
Returns
A DAC_Handle on success or a NULL on an error or if it has been opened already.
See also
DAC_init()
DAC_close()

§ DAC_close()

void DAC_close ( DAC_Handle  handle)

Function to close a given DAC peripheral specified by the DAC handle.

Precondition
DAC_open() had to be called first.
Parameters
[in]handleA DAC_Handle returned from DAC_open
See also
DAC_open()

§ DAC_setVoltage()

int_fast16_t DAC_setVoltage ( DAC_Handle  handle,
uint32_t  uVoltOutput 
)

Function to set the DAC voltage value in microvolts.

Warning
This function takes a value in microvolts, but the actual output is limited by the DAC's resolution.
Precondition
DAC_enable() has to be called first.
Parameters
[in]handleA DAC_Handle returned from DAC_open.
[in]uVoltOutputDesired output voltage in uV.
Returns
Implementation specific return codes. Negative values indicate unsuccessful operations.
Return values
DAC_STATUS_SUCCESSThe call was successful.
DAC_STATUS_ERRORThe call was unsuccessful.
DAC_STATUS_INVALIDThe desired output voltage was out of bounds for the DAC.
See also
DAC_setCode()

§ DAC_setCode()

int_fast16_t DAC_setCode ( DAC_Handle  handle,
uint32_t  code 
)

Function to set the DAC voltage in terms of a DAC code.

Warning
The appropriate DAC code is device-specific and admissible values depend on the DAC's resolution.
Precondition
DAC_open() has to be called first.
Parameters
[in]handleA DAC_Handle returned from DAC_open.
[in]codeDesired output in terms of a DAC code.
Return values
DAC_STATUS_SUCCESSThe call was successful.
DAC_STATUS_ERRORThe call was unsuccessful.
See also
DAC_open()

§ DAC_enable()

int_fast16_t DAC_enable ( DAC_Handle  handle)

Function to enable the DAC's output.

This function claims ownership of the DAC peripheral, and depending on the selected voltage reference source, it calculates the output voltage range.

Furthermore, the function configures and enables the DAC.

Precondition
DAC_open() has to be called first.
Parameters
[in]handleA DAC_Handle returned from DAC_open.
Return values
DAC_STATUS_SUCCESSThe call was successful.
DAC_STATUS_ERRORThe call was unsuccessful.
DAC_STATUS_INUSEThe call was unsuccessful because the DAC is in use by the Sensor Controller or by another handle.
See also
DAC_disable()

§ DAC_disable()

int_fast16_t DAC_disable ( DAC_Handle  handle)

Function to disable the DAC's output.

Precondition
DAC_enable() has to be called first.
Parameters
[in]handleA DAC_Handle returned from DAC_open.
Return values
DAC_STATUS_SUCCESSThe call was successful.
DAC_STATUS_ERRORThe call was unsuccessful.
See also
DAC_enable()

§ DAC_Params_init()

void DAC_Params_init ( DAC_Params params)

Function to initialize the DAC_Params struct to its defaults.

Parameters
[out]paramsA pointer to DAC_Params structure for initialization

Defaults values are:

params.initCode = 0,
params.custom = NULL;
Parameters
paramsParameter structure to initialize

Variable Documentation

§ DAC_defaultParams

const DAC_Params DAC_defaultParams

Default DAC_Params structure.

See also
DAC_Params_init()
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale