0

servos & the PWMOut duty_cycle argument
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

servos & the PWMOut duty_cycle argument

by gallaugher on Sat Sep 18, 2021 3:34 pm

I'm trying to make sure I understand if setting a duty_cycle is important when configuring a servo in CircuitPython. The tutorial setup code below has a PWMOut setup that uses a middle parameter for setting the duty_cycle:
Code: Select all | TOGGLE FULL SIZE
pwm = pwmio.PWMOut(board.A2, duty_cycle=2 ** 15, frequency=50)

https://learn.adafruit.com/adafruit-circuit-playground-express/circuitpython-servo
However, this tutorial for working with servos does not include the duty_cycle argument:
[link]https://learn.adafruit.com/using-servos-with-circuitpython/high-level-servo-control[/link]
I tried initializing a PWMOut object with and without the duty_cycle parameter & it looks like the default without the argument is duty_cycle=0. The code seems to work. I then ran code & printed the pwm.duty_cycle property after each angle set to see the change. The pwm.duty_cycle value changed to a fixed value, high for 180 (7372 in my example), lower for lower degrees (2457 at angle 0).
Is it correct to say that setting duty_cycle doesn't matter when configuring the servo? If not, when would I want to include the duty_cycle argument when setting up pwm? The first demo code sets the duty_cycle to something that's way larger than anything my servo produced when switching angles: (2^15 = 32768). I've read through the Adafruit Basics: Analog Inputs & Outputs page, but am still not sure I get what's happening with the middle-attribute in PWMOut and why it should or doesn't need to be used.
Am also wondering, since most inexpensive sensors aren't perfectly calibrated for a true 0 to 180 degree range, is it OK to simply tweak the min and max values like this:
Code: Select all | TOGGLE FULL SIZE
servo_1 = servo.Servo(pwm, min_pulse = 600, max_pulse = 2250)

And at what point do you worry about going too low or high with min & max pulse values? When you hear the motor start to whine?
Thx for any help!

gallaugher
 
Posts: 236
Joined: Tue Aug 14, 2018 12:42 pm

Re: servos & the PWMOut duty_cycle argument

by tannewt on Mon Sep 20, 2021 5:09 pm

I think you are correct on all counts.

1. The constructor argument is a default value and should be fine to omit (default 0 is fine.) I believe zero on some servos can indicate free motion rather than a specific angle.
2. min_pulse and max_pulse should be used for calibration.
3. Yup, out of range values may cause a motor stall (aka whine.)

tannewt
 
Posts: 2631
Joined: Thu Oct 06, 2016 8:48 pm

Re: servos & the PWMOut duty_cycle argument

by gallaugher on Mon Sep 20, 2021 7:45 pm

Thx for clearing things up. And congrats on 7.0! We all appreciate your work.

gallaugher
 
Posts: 236
Joined: Tue Aug 14, 2018 12:42 pm

Please be positive and constructive with your questions and comments.