I have finally got the time to use my WiPy and want to use it to drive some servos, I have only had time for a quick look at the documents and it is going to be a few days before I can try it out.
So I thought I might save myself some time by posting my understanding of PWM on the WiPy and (politely) ask other users to review it and tell me if it is wrong.
If anyone has got a link to working code that would be fantastic
from WiPy pinout only the following pins can be used for PWM with alternate function in brackets
GP24 (5)
GP11 (3)
GP10 (3)
GP9 (3)
Is the alternate function for GP24 correct or should it be 3?
GP11 is referred to as PWM_8 and is connected to Timer 3 channel B, so this is the timer used to control the PWM.
sample code as a starting point:
from machine import Timer
from machine import Pin
# set GP11 as an output and specify alternate function 3 for PWM
g=machine.Pin('GP11',mode=Pin.OUT, alt=3)
# now initialse Timer 3 as PWM and it is associated with GP11 automatically
tim = Timer(3, mode=Timer.PWM, width=16)
# now set frequency and duty cycle
tim_b = tim.channel(Timer.B, freq=50, duty_cycle=0500)#5%pulse =0
time.sleep_ms(100)
tim_b = tim.channel(Timer.B, freq=50, duty_cycle=0750) # 7.5% pulse = 90 degs
time.sleep_ms(100)
tim_b = tim.channel(Timer.B, freq=50, duty_cycle=1000) # 10% pulse = 180 degs
---------------------------------------------
thanks
Controlling hobby servos
Re: Controlling hobby servos
got my code to work,
mode should be Pin.ALT, not Pin.OUT
mode should be Pin.ALT, not Pin.OUT