Servo pin

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
chipxx
Posts: 14
Joined: Mon Oct 21, 2019 8:55 am

Servo pin

Post by chipxx » Sat Nov 16, 2019 9:45 pm

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

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Servo pin

Post by dhylands » Sat Nov 16, 2019 9:59 pm

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.

Code: Select all

>>> t1 = pyb.Timer(1)
>>> t1.source_freq()
168000000
>>> t2 = pyb.Timer(2)
>>> t2.source_freq()
84000000
>>> 

chipxx
Posts: 14
Joined: Mon Oct 21, 2019 8:55 am

Re: Servo pin

Post by chipxx » Sat Nov 16, 2019 10:34 pm

So if I wanted to use 12 servos, that would be a problem. Nice catch... ahahahahaha
chipxx

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: Servo pin

Post by dhylands » Sat Nov 16, 2019 11:06 pm

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.

Post Reply