Why Is servo library necessary and we can't use PWM directory?

Not sure It this Is a software question, but that's because I dont know the answer .. why should we use servo library to drive a ESC and we cannot use PWM signal directly?

The PWM produced by analogWrite() is different from the signal produced by the servo library even though that is also referred to as PWM. Unfortunately the same name is used for for two different things.

...R

Servo PWM is low duty cycle (5 to 10%) at 50Hz. Has been for well over 40 years.

analogWrite PWM is full range duty cycle (0 to 100%) at around 490 Hz or 980 Hz.

Even if you slowed the frequency of analogWrite PWM to 50 Hz, the resolution available for the active period would be too poor for adequate control.

Servos expect a 1 to 2 ms wide pulse occurring every 20mS (50 Hz as noted above). 1ms is fully turned one direction, 1.5ms is the middle, and 2ms is fully turned the other direction.

AnalogWrite(), which outputs on pins 3,5,6,9,10,11 on an Uno for example, has a width of 1/255 of ~2ms period (at 490 Hz) varying to 254/255 of a 2ms period, or the same from a ~1ms period (at 980 Hz).

Use the Servo() library to control servos on pins you decide. Or use the writeMicroseconds() command

DarioNetLab:
Not sure It this Is a software question, but that's because I dont know the answer .. why should we use servo library to drive a ESC and we cannot use PWM signal directly?

You don't have to use Servo library. It is not "necessary".

Standard RC servo signal expects control pulses coming at ~50Hz frequency. This value is quite flexible, but a plain analog output will not work, since PWM signal there uses much higher frequency. A standard servo can't work with such signal.

However, just for the sake of experiment you can generate the proper signal "manually", with digitalWrite and delayMicroseconds functions, without using Servo library. It will work perfectly fine. This is not a good technique for any serious applications though, since pulses are pretty short and any irregularities in timing caused by you doing other things in the code might/will affect the servo.

So, a better way to generate a stable servo signal in software would be using timer-based interrupt handler. And that is what Servo library does for you.