Help with digital servos and the Servo Class

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
Iyassou
Posts: 42
Joined: Sun Jun 26, 2016 9:15 am

Help with digital servos and the Servo Class

Post by Iyassou » Thu Jul 13, 2017 2:19 pm

Hello all.

I'm currently using my PYBLITE to control a digital servo (precisely the Savox SG0211MG). So far I've been able to initialize Servo instances keeping in mind the pin mapping for the PYBLITE as mentioned in this thread (viewtopic.php?t=2806) and get the servo to move using the angle method.

Digital servos have smaller cycles compared to analog servos (250Hz-333Hz compared to 50Hz) and the servos' timer (Timer(5)) has a frequency of 50Hz.

Code: Select all

>>> Timer(5).freq()
50
When I set its frequency to 300Hz the servo becomes unresponsive. A soft reboot and recreating the Servo instance gets it working again, the timer operating back at 50Hz.

My question is: is it possible to modify Timer(5)'s frequency for when dealing with digital servos?

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Help with digital servos and the Servo Class

Post by deshipu » Mon Jul 17, 2017 6:07 pm

Unfortunately, that class is written with assumption that the timer frequency is 50Hz and if you try to change it, the counters are all wrong and all you get is a short spike, too narrow to control the servo.

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

Re: Help with digital servos and the Servo Class

Post by dhylands » Mon Jul 17, 2017 7:50 pm

The simplest solution is to probably create your own servo class.

I have some sample code for using the PWM directly here:
https://github.com/dhylands/upy-example ... .py#L6-L13

With the above code, using a period of 3999 would give 250 Hz, and 2999 would give 333 Hz. Setting the pulse width to 1000 means 1000 micro-seconds or 1 milli-second.

Iyassou
Posts: 42
Joined: Sun Jun 26, 2016 9:15 am

Re: Help with digital servos and the Servo Class

Post by Iyassou » Sat Jul 22, 2017 8:34 am

Noted. Thanks for your help guys :)

Post Reply