Servo class can't set "zero" for PWM

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
riklaunim
Posts: 32
Joined: Fri Aug 22, 2014 5:42 pm

Servo class can't set "zero" for PWM

Post by riklaunim » Fri Sep 26, 2014 8:33 pm

I'm playing with DRV8833 DC motor controller and it uses PWM to controll the motors ( http://www.pololu.com/product/2130 ). When I do:

Code: Select all

s = pyb.Servo(1)
It already starts the PWM with some value and motor starts. When I do:

Code: Select all

s.pulse_width(0)
Motor still moves but very very slowly (640 is returned by s.pulse_width()). I have to kill it with:

Code: Select all

 pyb.Pin('X1', pyb.Pin.OUT_PP).low()
Which is a not so good idea as the servo object would have to be recreated... pulse_width(0) should stop any PWM activiy (or some other class method).

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: Servo class can't set "zero" for PWM

Post by blmorris » Sat Sep 27, 2014 1:14 am

I'll look into this in some more depth later (posting from my phone now), but my initial guess is that PWM as implemented by the Servo class is different from the PWM needed by your DC motor controller. For the Servo class, the PWM signal indicates an angle for the servo to move to, there is a minimum and maximum pulse width but it is never zero. For a DC motor controller (guessing in this case, I'll look it up later) your speed is set by a duty cycle which can fully vary from 0 to 1. Duty cycle doesn't really have much meaning for a hobby servo control signal.
What you need to use is more likely the PWM function added recently to the Timer class by @dhylands, you can get it by updating the firmware on your pyboard.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: Servo class can't set "zero" for PWM

Post by pythoncoder » Tue Sep 30, 2014 10:15 am

blmorris is right. A servo controller emits pulses with a repetition rate of 50Hz. The pulse width varies from roughly 600uS to 2.4mS. In other words the duty cycle never goes to zero, and doesn't extend much beyond 10%. For DC motor control you normally use a much higher repetition rate with a duty cycle from zero to 100%. The timer class offers support for such PWM, see http://micropython.org/doc/module/pyb/Timer

Regards, Pete
Peter Hinch
Index to my micropython libraries.

Post Reply