16-Channel 12-bit PWM Servo Board

For Adafruit customers who seek help with microcontrollers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
michaeljvdh
 
Posts: 16
Joined: Fri Sep 06, 2013 10:01 am

16-Channel 12-bit PWM Servo Board

Post by michaeljvdh »

I bought the following product https://www.adafruit.com/products/1411
I have it hooked up to my raspberry pi. And it's working great. I can move my servo 180 degree's
However .. I have NO clue on how to control the speed. It was quite simple on Arduino ... but I cant figure this out for the pi.
The lesson at Adafruit .. doesnt really go in it in detail. I could really use some help.

This is where I was trying to see how you control the speed of the action ? https://learn.adafruit.com/adafruit-16- ... -reference

Makes no sense to me ... Thanks in advance.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: 16-Channel 12-bit PWM Servo Board

Post by adafruit_support_bill »

RC Servo speed is a function of the servo. When you send it a position via setPWMFreq() it will move there as fast as it can. RC Servos speed is typically reported as how fast it will move over a 60 degree arc at a certain voltage with no load.

If you want to sweep slowly, you need to send it incremental commands over a period of time.

User avatar
michaeljvdh
 
Posts: 16
Joined: Fri Sep 06, 2013 10:01 am

Re: 16-Channel 12-bit PWM Servo Board

Post by michaeljvdh »

Hi yeah in python I ran it through a series of steps using the for statement cycling through 100 ticks for example.

However it's ability to issue and respond is LIGHT YEARS behind the speed of the Arduino that's for sure. I know the Arduino is allot faster based on it's design and being able to communicate directly with hardware. But I didn't realise it was THAT fast compared to the pi.

I couldn't judge this speed through he use of relays and other on off style electronics .. but via a servo .. you can see the Arduino's speed.

Am I correct in what I have observed above.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: 16-Channel 12-bit PWM Servo Board

Post by adafruit_support_bill »

The Pi does have a bit more overhead between the python script and the hardware. But you should be able to get reasonable response from the servo. If you post your code we'll see if there is anything that can be optimized.

User avatar
michaeljvdh
 
Posts: 16
Joined: Fri Sep 06, 2013 10:01 am

Re: 16-Channel 12-bit PWM Servo Board

Post by michaeljvdh »

Here is the code .. the servo moves slowly ? if I don't use the for statement and just make to move from 200 to 600 and move allot faster ?

# Initialise the PWM device using the default address
# bmp = PWM(0x40, debug=True)
pwm = PWM(0x40, debug=True)

servoMin = 150 # Min pulse length out of 4096
servoMax = 600 # Max pulse length out of 4096

def setServoPulse(channel, pulse):
pulseLength = 1000000 # 1,000,000 us per second
pulseLength /= 60 # 60 Hz
print "%d us per period" % pulseLength
pulseLength /= 4096 # 12 bits of resolution
print "%d us per bit" % pulseLength
pulse *= 1000
pulse /= pulseLength
pwm.setPWM(channel, 0, pulse)

pwm.setPWMFreq(60) # Set frequency to 60 Hz


for x in range(200,600):
pwm.setPWM(0,0,x)
for x in range(600,200,-1):
pwm.setPWM(0,0,x)

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

Re: 16-Channel 12-bit PWM Servo Board

Post by adafruit_support_bill »

Eliminating the for should make it move much faster. You can also try increasing the step value in the range. e.g:

Code: Select all

for x in range(200,600,5):

User avatar
michaeljvdh
 
Posts: 16
Joined: Fri Sep 06, 2013 10:01 am

Re: 16-Channel 12-bit PWM Servo Board

Post by michaeljvdh »

Perfect .. thank you Ill try this and report back.

Locked
Please be positive and constructive with your questions and comments.

Return to “Microcontrollers”