Average two PWM signals

I am a total noob, so please forgive if this is a stupid question. How would I best go about using two PWM signals as input, calculate the average of the two and output the result as a PWM signal? If that proves simple enough, I would also like to be able to add a percentage of the averaged signal to the output. For example, if one signal provided a duty cycle of 40%, and the other signal was 60%, the average of the two would be 50%. To this result would be added, say, ten percent, resulting in an output with a duty cycle of 55%.

It isn't a stupid question. It's a very good question to make advanced users think very hard :P

The Arduino has internal timers, and can measure frequencies and pulse widths. http://arduino.cc/en/Reference/pulseIn But two of those signals is harder.

What is the frequency and the width of the pulse ? If that frequency is too high, perhaps you can use an RC filter to make the pwm signals analog and let the Arduino read the analog signal. Would that be an option ? or is that too inaccurate ?

Is this an R/C channel mixer problem?

Thumbs up for the second option.

With a carefull filter design add an rc filter and capture the voltage with the ADC.

So now you have:

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int pwm1 = analogRead(A0);  //Read PWM signal 1
  int pwm2 = analogRead(A1);  //Read PWM signal 2
  
  
  //Create a Variable to average both signals
  int pwmout = ((pwm1+pwm2)/2)
  
  analogWrite(6, (pwmout/4));
  //Write the pwmout value 
  Serial.println(pwmout/4);
  // print out the value you read (0 to 255)
}

AWOL: Is this an R/C channel mixer problem?

Yes it is, (kind of). I am building a (sort of) quadrotor using Arducopter, I wish to eliminate the open props, so I am using 4 electric ducted fans as the 4 rotors, but there are a couple of problems: 1, they are power hungry, and not too efficient at providing static thrust, and 2, due to their lack of "traction" compared to props, they provide poor yaw control. In order to (hopefully) mitigate these problems, I am using a central, ducted pair of contra rotating propellers to provide yaw control and most of the lift. My thinking is that if I take the two signals for the clockwise motors, average them, and feed that signal to the center clockwise prop, and do the same for the counterclockwise set, the net effect will be to cancel out the pitch and roll factors while retaining yaw control. I am aware that this would be relatively easy by channel mixing with the transmitter, but that would only achieve manual flight control, and I would like it all to work on autopilot. I took a look at the Arducopter software, and I fear that rewriting it will forever remain beyond my scope. So far, this has been the best plan I could come up with, but I am open to suggestions!

So, are you saying you want to process the actual motor drive PWM, or the ESC/servo drive PWM?

I THINK I want to process the signals which drive the ESC’s, in order to drive a third ESC with the average of the two signals.
Most of my parts are still in transit, so I do not yet know the frequency used by the Ardupilot. I can’t seem to find out from the literature I have studied so far.

Murpocalypse: I THINK I want to process the signals which drive the ESC's

Since the Arducopter is generating the signals, it seems to me that the best approach would be to modify the Arducopter sketch to generate the output you want directly.

If you decide to go ahead with an external device instead, I suspect a servo mixer would do the job far better and far cheaper than an Arduino based solution, although an Arduino solution is definitely possible.

Finally, if you take the Arduino approach you would be dealing with a pair of servo control signals, not plain old pwm.

it seems to me that the best approach would be to modify the Arducopter sketch to generate the output you want directly.

+1