Hi, on my pyboard I experienced the servo.
The x1,x2,x3,x4 pins work well but if I want to use another pin it gives me an error, for example pin x5: ''Servo(5) does not exist.''
Any ideas?
Thank you
chipxx
Servo pin
Re: Servo pin
The Servo pins only support 1-4 which map to X1-X4 (See: http://docs.micropython.org/en/latest/l ... Servo.html). However, you can drive servos using any pin that can generate a PWM signal.
Here's some code which generates a typical servo pulse: https://github.com/dhylands/upy-example ... ic_test.py
Servo pulses are typically 1-2 ms wide and sent approximately 50-60 times per second.
The prescalar that you'd use will depend on the exact timer you use. You can use the source_freq() method to determine the source frequency. For example Timer 1 has a source frequency of 168 MHz, so you'd use a prescalar of 167, and Timer 2 has a source frequency of 84 MHz, so you'd use a prescalar of 83.
Here's some code which generates a typical servo pulse: https://github.com/dhylands/upy-example ... ic_test.py
Servo pulses are typically 1-2 ms wide and sent approximately 50-60 times per second.
The prescalar that you'd use will depend on the exact timer you use. You can use the source_freq() method to determine the source frequency. For example Timer 1 has a source frequency of 168 MHz, so you'd use a prescalar of 167, and Timer 2 has a source frequency of 84 MHz, so you'd use a prescalar of 83.
Code: Select all
>>> t1 = pyb.Timer(1)
>>> t1.source_freq()
168000000
>>> t2 = pyb.Timer(2)
>>> t2.source_freq()
84000000
>>>
Re: Servo pin
So if I wanted to use 12 servos, that would be a problem. Nice catch... ahahahahaha
chipxx
chipxx
Re: Servo pin
By my count, there are 18 PWM lines that could be used (on the pyboard). You can use multiple channels on the same timer. But you can't use CH2N and CH2 (since CH2N is an inverse of CH2 in hardware).
Here's my list:
Timer 1, channels 1, 2, and 3
Timer 2, channels 1, 3, and 4
Timer 4, channels 1, 2, 3, and 4
Timer 5 channels 1, 2, 3, 4
Timer 8, channels 1, 2
Timer 13, channel 1,
Timer 14 channel 1.
Here's my list:
Timer 1, channels 1, 2, and 3
Timer 2, channels 1, 3, and 4
Timer 4, channels 1, 2, 3, and 4
Timer 5 channels 1, 2, 3, 4
Timer 8, channels 1, 2
Timer 13, channel 1,
Timer 14 channel 1.