need help with servo jitter due to unstable PWM signal

As the title says, i need to build a servo mixer that takes in 4 signals coming from a RX. there are 4 output servos that need to move in certain direction based on what the input signal do. for example, when input 1 makes servo 1 and 2 move clockwise, but input signal 2 makes servo 1 and 2 move in opposite directions. (very much like a V-tail mixer on RC where 2 servos move and mix based on the elevator and rudder inputs.)

Anyway, i have the program working correctly now so that the servos move correctly. I basically have 2 mixes per servo pair and 2 pair that operate the same way. so what i did was read the incoming signal and scale to the servo range of motion from 0 to 180 and stored that value, then i read the second signal and scale the range of motion from 180 to 0 to get the reverse channel and save that as well. finally i add both angle values and divide by 2 to get the average of the 2, this works perfectly.
The problem now is that the value of the incoming signals fluctuates ever so sightly. this makes for a slightly different output angle every time the program reads through the code. this cause a .5 to 2 degree servo jitter on the output.

The question now is, what can i do to stabilize these signals or buffer them to ignore those slight variations in output but still respond to deliberate inputs.

  cycfaval = pulseIn (cycfa, HIGH);           //read pulse from cyclic fore/aft, store in cyclic fore aft val
  constrain (cycfaval, 1000, 2000);           //constrain the values of cycfaval from 1000 to 2000 Us
  FPEval = map(cycfaval, 1000, 2000, 0, 180);  // map cyclic fore/aft to front pitch servo
  BPEval = map(cycfaval, 1000, 2000, 180, 0);  // map cyclic fore/aft to back pitch servo


  collval = pulseIn (coll, HIGH);             //read pulse from collective, store in collective val
  constrain (collval, 1000, 2000);            //constrain the values of collval from 1000 to 2000 Us
  FPCval = map(collval, 1000, 2000, 0, 180);   // map collective to front pitch servo
  BPCval = map(collval, 1000, 2000, 0, 180);   // map collective to back pitch servo

  FPval = ((FPEval+FPCval)/2);                  // calculate total movement for Front pitch servo
  BPval = ((BPEval+BPCval)/2);                  // calculate total movement for back pitch servo

  FP.write (FPval);                             // write total value to front pitch servo
  BP.write (BPval);                             // write total value to back pitch servo

I was recently working on a project where servo library output jitter was an issue.

First rule out mechanical issue. Some cheap servos jitter.. just the way it is. The have cheap potentiometer's in them they aren't precise enough to hold position.

Does the output jitter when you are sending a fixed output pulse? I found that mine still did.

Using servo.writeMicroseconds() will give more resolution. You are taking 1000-2000 input pulse length converting to 0-180 number. If you keep just using microseconds you won't lose that resolution.

In the end I found it was also the servo pulse itself that fluctuated by up to 10 microseconds because of interrupts my code. I only had two servos so I used a timer1 servo library to remove all the jitter.

Thank you for the advice, i did not know that command.
if i can scale the input and the output as a range of 1000 rather then 180, subtle changes may not cause as much fluctuation (like you said). going to try that right now.

these are not cheap servos, they go to one of my big helicopters (they are futaba digital servos) and they have worked with 0 jitter attached to a BeastX flybarless controller. they are rock solid.

will update soon.

reaper64D:
if i can scale the input and the output as a range of 1000 rather then 180

Do you even need to do that? Looks to me like you're working in a µs domain to start with.

manor_royal:
Do you even need to do that? Looks to me like you're working in a µs domain to start with.

For sensitive systems even small fluctuations make a difference. 5 us is more than one "click" of trim on my RC stuff. Can mean the difference of going straight or not. On a quadcopter if you adjust your trim 2us to any direction it starts moving.

0-180 only would give a resolution of 6-7 us unless I am missing something obvious.

Yeah I understood that. I said, is it necessary to go from degrees back to microseconds when it looks to me like you're coming from microseconds in cycfaval of 1000-2000 in the first place.

You go from 1000-2000 to 0-180 degrees and now you're talking of going back to 1000-2000 microseconds. So just use the values you start with, was my thinking.

manor_royal:
Yeah I understood that. I said, is it necessary to go from degrees back to microseconds when it looks to me like you're coming from microseconds in cycfaval of 1000-2000 in the first place.

You go from 1000-2000 to 0-180 degrees and now you're talking of going back to 1000-2000 microseconds. So just use the values you start with, was my thinking.

Ok sorry, I think we are all saying the same thing here. No scaling necessary.

One other thing comes to mind.. there is only 4us presision with micros() . You might have fluctuations from reading the pulse too.

If it's somewhere close to 1498 pulse in might return 1496 or 1500 for example. I don't know if pulseIn() has the same 4us precision.

Edit: it doesn't use micros() but has some issues with precision too.