I've just discovered "Phase and Frequency Correct PWM mode" and I'd like to share it with those who don't already know it. I've searched the forums and I don't think this has been posted before.If I understood correctly, it's the best way to control 1 or 2 servos. It's much more precise than delay_cycles and more comfortable because it doesn't take any CPU time.

This is what you have to do (will work only with ATmega8 running at 1MHz):

1. Call the following setup function before entering the main loop (before the while(1) in main()):

Its exactly for this kinda scenario that I created my library - (see my signature) - rather than having to come up with different code for different platforms, CPU speed etc etc I created a lib where you could say 'I got a servo on pin xx - please control it with PWM' - and it just does it.

But hey ho - back to the details....

Send me your code and I'll have a look. Roboduino=ATMega168 and F_CPU=16Mhz, right?

Incidentally: Phase and Frequency Correct mode is really aimed at DC motors and, although it will still work fine, you can also use Fast PWM mode for servos.

Phase and frequency correct mode is indeed used for DC motors, but it can also be used for many other applications that require PWM. As far as I know, the main advantage of the phase and frequency corrected PWM is the fact that the pulses are always positioned in the middle of the period. Therefore the signal will be more symmetric, which results in less harmonic distortion in the device you are driving (like a DC motor or some voltage converter coil). For a DC motor this means a decrease in torque ripple, fewer losses due to eddy currents and less stress on the motor magnets (if it has any).

When you are a hobbyist, this might not be the most useful or necessary thing to consider using, but for some more advances control it could be something to look in to. And of course, you can also use it to control servos but they will not benefit from the 'positioned' pulse.

Correct, there is no benefit using that mode with RC servos. The analog servo's internal driver chip uses sample and hold based on the HI pulse width only. They are specifically designed to completely tolerant to phasing, to LO period and to frequency, provided the LO period is less than the timeout period.

I did testing of Hitec and Futaba analog servos deliberately introducing large period and frequency errors( +/- 10% and worse) including random jitter per pulse, and it made no noticable difference to servo performance.

The only thing you need to get right is the period of the HI pulse, and to send pulses often enough so it doesn't shut down.