aboutsummaryrefslogtreecommitdiff
path: root/docs/library/pyb.ADC.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/library/pyb.ADC.rst')
-rw-r--r--docs/library/pyb.ADC.rst72
1 files changed, 54 insertions, 18 deletions
diff --git a/docs/library/pyb.ADC.rst b/docs/library/pyb.ADC.rst
index 2e2c2070d..8623dfc43 100644
--- a/docs/library/pyb.ADC.rst
+++ b/docs/library/pyb.ADC.rst
@@ -1,12 +1,12 @@
.. _pyb.ADC:
-class ADC -- analog to digital conversion: read analog values on a pin
-======================================================================
+class ADC -- analog to digital conversion
+=========================================
.. only:: port_pyboard
Usage::
-
+
import pyb
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
import pyb
- adc = pyb.ADC(pin) # create an analog object on one of the 4 ADC channels
- val = adc.read() # read an analog value
- adc.deinit() # disable the adc channel
- adc.init() # enable the adc channel
+ adc = pyb.ADC() # create an ADC object
+ apin = adc.channel(pin='GP3') # create an analog pin on GP3
+ val = apin() # read an analog value
Constructors
------------
+
.. only:: port_pyboard
.. class:: pyb.ADC(pin)
-
+
Create an ADC object associated with the given pin.
This allows you to then read analog values on that pin.
.. only:: port_wipy
- .. class:: pyb.ADC(pin)
-
+ .. class:: pyb.ADC(id=0, \*, bits=12)
+
Create an ADC object associated with the given pin.
This allows you to then read analog values on that pin.
For more info check the `pinout and alternate functions
table. <https://raw.githubusercontent.com/wipy/wipy/master/docs/PinOUT.png>`_
.. warning::
-
+
ADC pin input range is 0-1.4V (being 1.8V the absolute maximum that it
can withstand). When GP2, GP3, GP4 or GP5 are remapped to the
ADC block, 1.8 V is the maximum. If these pins are used in digital mode,
@@ -58,12 +58,12 @@ Constructors
Methods
-------
-.. method:: adc.read()
+.. only:: port_pyboard
- Read the value on the analog pin and return it. The returned value
- will be between 0 and 4095.
+ .. method:: adc.read()
-.. only:: port_pyboard
+ Read the value on the analog pin and return it. The returned value
+ will be between 0 and 4095.
.. method:: adc.read_timed(buf, timer)
@@ -97,15 +97,51 @@ Methods
# this will take 10 seconds to finish
for val in buf: # loop over all values
print(val) # print the value out
-
+
This function does not allocate any memory.
.. only:: port_wipy
+ .. method:: adc.channel(id, *, pin)
+
+ Create an analog pin. If only channel ID is given, the correct pin will be selected. Alternatively,
+ only the pin can be passed and the correct channel will be selected. Examples::
+
+ # all of these are equivalent and enable ADC channel 1 on GP3
+ apin = adc.channel(1)
+ apin = adc.channel(pin='GP3')
+ apin = adc.channel(id=1, pin='GP3')
+
.. method:: adc.init()
- Enable the ADC channel.
+ Enable the ADC block.
.. method:: adc.deinit()
- Disable the ADC channel.
+ Disable the ADC block.
+
+.. only:: port_wipy
+
+ class ADCChannel --- read analog values from internal or external sources
+ =========================================================================
+
+ .. only:: port_wipy
+
+ ADC channels can be connected to internal points of the MCU or to GPIO pins.
+ ADC channels are created using the ADC.channel method.
+
+ .. method:: adcchannel()
+
+ Fast method to read the channel value.
+
+ .. method:: adcchannel.value()
+
+ Read the channel value.
+
+ .. method:: adcchannel.init()
+
+ Re-init (and effectively enable) the ADC channel.
+
+ .. method:: adcchannel.deinit()
+
+ Disable the ADC channel.