How can I invert the PWM signal?

No.
See the earlier discussions.

Ok, I am confused. What is the purpose of this inversion? Servos will not function properly with such signals.

Servos will not function properly with such signals.

No, they won't, but maybe the transmission medium prefers inversion (some do)
The OP hasn't told us.

AWOL:

Servos will not function properly with such signals.

No, they won't, but maybe the transmission medium prefers inversion (some do)
The OP hasn't told us.

And it's not the first time a poster has raised such a question, although I can't recall the reason for asking in past cases either.

Shpaget:
Ok, I am confused. What is the purpose of this inversion? Servos will not function properly with such signals.

As my previous experience, the PPM signal level will drop a half when the servo motor is running. So, I add a buffer,ULN2003A, between I/O pin and Servo motor. However, ULN2003A is a inverter. That is the reason that why I need to invert the PPM signal.

As my previous experience, the PPM signal level will drop a half when the servo motor is running

I'd find out why that happens, rather than embarking on software rewrites and additional hardware. Check you power supply.
It's never been a problem with any servo or ESC I've ever used.

AWOL ...

The "mapping" function you are talking about is in WMath.cpp and is merely a linear scaling based on the standard "Cartesian slope-intercept" equation for a straight line (y=mx+b). It linearly scales the input from 0 to 180 (degrees) to an output range set by the 'min' and 'max' parameters set in the function: servo.attach(pin, min, max) - Attaches to a pin, setting min and max values in microseconds.

long map(long x, long in_min, long in_max, long out_min, long out_max)
{
  return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
// where: in_min = 0  and  in_max = 180

Therefore, if you set "x = 180 - invertedWidth" and pass x to the servo.write function it will result the inverted waveform I drew previously IF the min and max values are set correctly for the inverted signal. If you set invertedWidth to 0 it will yield the Maximum microseconds 'normal' pulse resulting in the shortest inverted pulsewidth. Conversely, an invertedWidth of 180 will result in the Minimum microseconds 'normal' pulse width yielding the longest inverted pulsewidth. Any invertedInput between these 2 values will result in a linearly scaled proportional output pulsewidth. The value of the PRT (Pulse Recurrent Time) is needed (25 ms for 40 Hz as posted by others) because the inverted pulse width is equal to (PRT - 'normal' pulsewidth).

I looked at this further while the Arduino site was down last night and determined that you can easily "remap" the function for an inverted waveform just by correctly setting the min and max pulse widths in servo.attach ...

// Assuming fixed frequency Pulse Width Modulation:  40 Hz PRF (= 25000us PRT)
minWidth = 25000 - invertedWidthMin    // in microseconds
maxWidth = 25000 - invertedWidthMax    // in microseconds
servo.attach(pin, minWidth, maxWidth)

Now, passing 0 to servo.write() results in the longest 'normal' pulse and the shortest inverted pulse. Passing 180 to servo.write() results in the shortest 'normal' pulse and the longest inverted pulse. So, setting the min and max properly in the servo.attach function makes the invert operation totally transparent!

Blessings in abundance, all the best, & ENJOY!
Art in Carlisle, PA USA

As my previous experience, the PPM signal level will drop a half when the servo motor is running.

What is the power supply for the servo? Hopefully you aren't trying to power the servo directly from the arduino.

What is the power supply for the servo? Hopefully you aren't trying to power the servo directly from the arduino.

NO, I use another power supply for servo motors with common ground for the Arduino.

Boy, this situation is WAY more complicated than I thought, and I know little about the specific hardware capability and programming details of the various processors. Evidently the SERVO Library uses various interrupts, and the software interrupt services (not any hardware function) set and clear the PWM pin signals. I spent a couple of hours, but found NOTHING in terms of documentation or code comments that leads to defining the default frequency for the SERVO Library. Has anybody ever measured it with a frequency counter? That would be significant.

I did find 2 articles that try to clear up some of the PWM fog, but I didn't get much out of them:
http://playground.arduino.cc/Main/TimerPWMCheatsheet

Also, this article claims that the PWM frequency (Duemilanove with ATmega328) is around 500 Hz! That is totally different from the 40 Hz mentioned elsewhere in this thread.:

So, my apologies to all ... my mathematical analysis MIGHT work, but ONLY if the PWM frequency is accurately known. The library software is SO convoluted and lacking in comments (regarding PWM frequency) that it is no wonder that there is so much confusion out there.

If somebody actually does figure out the Frequency question, it certainly would be appropriate to have some discussion of the Default Frequency added to the introductory comments in the Servo Library source code.

Good luck to all ... I am removing myself from further discussions on this issue. It is way to complicated to resolve peacefully.

Blessings in abundance, all the best, & ENJOY!
Art in Carlisle, PA USA

I spent a couple of hours, but found NOTHING in terms of documentation or code comments that leads to defining the default frequency for the SERVO Library.

#define REFRESH_INTERVAL    20000    // minumim time to refresh servos in microseconds
Servo.h

webtest:
Using my method, if you look at the signal with an oscilloscope, you would see something like the following:

"normal"

___              ___
   |   |            |   |   
  |   |_______|   |

"inverted"
  _     ____________     ____
   |   |            |   |
   ||            ||



This you can do only with a transistor that invert your signal on pin-OUT
BDX53 NPN, Signal PWM on B, VCC on C, GND on E, Signal inverted on C.

This is the scheme.....

Snapshot_20130823_3.JPG

littleming:
As my previous experience, the PPM signal level will drop a half when the servo motor is running. So, I add a buffer,ULN2003A, between I/O pin and Servo motor. However, ULN2003A is a inverter. That is the reason that why I need to invert the PPM signal.

In that case I suggest you fix the underlying problem, rather than looking for obscure workarounds. If the external device is designed to receive a servo signal, it should not be drawing enough current to pull the I/O pin voltage down. What is it, and how much current is it drawing from the control input?

in file C:\Program Files (x86)\Arduino\libraries\Servo\src\xxx\Servo.cpp change the LOW to HIGH and the HIGH to LOW to invert the PWM signal.