aboutsummaryrefslogtreecommitdiff
path: root/docs/library/machine.Timer.rst
diff options
context:
space:
mode:
authordanicampora <daniel@wipy.io>2016-02-23 20:18:45 +0100
committerdanicampora <daniel@wipy.io>2016-02-23 20:22:26 +0100
commit57b96a7be214c8f2493db7d430348f5efcc8ad34 (patch)
tree7cb85812ec5b4b1c7ce52755735c902459e90fda /docs/library/machine.Timer.rst
parent8e1fdf2eb3444740d1631878c270cf0003b5d404 (diff)
docs: Correct machine.Timer code examples related to duty cycle.
Diffstat (limited to 'docs/library/machine.Timer.rst')
-rw-r--r--docs/library/machine.Timer.rst14
1 files changed, 8 insertions, 6 deletions
diff --git a/docs/library/machine.Timer.rst b/docs/library/machine.Timer.rst
index a3be95b0e..daf63c9b9 100644
--- a/docs/library/machine.Timer.rst
+++ b/docs/library/machine.Timer.rst
@@ -40,13 +40,13 @@ class Timer -- control internal timers
Further examples::
from machine import Timer
- tim1 = Timer(2, mode=Timer.ONE_SHOT) # initialize it in one shot mode
- tim2 = Timer(1, mode=Timer.PWM) # initialize it in PWM mode
+ tim1 = Timer(1, mode=Timer.ONE_SHOT) # initialize it in one shot mode
+ tim2 = Timer(2, mode=Timer.PWM) # initialize it in PWM mode
tim1_ch = tim1.channel(Timer.A, freq=10, polarity=Timer.POSITIVE) # start the event counter with a frequency of 10Hz and triggered by positive edges
- tim2_ch = tim2.channel(Timer.B, freq=10000, duty_cycle=50) # start the PWM on channel B with a 50% duty cycle
+ tim2_ch = tim2.channel(Timer.B, freq=10000, duty_cycle=5000) # start the PWM on channel B with a 50% duty cycle
tim2_ch.freq(20) # set the frequency (can also get)
- tim2_ch.duty_cycle(30) # set the duty cycle to 30% (can also get)
- tim2_ch.duty_cycle(30, Timer.NEGATIVE) # set the duty cycle to 30% and change the polarity to negative
+ tim2_ch.duty_cycle(3010) # set the duty cycle to 30.1% (can also get)
+ tim2_ch.duty_cycle(3020, Timer.NEGATIVE) # set the duty cycle to 30.2% and change the polarity to negative
tim2_ch.period(2000000) # change the period to 2 seconds
.. note::
@@ -185,7 +185,9 @@ Methods
.. method:: timerchannel.duty_cycle([value])
- Get or set the duty cycle of the PWM signal (in the range of 0-100).
+ Get or set the duty cycle of the PWM signal. It's a percentage (0.00-100.00). Since the WiPy
+ doesn't support floating point numbers the duty cycle must be specified in the range 0-10000,
+ where 10000 would represent 100.00, 5050 represents 50.50, and so on.
Constants
---------