Hello, I’m a couple days in working with my shiny new Panda board. It rocks.
I’m building an autopilot and need smooth clean servo control. I have used the sample code provided somewhere using the PWM driver. I don’t even remeber where I got the same because it’s the most common PWM demo.
That works, but my code loop controls the servo on a timed loop that’s independent of the PWM clock cycle. Instead of smooth steady movement, the servo is jittery, even when I generate a smooth sweep with a loop in my code.
I think my call to SetPulse in the control loop interrupts the PWM signal and sometimes sends the sends the servo only part of the high pulse, basically giving it an error value. I don’t have a scope so I have no good way to confirm this.
Is there a way to use hardware PWM but make sure that a cycle is never interrupted? I imageI’d have the same problem with OutputCompare. I could write my own software driver but I’d rather use h/w PWM. I know I can not call SetPulse if my value hasn’t changed, but I will be making small changes to the values and need smooth output.
Has anyone ran into this? I can paste code here but it’s spread across several classes so I’d have to write a simple demo function, but I can do that.
Are you running the beta? IF you aren’t, there was a bug that got fixed a long time ago that made servos and ESCs go nuts if they were controlled by a PWM pin.
I figured it was best to post the code. I sounds like all will be good with the next release so if I’m doing this the right way I’ll move on to other things and come back to servos.
PWM outputPort = new PWM((PWM.Pin)FEZ_Pin.PWM.Di10);
int delta = 5;
int value = 1250;
while(true)
{
outputPort.SetPulse(20000000, (uint)value * 1000);
value += delta;
if (value >= 1750 || value <= 1250)
{
delta = -delta;
}
Thread.Sleep(100);
}