Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

PWM ValueError: duty_cycle must be between 0 and 65535 inclu
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

PWM ValueError: duty_cycle must be between 0 and 65535 inclu

by garyscetbon on Wed Jun 17, 2020 3:07 pm

I'm trying to control a servo motor from a Trinket M0. My code is:

Code: Select all | TOGGLE FULL SIZE
import time
import board
import pulseio
from adafruit_motor import servo
pwm = pulseio.PWMOut(board.A4, duty_cycle=2 ** 15, frequency=1000)
my_servo = servo.Servo(pwm)
my_servo.angle = 180


But I get a ValueError saying that "PWM duty_cycle must be between 0 and 65535 inclusive (16 bit resolution)."

Full disclosure: this used to work but I accidentally short circuited my wiring by connecting the control wire of the servo to the reset pin of the Trinket M0. Is it possible that this would have damaged the SAMD21 on the M0?

garyscetbon
 
Posts: 4
Joined: Wed Dec 12, 2018 9:49 am

Re: PWM ValueError: duty_cycle must be between 0 and 65535 i

by dastels on Wed Jun 17, 2020 3:57 pm

If it was damaged, I doubt it should show itself this way.

What line does the error occur on? Can you paste the console output from running this, please?

Dave

dastels
 
Posts: 2987
Joined: Tue Oct 20, 2015 3:22 pm

Re: PWM ValueError: duty_cycle must be between 0 and 65535 i

by garyscetbon on Wed Jun 17, 2020 4:23 pm

I ended up changing the pwm definition line with:
Code: Select all | TOGGLE FULL SIZE
pwm = pulseio.PWMOut(board.A4, frequency=50)

That works but prevents me from assigning multiple servos on different pins (I get a "all timers are in use" error).
The workaround I found is to deinit() the pwm pin each time I want to use another one.
Not super efficient, I'm open to any improvement suggestion.

garyscetbon
 
Posts: 4
Joined: Wed Dec 12, 2018 9:49 am

Re: PWM ValueError: duty_cycle must be between 0 and 65535 i

by dastels on Wed Jun 17, 2020 6:19 pm

How many servos are you looking to use? A servo driver board like https://www.adafruit.com/product/815 will work if you need several.

Dave

dastels
 
Posts: 2987
Joined: Tue Oct 20, 2015 3:22 pm

Re: PWM ValueError: duty_cycle must be between 0 and 65535 i

by garyscetbon on Wed Jun 17, 2020 6:29 pm

3 servos so far. But yes you're right thanks for the tip, I need one of those to control them asynchronously.

garyscetbon
 
Posts: 4
Joined: Wed Dec 12, 2018 9:49 am

Please be positive and constructive with your questions and comments.