Digital to Analog Conversion (DAC) Output Driver.
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.
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.
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.
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.
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)>
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_Config * | DAC_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... | |
#define DAC_STATUS_SUCCESS (0) |
Successful status code returned by DAC API.
#define DAC_STATUS_ERROR (-1) |
Generic error status code returned by DAC API.
#define DAC_STATUS_INUSE (-2) |
The DAC is currently in use by another handle or by the sensor controller.
#define DAC_STATUS_INVALID (-3) |
The desired output value is outside the DAC's output range.
typedef DAC_Config* DAC_Handle |
A handle that is returned from a DAC_open() call.
void DAC_init | ( | void | ) |
Function to initialize the DAC module.
DAC_Handle DAC_open | ( | uint_least8_t | index, |
DAC_Params * | params | ||
) |
Function to initialize a given DAC peripheral specified by the particular index value.
[in,out] | index | Logical peripheral number for the DAC indexed into the DAC_config table |
[in] | params | Pointer to a parameter block. All the fields in this structure are RO (read-only). Providing a NULL pointer cannot open the module. |
void DAC_close | ( | DAC_Handle | handle | ) |
Function to close a given DAC peripheral specified by the DAC handle.
[in] | handle | A DAC_Handle returned from DAC_open |
int_fast16_t DAC_setVoltage | ( | DAC_Handle | handle, |
uint32_t | uVoltOutput | ||
) |
Function to set the DAC voltage value in microvolts.
[in] | handle | A DAC_Handle returned from DAC_open. |
[in] | uVoltOutput | Desired output voltage in uV. |
DAC_STATUS_SUCCESS | The call was successful. |
DAC_STATUS_ERROR | The call was unsuccessful. |
DAC_STATUS_INVALID | The desired output voltage was out of bounds for the DAC. |
int_fast16_t DAC_setCode | ( | DAC_Handle | handle, |
uint32_t | code | ||
) |
Function to set the DAC voltage in terms of a DAC code.
[in] | handle | A DAC_Handle returned from DAC_open. |
[in] | code | Desired output in terms of a DAC code. |
DAC_STATUS_SUCCESS | The call was successful. |
DAC_STATUS_ERROR | The call was unsuccessful. |
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.
[in] | handle | A DAC_Handle returned from DAC_open. |
DAC_STATUS_SUCCESS | The call was successful. |
DAC_STATUS_ERROR | The call was unsuccessful. |
DAC_STATUS_INUSE | The call was unsuccessful because the DAC is in use by the Sensor Controller or by another handle. |
int_fast16_t DAC_disable | ( | DAC_Handle | handle | ) |
Function to disable the DAC's output.
[in] | handle | A DAC_Handle returned from DAC_open. |
DAC_STATUS_SUCCESS | The call was successful. |
DAC_STATUS_ERROR | The call was unsuccessful. |
void DAC_Params_init | ( | DAC_Params * | params | ) |
Function to initialize the DAC_Params struct to its defaults.
[out] | params | A pointer to DAC_Params structure for initialization |
Defaults values are:
params | Parameter structure to initialize |
const DAC_Params DAC_defaultParams |
Default DAC_Params structure.