I find I prefer to control the timing if my timers when driving a servo.
So, if you initialize the timer like this (take from
https://github.com/dhylands/upy-example ... .py#L6-L13):
Code: Select all
# For this example, we'll setup a timer in PWM mode to generate a servo pulse.
# Using a prescalar of 83 gives a timer-tick frequency of 1 MHz (84 MHz / 84).
# The period of 19999 gives a 20,000 usec or 20 msec period. The pulse width
# is then in microseconds.
servo_pin = pyb.Pin.board.X1
t5 = pyb.Timer(5, prescaler=83, period=19999);
servo = t5.channel(1, pyb.Timer.PWM, pin=servo_pin)
servo.pulse_width(1000)
Timers 2-7 and 12-14 have a source frequency of 84 MHz, so dividing by 84 gives 1 MHz tick. The other timers (1 and 8-11) have a source freq of 168 MHz, so replace 83 with 167 for those timers).
You can then specify the period of 20 msec, and when you call servo.pulse_width the number you pass in represents microseconds.
This will give you microsecond granularity on the servo. If you initialize the timer and let it choose the period and prescalar (which is what happens when you specify freq=) then you don't know the actual pulse_width granularity and if might differ depending on the timer's source frequency.
That's just my personal preference. If you prefer using percentages then by all means - continue to do so.