Skip to content

Commit d5ad2cd

Browse files
mattytrentinidpgeorge
authored andcommitted
docs/library: Add machine.DAC documentation.
Fixes issue micropython#7915. Signed-off-by: Matt Trentini <[email protected]>
1 parent 9b3b3a5 commit d5ad2cd

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed

docs/library/machine.DAC.rst

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
.. currentmodule:: machine
2+
.. _machine.DAC:
3+
4+
class DAC -- digital to analog conversion
5+
=========================================
6+
7+
The DAC is used to output an analog voltage based on a digital value.
8+
9+
The output voltage will be between 0 and 3.3V.
10+
11+
DAC is currently supported on ESP32 [#esp32_dac]_, SAMD and Renesas RA.
12+
13+
.. note::
14+
The STM32 port has similar functionality to ``machine.DAC``. See
15+
:ref:`pyb.DAC <pyb.DAC>` for details.
16+
17+
Example usage (ESP32)::
18+
19+
from machine import DAC
20+
21+
dac = DAC(pin) # create a DAC object acting on a pin
22+
dac.write(128) # write a value to the DAC
23+
dac.write(255) # output maximum value, 3.3V
24+
25+
Constructors
26+
------------
27+
28+
.. class:: DAC(id)
29+
30+
Construct a new DAC object.
31+
32+
``id`` is a pin object (ESP32 and Renesas RA) or an index to a DAC resource (SAMD).
33+
34+
.. note::
35+
On the ESP32, DAC functionality is available on pins 25 and 26. On the
36+
ESP32-S2, pins 17 and 18. See :ref:`ESP32 Quickref <esp32_quickref>`
37+
for more details.
38+
39+
.. note::
40+
SAMD21 has one DAC resource, SAMD51 has two. See :ref:`SAMD Quickref <samd_quickref>`
41+
for more details.
42+
43+
Methods
44+
-------
45+
46+
.. method:: DAC.write(value)
47+
48+
Output an analog voltage to the pin connected to the DAC.
49+
50+
``value`` is a representation of the desired output; a linear interpolation of
51+
0-3.3V, though the range differs depending on the port and micro, see below:
52+
53+
+--------------+------+--------+
54+
| *Port/micro* | Bits | Range |
55+
+==============+======+========+
56+
| ESP32 | 8 | 0-255 |
57+
+--------------+------+--------+
58+
| SAMD21 | 10 | 0-1023 |
59+
+--------------+------+--------+
60+
| SAMD51 | 12 | 0-4095 |
61+
+--------------+------+--------+
62+
| Renesas RA | 12 | 0-4095 |
63+
+--------------+------+--------+
64+
65+
.. rubric:: Footnotes
66+
67+
.. [#esp32_dac] The original ESP32 and ESP32-S2 *only*, since DAC hardware is
68+
not present on other microcontrollers in the family.

docs/library/machine.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ Classes
260260
machine.Signal.rst
261261
machine.ADC.rst
262262
machine.ADCBlock.rst
263+
machine.DAC.rst
263264
machine.PWM.rst
264265
machine.UART.rst
265266
machine.SPI.rst

0 commit comments

Comments
 (0)