Arduino 16 pwm driver setServoPulse function

For other supported Arduino products from Adafruit: Shields, accessories, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
dielectrichair
 
Posts: 1
Joined: Wed Mar 25, 2015 6:20 am

Arduino 16 pwm driver setServoPulse function

Post by dielectrichair »

Hi there

I am currently trying to use the Arduino 16 pwm driver to control 16 servos for the legs of a hexapod.

In the pwm driver library's sample file servo there is an unused function called setServoPulse.

Can someone please explain how to use this function?

Code: Select all

// you can use this function if you'd like to set the pulse length in seconds
// e.g. setServoPulse(0, 0.001) is a ~1 millisecond pulse width. its not precise!
void setServoPulse(uint8_t n, double pulse) {
  double pulselength;
  
  pulselength = 1000000;   // 1,000,000 us per second
  pulselength /= 60;   // 60 Hz
  Serial.print(pulselength); Serial.println(" us per period"); 
  pulselength /= 4096;  // 12 bits of resolution
  Serial.print(pulselength); Serial.println(" us per bit"); 
  pulse *= 1000;
  pulse /= pulselength;
  Serial.println(pulse);
  pwm.setPWM(n, 0, pulse);
}

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

Re: Arduino 16 pwm driver setServoPulse function

Post by adafruit_support_bill »

Most RC servos respond to pulse widths in the 1 to 2 ms range, with 1.5ms being the center or 'neutral' position.
Assuming a standard 180 servo travel range:
setServoPulse(0, 0.001); should position the servo at about 0 degrees
setServoPulse(0, 0.0015); should position the servo at about 90 degrees
setServoPulse(0, 0.002); should position the servo at about 180 degrees

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

Return to “Other Arduino products from Adafruit”