summaryrefslogtreecommitdiffstatshomepage
path: root/docs/library/machine.Timer.rst
diff options
context:
space:
mode:
authordanicampora <daniel@wipy.io>2015-10-20 16:24:25 +0200
committerdanicampora <daniel@wipy.io>2015-10-21 15:30:56 +0200
commitceb169008d93165d461a9ab1b9bb5e9c85d03949 (patch)
tree93354eab1b3e98ffa5902f98adaea224edc54a78 /docs/library/machine.Timer.rst
parent04db848dc7c7356a38f809b5efdd4699a41aa54f (diff)
downloadmicropython-ceb169008d93165d461a9ab1b9bb5e9c85d03949.tar.gz
micropython-ceb169008d93165d461a9ab1b9bb5e9c85d03949.zip
docs: Several corrections to the classes in the machine module.
Diffstat (limited to 'docs/library/machine.Timer.rst')
-rw-r--r--docs/library/machine.Timer.rst19
1 files changed, 11 insertions, 8 deletions
diff --git a/docs/library/machine.Timer.rst b/docs/library/machine.Timer.rst
index 4814da8603..5d357ca079 100644
--- a/docs/library/machine.Timer.rst
+++ b/docs/library/machine.Timer.rst
@@ -19,13 +19,15 @@ class Timer -- control internal timers
Example usage to toggle an LED at a fixed frequency::
- tim = machine.Timer(4) # create a timer object using timer 4
- tim.init(mode=Timer.PERIODIC) # initialize it in periodic mode
- tim_ch = tim.channel(Timer.A, freq=2) # configure channel A at a frequency of 2Hz
- tim_ch.callback(handler=lambda t:led.toggle()) # toggle a LED on every cycle of the timer
+ from machine import Timer
+ tim = Timer(4) # create a timer object using timer 4
+ tim.init(mode=Timer.PERIODIC) # initialize it in periodic mode
+ tim_ch = tim.channel(Timer.A, freq=2) # configure channel A at a frequency of 2Hz
+ tim_ch.callback(handler=lambda t:led.toggle()) # toggle a LED on every cycle of the timer
Example using named function for the callback::
+ from machine import Timer
tim = Timer(1, mode=Timer.PERIODIC)
tim_a = tim.channel(Timer.A, freq=1000)
@@ -39,8 +41,9 @@ class Timer -- control internal timers
Further examples::
- tim1 = machine.Timer(2, mode=Timer.EVENT_COUNT) # initialize it capture mode
- tim2 = machine.Timer(1, mode=Timer.PWM) # initialize it in PWM mode
+ from machine import Timer
+ tim1 = Timer(2, mode=Timer.EVENT_COUNT) # initialize it capture mode
+ tim2 = Timer(1, mode=Timer.PWM) # initialize it in PWM mode
tim_ch = tim1.channel(Timer.A, freq=1, polarity=Timer.POSITIVE) # start the event counter with a frequency of 1Hz and triggered by positive edges
tim_ch = tim2.channel(Timer.B, freq=10000, duty_cycle=50) # start the PWM on channel B with a 50% duty cycle
tim_ch.time() # get the current time in usec (can also be set)
@@ -54,8 +57,8 @@ class Timer -- control internal timers
.. note::
- Memory can't be allocated during a callback (an interrupt) and so
- exceptions raised within a callback don't give much information. See
+ Memory can't be allocated inside irq handlers (an interrupt) and so
+ exceptions raised within a handler don't give much information. See
:func:`micropython.alloc_emergency_exception_buf` for how to get around this
limitation.