11.. _pyb.ADC :
22
3- class ADC -- analog to digital conversion: read analog values on a pin
4- ======================================================================
3+ class ADC -- analog to digital conversion
4+ =========================================
55
66.. only :: port_pyboard
77
88 Usage::
9-
9+
1010 import pyb
1111
1212 adc = pyb.ADC(pin) # create an analog object from a pin
@@ -24,32 +24,32 @@ class ADC -- analog to digital conversion: read analog values on a pin
2424
2525 import pyb
2626
27- adc = pyb.ADC(pin) # create an analog object on one of the 4 ADC channels
28- val = adc.read() # read an analog value
29- adc.deinit() # disable the adc channel
30- adc.init() # enable the adc channel
27+ adc = pyb.ADC() # create an ADC object
28+ apin = adc.channel(pin='GP3') # create an analog pin on GP3
29+ val = apin() # read an analog value
3130
3231Constructors
3332------------
3433
34+
3535.. only :: port_pyboard
3636
3737 .. class :: pyb.ADC(pin)
38-
38+
3939 Create an ADC object associated with the given pin.
4040 This allows you to then read analog values on that pin.
4141
4242.. only :: port_wipy
4343
44- .. class :: pyb.ADC(pin )
45-
44+ .. class :: pyb.ADC(id=0, \*, bits=12 )
45+
4646 Create an ADC object associated with the given pin.
4747 This allows you to then read analog values on that pin.
4848 For more info check the `pinout and alternate functions
4949 table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png> `_
5050
5151 .. warning ::
52-
52+
5353 ADC pin input range is 0-1.4V (being 1.8V the absolute maximum that it
5454 can withstand). When GP2, GP3, GP4 or GP5 are remapped to the
5555 ADC block, 1.8 V is the maximum. If these pins are used in digital mode,
@@ -58,12 +58,12 @@ Constructors
5858Methods
5959-------
6060
61- .. method :: adc.read()
61+ .. only :: port_pyboard
6262
63- Read the value on the analog pin and return it. The returned value
64- will be between 0 and 4095.
63+ .. method :: adc.read()
6564
66- .. only :: port_pyboard
65+ Read the value on the analog pin and return it. The returned value
66+ will be between 0 and 4095.
6767
6868 .. method :: adc.read_timed(buf, timer)
6969
@@ -97,15 +97,51 @@ Methods
9797 # this will take 10 seconds to finish
9898 for val in buf: # loop over all values
9999 print(val) # print the value out
100-
100+
101101 This function does not allocate any memory.
102102
103103.. only :: port_wipy
104104
105+ .. method :: adc.channel(id, *, pin)
106+
107+ Create an analog pin. If only channel ID is given, the correct pin will be selected. Alternatively,
108+ only the pin can be passed and the correct channel will be selected. Examples::
109+
110+ # all of these are equivalent and enable ADC channel 1 on GP3
111+ apin = adc.channel(1)
112+ apin = adc.channel(pin='GP3')
113+ apin = adc.channel(id=1, pin='GP3')
114+
105115 .. method :: adc.init()
106116
107- Enable the ADC channel .
117+ Enable the ADC block .
108118
109119 .. method :: adc.deinit()
110120
111- Disable the ADC channel.
121+ Disable the ADC block.
122+
123+ .. only :: port_wipy
124+
125+ class ADCChannel --- read analog values from internal or external sources
126+ =========================================================================
127+
128+ .. only :: port_wipy
129+
130+ ADC channels can be connected to internal points of the MCU or to GPIO pins.
131+ ADC channels are created using the ADC.channel method.
132+
133+ .. method :: adcchannel()
134+
135+ Fast method to read the channel value.
136+
137+ .. method :: adcchannel.value()
138+
139+ Read the channel value.
140+
141+ .. method :: adcchannel.init()
142+
143+ Re-init (and effectively enable) the ADC channel.
144+
145+ .. method :: adcchannel.deinit()
146+
147+ Disable the ADC channel.
0 commit comments