From 57b96a7be214c8f2493db7d430348f5efcc8ad34 Mon Sep 17 00:00:00 2001 From: danicampora Date: Tue, 23 Feb 2016 20:18:45 +0100 Subject: [PATCH] docs: Correct machine.Timer code examples related to duty cycle. --- docs/library/machine.Timer.rst | 14 ++++++++------ docs/wipy/quickref.rst | 12 ++++-------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/docs/library/machine.Timer.rst b/docs/library/machine.Timer.rst index a3be95b0e0..daf63c9b93 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 --------- diff --git a/docs/wipy/quickref.rst b/docs/wipy/quickref.rst index a2886e78c6..6fd77a81bd 100644 --- a/docs/wipy/quickref.rst +++ b/docs/wipy/quickref.rst @@ -63,16 +63,12 @@ PWM (pulse width modulation) See :ref:`machine.Pin ` and :ref:`machine.Timer `. :: from machine import Timer - from machine import Pin - # assign GP25 to alternate function 9 (PWM) - p_out = Pin('GP25', mode=Pin.AF, alt=9) - - # timer 2 in PWM mode and width must be 16 buts - tim = Timer(2, mode=Timer.PWM, width=16) + # timer 1 in PWM mode and width must be 16 buts + tim = Timer(1, mode=Timer.PWM, width=16) - # enable channel A @1KHz with a 50% duty cycle - tim_a = tim.channel(Timer.A, freq=1000, duty_cycle=50) + # enable channel A @1KHz with a 50.55% duty cycle + tim_a = tim.channel(Timer.A, freq=1000, duty_cycle=5055) ADC (analog to digital conversion) ----------------------------------