summaryrefslogtreecommitdiffstatshomepage
path: root/docs/library
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-02-05 14:20:17 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2017-02-05 14:20:17 +0300
commitd5e9ab6e61729f533dbed5c2b6b27307ce6c3b55 (patch)
tree727c3606486ac2722726ad9471f37e6f95f7d660 /docs/library
parentbd04ed3e8a4235664743fd4c452091a9ce603011 (diff)
downloadmicropython-d5e9ab6e61729f533dbed5c2b6b27307ce6c3b55.tar.gz
micropython-d5e9ab6e61729f533dbed5c2b6b27307ce6c3b55.zip
extmod/machine_pulse: Make time_pulse_us() not throw exceptions.
machine.time_pulse_us() is intended to provide very fine timing, including while working with signal bursts, where each transition is tracked in row. Throwing and handling an exception may take too much time and "signal loss". So instead, in case of a timeout, just return negative value. Cases of timeout while waiting for initial signal stabilization, and during actual timing, are recognized. The documentation is updated accordingly, and rewritten somewhat to clarify the function behavior.
Diffstat (limited to 'docs/library')
-rw-r--r--docs/library/machine.rst11
1 files changed, 7 insertions, 4 deletions
diff --git a/docs/library/machine.rst b/docs/library/machine.rst
index 753f6b4173..c6da715852 100644
--- a/docs/library/machine.rst
+++ b/docs/library/machine.rst
@@ -118,12 +118,15 @@ Miscellaneous functions
microseconds. The `pulse_level` argument should be 0 to time a low pulse
or 1 to time a high pulse.
- The function first waits while the pin input is different to the `pulse_level`
- parameter, then times the duration that the pin is equal to `pulse_level`.
+ If the current input value of the pin is different to `pulse_level`,
+ the function first (*) waits until the pin input becomes equal to `pulse_level`,
+ then (**) times the duration that the pin is equal to `pulse_level`.
If the pin is already equal to `pulse_level` then timing starts straight away.
- The function will raise an OSError with ETIMEDOUT if either of the waits is
- longer than the given timeout value (which is in microseconds).
+ The function will return -2 if there was timeout waiting for condition marked
+ (*) above, and -1 if there was timeout during the main measurement, marked (**)
+ above. The timeout is the same for both cases and given by `timeout_us` (which
+ is in microseconds).
.. _machine_constants: