DAC.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021, Texas Instruments Incorporated
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Texas Instruments Incorporated nor the names of
17  * its contributors may be used to endorse or promote products derived
18  * from this software without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*!****************************************************************************
33  * @file DAC.h
34  * @brief Digital to Analog Conversion (DAC) Output Driver
35  *
36  * @anchor ti_drivers_DAC_Overview
37  * # Overview
38  *
39  * The DAC driver allows you to manage a Digital to Analog peripheral via
40  * simple and portable APIs. This driver supports converting DAC codes
41  * into an analog voltage with varying degrees of precision (microvolts
42  * or millivolts) depending on the resolution of the DAC.
43  *
44  * <hr>
45  * @anchor ti_drivers_DAC_Usage
46  * # Usage
47  *
48  * This documentation provides a basic @ref ti_drivers_DAC_Synopsis
49  * "usage summary" and a set of @ref ti_drivers_DAC_Examples "examples"
50  * in the form of commented code fragments. Detailed descriptions of the
51  * APIs are provided in subsequent sections.
52  *
53  * @anchor ti_drivers_DAC_Synopsis
54  * ## Synopsis
55  * @anchor ti_drivers_DAC_Synopsis_Code
56  * @code
57  * // Import DAC Driver definitions
58  * #include <ti/drivers/DAC.h>
59  *
60  * // Define name for DAC channel index
61  * #define VREFERENCE_OUT 0
62  *
63  * // One-time init of DAC driver
64  * DAC_init();
65  *
66  * // Initialize optional DAC parameters
67  * DAC_Params params;
68  * DAC_Params_init(&params);
69  *
70  * // Open DAC channels for usage
71  * DAC_Handle dacHandle = DAC_open(VREFERENCE_OUT, &params);
72 
73  * // Enable the DAC channel
74  * DAC_enable(dacHandle);
75  *
76  * // Output 800mV using the DAC
77  * DAC_setVoltage(dacHandle, 800000);
78  *
79  * // Output a voltage using DAC codes
80  * DAC_setCode(dacHandle, 125);
81  *
82  * // Disable the DAC channel
83  * DAC_disable(dacHandle);
84  *
85  * // Close the DAC channel
86  * DAC_close(dacHandle);
87  *
88  * @endcode
89  *
90  * <hr>
91  * @anchor ti_drivers_DAC_Examples
92  * # Examples
93  *
94  * @li @ref ti_drivers_DAC_Examples_open "Opening a DAC instance"
95  * @li @ref ti_drivers_DAC_Examples_reference "Using DAC to set a reference voltage"
96  * @li @ref ti_drivers_DAC_Examples_code "Using DAC to set a code"
97  *
98  * @anchor ti_drivers_DAC_Examples_open
99  * ## Opening a DAC instance
100  *
101  * @code
102  * DAC_Handle dac;
103  * DAC_Params params;
104  *
105  * DAC_Params_init(&params);
106  *
107  * dac = DAC_open(0, &params);
108  * if (dac == NULL) {
109  * // DAC_open() failed
110  * while (1) {}
111  * }
112  * @endcode
113  *
114  * @anchor ti_drivers_DAC_Examples_reference
115  * ## Using DAC to set a reference voltage
116  *
117  * To set a reference voltage first enable the DAC with DAC_enable()
118  * and then set the desired output voltage with DAC_setVoltage().
119  * The returned value can be used to check if the call was successful.
120  *
121  * @code
122  * int_fast16_t res;
123  * uint32_t outputMicroVolts = 1500000;
124  *
125  * DAC_enable(dac);
126  * res = DAC_setVoltage(dac, outputMicroVolts);
127  * if (res == DAC_STATUS_SUCCESS)
128  * {
129  * printf(outputMicroVolts);
130  * }
131  * @endcode
132  *
133  * @anchor ti_drivers_DAC_Examples_code
134  * ## Using DAC to set a code
135  *
136  * The following example shows how to set a DAC code. The use of DAC_setCode()
137  * instead of DAC_setVoltage() comes handy in scenarios such as outputting a
138  * data buffer at a particular time rate (e.g. waveform generation). Nevertheless,
139  * it's important to remember that DAC codes produce different output voltages
140  * depending on the selected voltage reference source.
141  *
142  * @code
143  * int_fast16_t res;
144  * uint32_t outputCode = 127;
145  * DAC_enable(dac);
146  * res = DAC_setCode(dac, outputCode);
147  * if (res == DAC_STATUS_SUCCESS)
148  * {
149  * printf(outputCode);
150  * }
151  * @endcode
152  *
153  * <hr>
154  * @anchor ti_drivers_DAC_Configuration
155  * # Configuration
156  *
157  * Refer to the @ref driver_configuration "Driver's Configuration" section
158  * for driver configuration information.
159  * <hr>
160  ******************************************************************************
161  */
162 
163 #ifndef ti_drivers_DAC__include
164 #define ti_drivers_DAC__include
165 
166 #include <stddef.h>
167 #include <stdbool.h>
168 #include <stdint.h>
169 
170 #include <ti/devices/DeviceFamily.h>
171 #include DeviceFamily_constructPath(driverlib/aux_dac.h)
172 
173 #ifdef __cplusplus
174 extern "C" {
175 #endif
176 
180 #define DAC_STATUS_SUCCESS (0)
181 
185 #define DAC_STATUS_ERROR (-1)
186 
190 #define DAC_STATUS_INUSE (-2)
191 
195 #define DAC_STATUS_INVALID (-3)
196 
207 typedef struct
208 {
210  void *object;
212  void const *hwAttrs;
213 } DAC_Config;
214 
219 
228 typedef struct
229 {
231  uint32_t initCode;
233  void *custom;
234 } DAC_Params;
235 
241 extern const DAC_Params DAC_defaultParams;
242 
251 extern void DAC_init(void);
252 
272 extern DAC_Handle DAC_open(uint_least8_t index, DAC_Params *params);
273 
284 extern void DAC_close(DAC_Handle handle);
285 
308 extern int_fast16_t DAC_setVoltage(DAC_Handle handle, uint32_t uVoltOutput);
309 
328 extern int_fast16_t DAC_setCode(DAC_Handle handle, uint32_t code);
329 
351 extern int_fast16_t DAC_enable(DAC_Handle handle);
352 
365 extern int_fast16_t DAC_disable(DAC_Handle handle);
366 
381 extern void DAC_Params_init(DAC_Params *params);
382 
383 #ifdef __cplusplus
384 }
385 #endif
386 
387 #endif /* ti_drivers_DAC__include */
ADC_Params params
Definition: Driver_Init.h:11
void const * hwAttrs
Definition: DAC.h:212
int_fast16_t DAC_enable(DAC_Handle handle)
Function to enable the DAC&#39;s output.
DAC_Handle DAC_open(uint_least8_t index, DAC_Params *params)
Function to initialize a given DAC peripheral specified by the particular index value.
int_fast16_t DAC_disable(DAC_Handle handle)
Function to disable the DAC&#39;s output.
void * object
Definition: DAC.h:210
DAC_Config * DAC_Handle
A handle that is returned from a DAC_open() call.
Definition: DAC.h:218
DAC Global configuration.
Definition: DAC.h:207
void DAC_init(void)
Function to initialize the DAC module.
const DAC_Params DAC_defaultParams
Default DAC_Params structure.
Basic DAC Parameters.
Definition: DAC.h:228
uint32_t initCode
Definition: DAC.h:231
int_fast16_t DAC_setVoltage(DAC_Handle handle, uint32_t uVoltOutput)
Function to set the DAC voltage value in microvolts.
void DAC_Params_init(DAC_Params *params)
Function to initialize the DAC_Params struct to its defaults.
int_fast16_t DAC_setCode(DAC_Handle handle, uint32_t code)
Function to set the DAC voltage in terms of a DAC code.
void * custom
Definition: DAC.h:233
void DAC_close(DAC_Handle handle)
Function to close a given DAC peripheral specified by the DAC handle.
© Copyright 1995-2022, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale