1.. _dac-sample:
2
3Digital-to-Analog Converter (DAC)
4#################################
5
6Overview
7********
8
9This sample demonstrates how to use the DAC driver API.
10
11Building and Running
12********************
13
14The DAC output is defined in the board's devicetree and pinmux file.
15
16The board's :ref:`/zephyr,user <dt-zephyr-user>` node must have ``dac``,
17``dac-channel-id``, and ``dac-resolution`` properties set. See the predefined
18overlays in :zephyr_file:`samples/drivers/dac/boards` for examples.
19
20Building and Running for ST Nucleo L073RZ
21=========================================
22The sample can be built and executed for the
23:ref:`nucleo_l073rz_board` as follows:
24
25.. zephyr-app-commands::
26   :zephyr-app: samples/drivers/dac
27   :board: nucleo_l073rz
28   :goals: build flash
29   :compact:
30
31Building and Running for ST Nucleo L152RE
32=========================================
33The sample can be built and executed for the
34:ref:`nucleo_l152re_board` as follows:
35
36.. zephyr-app-commands::
37   :zephyr-app: samples/drivers/dac
38   :board: nucleo_l152re
39   :goals: build flash
40   :compact:
41
42Building and Running for ST Nucleo F767ZI
43=========================================
44The sample can be built and executed for the
45:ref:`nucleo_f767zi_board` as follows:
46
47.. zephyr-app-commands::
48   :zephyr-app: samples/drivers/dac
49   :board: nucleo_f767zi
50   :goals: build flash
51   :compact:
52
53Building and Running for ST Disco F3
54=========================================
55The sample can be built and executed for the
56:ref:`stm32f3_disco_board` as follows:
57
58.. zephyr-app-commands::
59   :zephyr-app: samples/drivers/dac
60   :board: stm32f3_disco
61   :goals: build flash
62   :compact:
63
64Building and Running for ST Nucleo F429ZI
65=========================================
66The sample can be built and executed for the
67:ref:`nucleo_f429zi_board` as follows:
68
69.. zephyr-app-commands::
70   :zephyr-app: samples/drivers/dac
71   :board: nucleo_f429zi
72   :goals: build flash
73   :compact:
74
75Building and Running for STM32L562E DK
76======================================
77The sample can be built and executed for the
78:ref:`stm32l562e_dk_board` as follows:
79
80.. zephyr-app-commands::
81   :zephyr-app: samples/drivers/dac
82   :board: stm32l562e_dk
83   :goals: build flash
84   :compact:
85
86Building and Running for ST Nucleo L552ZE Q
87===========================================
88The sample can be built and executed for the
89:ref:`nucleo_l552ze_q_board` as follows:
90
91.. zephyr-app-commands::
92   :zephyr-app: samples/drivers/dac
93   :board: nucleo_l552ze_q
94   :goals: build flash
95   :compact:
96
97Building and Running for NXP TWR-KE18F
98======================================
99The sample can be built and executed for the :ref:`twr_ke18f` as
100follows:
101
102.. zephyr-app-commands::
103   :zephyr-app: samples/drivers/dac
104   :board: twr_ke18f
105   :goals: build flash
106   :compact:
107
108DAC output is available on pin A32 of the primary TWR elevator
109connector.
110
111Building and Running for NXP FRDM-K64F
112======================================
113The sample can be built and executed for the :ref:`frdm_k64f` as
114follows:
115
116.. zephyr-app-commands::
117   :zephyr-app: samples/drivers/dac
118   :board: frdm_k64f
119   :goals: build flash
120   :compact:
121
122DAC output is available on connector J4 pin 11.
123
124Building and Running for BL652
125==============================
126The BL652 DVK PCB contains a footprint for a MCP4725 to use as an external
127DAC. Note this is not populated by default. The sample can be built and
128executed for the :ref:`bl652_dvk` as follows:
129
130.. zephyr-app-commands::
131   :zephyr-app: samples/drivers/dac
132   :board: bl652_dvk
133   :goals: build flash
134   :compact:
135
136DAC output is available on pin 1 of the MCP4725.
137
138Building and Running for BL653
139==============================
140The BL653 DVK PCB contains a footprint for a MCP4725 to use as an external
141DAC. Note this is not populated by default. The sample can be built and
142executed for the :ref:`bl653_dvk` as follows:
143
144.. zephyr-app-commands::
145   :zephyr-app: samples/drivers/dac
146   :board: bl653_dvk
147   :goals: build flash
148   :compact:
149
150DAC output is available on pin 1 of the MCP4725.
151
152Building and Running for BL654
153==============================
154The BL654 DVK PCB contains a footprint for a MCP4725 to use as an external
155DAC. Note this is not populated by default. The sample can be built and
156executed for the :ref:`bl654_dvk` as follows:
157
158.. zephyr-app-commands::
159   :zephyr-app: samples/drivers/dac
160   :board: bl654_dvk
161   :goals: build flash
162   :compact:
163
164DAC output is available on pin 1 of the MCP4725.
165
166Building and Running for BL5340
167===============================
168The BL5340 DVK PCB contains a MCP4725 to use as a DAC. The sample can be
169built and executed for the :ref:`bl5340_dvk` as follows:
170
171.. zephyr-app-commands::
172   :zephyr-app: samples/drivers/dac
173   :board: bl5340_dvk_cpuapp
174   :goals: build flash
175   :compact:
176
177DAC output is available on pin 1 of the MCP4725.
178
179Building and Running for GD32450I-EVAL
180======================================
181The sample can be built and executed for the
182:ref:`gd32f450i_eval` as follows:
183
184.. zephyr-app-commands::
185   :zephyr-app: samples/drivers/dac
186   :board: gd32f450i_eval
187   :goals: build flash
188   :compact:
189
190Bridge the JP23 to DAC with the jumper cap, then DAC output will available on JP7.
191
192Building and Running for Longan Nano and Longan Nano Lite
193=========================================================
194The sample can be built and executed for the
195:ref:`longan_nano` as follows:
196
197.. zephyr-app-commands::
198   :zephyr-app: samples/drivers/dac
199   :board: longan_nano
200   :goals: build flash
201   :compact:
202
203also can run for the
204:ref: `longan_nano_lite` as follows:
205
206.. zephyr-app-commands::
207   :zephyr-app: samples/drivers/dac
208   :board: longan_nano_lite
209   :goals: build flash
210   :compact:
211
212Sample output
213=============
214
215You should see a sawtooth signal with an amplitude of the DAC reference
216voltage and a period of approx. 4 seconds at the DAC output pin specified
217by the board.
218
219The following output is printed:
220
221.. code-block:: console
222
223   Generating sawtooth signal at DAC channel 1.
224
225.. note:: If the DAC is not supported, the output will be an error message.
226