I have been playing around with Saad Ahmad c++ library code mentioned in the thread:
https://groups.google.com/forum/embed/?place=forum/beagleboard&showsearch=true&showpopout=true&showtabs=true&hideforumtitle=true&parenturl=http%3A%2F%2Fbeagleboard.org%2FCommunity%2FForums%3Futm_expid%3D6702460-6%26utm_referrer%3Dhttp%3A%2F%2Fbeagleboard.org%2FSupport%2FHardware%2520Support#!category-topic/beagleboard/C2tzvRYk1Wg
Plus when I was first playing with these commands, I also found that the pulse was wrong for servos, as the polarity was wrong so for example when I was trying to create a 1500us pulse it was actually creating a 20000-1500us pulse. You can change this by updating the polarity variable/file of the test. For your Duty I would expect the valid ranges in us to within the 500-2500us range or maybe tighter (750-2250us). Obviously need to multiple by 1000 to get to ns.
I did an update to his test program that now looks like;
`
#include “PWM.h”
#include
#include
#include <unistd.h>
int main()
{
const int delayMS = 50;
const long periodNS = 20 * MILLISECONDS_TO_NANOSECONDS;
PWM::Pin pinA(“P8_13”, periodNS); // Since both pins share the same channel, they’re periods must be the same
std::cout << “P8_13 created” << std::endl;
PWM::Pin pinB(“P8_19”, periodNS);
std::cout << “P8_19 created” << std::endl;
int slot = PWM::GetCapeManagerSlot(“P8_13”);
std::stringstream ss;
ss << slot;
std::cout << "Found: " << ss.str() << std::endl;
// Enable both only after we have set the periods properly.
// Otherwise we will have conflicts since each pin will try to set its own period and conflict with the others
std::cout << “Before PinA enable” << std::endl;
pinA.Enable();
std::cout << “Before PinB enable” << std::endl;
pinB.Enable();
std::cout << “Pins Setup and ready to go!” << std::endl;
// I want to do a sweep of the two servos from 500us to 2500us
for (int pw = 500; pw < 2500; pw+=100)
{
pinA.SetDutyUS(pw);
pinB.SetDutyUS(3000-pw); // reverse this one.
usleep(100 * 1000); // delay for a bit maybe 5 pulses per pw
}
// Tell both pins to stop.
pinA.Disable();
pinB.Disable();
std::cout << “Done everything. Quiting now!” << std::endl;
}
`
I have my Saleae logic analyzer hooked up to these pins and have verified that I am now generating what appears to be very good servo like output. The only interesting thing was figuring out the best way to end the pulses. If I set the duty to zero, it created some strange outputs on one of the pins, likewise if I just let the objects get destroyed, one channel generated maybe 6 more pulses… Disable did it cleanly.
Note: I went through the complete steps to rebuild the test_pwm object plus create the SC_PWM overlays like he spelled out in his write up.
Kurt