@@ -8,28 +8,59 @@ The ADC class provides an interface to analog-to-digital convertors, and
8
8
represents a single endpoint that can sample a continuous voltage and
9
9
convert it to a discretised value.
10
10
11
+ For extra control over ADC sampling see :ref: `machine.ADCBlock <machine.ADCBlock >`.
12
+
11
13
Example usage::
12
14
13
- import machine
15
+ from machine import ADC
14
16
15
- adc = machine.ADC(pin) # create an ADC object acting on a pin
16
- val = adc.read_u16() # read a raw analog value in the range 0-65535
17
+ adc = ADC(pin) # create an ADC object acting on a pin
18
+ val = adc.read_u16() # read a raw analog value in the range 0-65535
19
+ val = adc.read_uv() # read an analog value in microvolts
17
20
18
21
Constructors
19
22
------------
20
23
21
- .. class :: ADC(id)
24
+ .. class :: ADC(id, *, sample_ns, atten )
22
25
23
26
Access the ADC associated with a source identified by *id *. This
24
27
*id * may be an integer (usually specifying a channel number), a
25
28
:ref: `Pin <machine.Pin >` object, or other value supported by the
26
29
underlying machine.
27
30
31
+ If additional keyword-arguments are given then they will configure
32
+ various aspects of the ADC. If not given, these settings will take
33
+ previous or default values. The settings are:
34
+
35
+ - *sample_ns * is the sampling time in nanoseconds.
36
+
37
+ - *atten * specifies the input attenuation.
38
+
28
39
Methods
29
40
-------
30
41
42
+ .. method :: ADC.init(*, sample_ns, atten)
43
+
44
+ Apply the given settings to the ADC. Only those arguments that are
45
+ specified will be changed. See the ADC constructor above for what the
46
+ arguments are.
47
+
48
+ .. method :: ADC.block()
49
+
50
+ Return the :ref: `ADCBlock <machine.ADCBlock >` instance associated with
51
+ this ADC object.
52
+
53
+ This method only exists if the port supports the
54
+ :ref: `ADCBlock <machine.ADCBlock >` class.
55
+
31
56
.. method :: ADC.read_u16()
32
57
33
58
Take an analog reading and return an integer in the range 0-65535.
34
59
The return value represents the raw reading taken by the ADC, scaled
35
60
such that the minimum value is 0 and the maximum value is 65535.
61
+
62
+ .. method :: ADC.read_uv()
63
+
64
+ Take an analog reading and return an integer value with units of
65
+ microvolts. It is up to the particular port whether or not this value
66
+ is calibrated, and how calibration is done.
0 commit comments