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