Here is my idea which uses timers allow a servo from every digital I/O pin.I am assuming the MCU is running at 12MIPs (12 instructions per uS)
The position of the servos are stored in an array of integers. Each element in the array is 0-100, 0 being -90
o degrees, 100 being +90
o. The number really represents how many 10s of microseconds more than 1 millisecond you want the pulse to last.
EG servoPosArray[4] = 25 means that the pin controlling servo 4 would give out pulses that are 1ms + 25*10 uS = 1.25 mS long.
1) Turn on all of the I/O pins.
2) Delay for 1ms.
3) Set a timer going.
4) Set up a while loop like this -
while(1) {
if (servoPosArray[1] < (timer0.value/120)) //Has enough time passed to turn off pin controlling servo 1?
pinForServo1 = 0;
if (servoPosArray[2] < (timer0.value/120)) //Has enough time passed to turn off pin controlling servo 2?
pinForServo2 = 0;
if (servoPosArray[3] < (timer0.value/120)) //Has enough time passed to turn off pin controlling servo 3?
pinForServo3 = 0;
...
if (servoPosArray[n] < (timer0.value/120)) //Has enough time passed to turn off pin controlling servo n?
pinForServon = 0;
if((timer0.value/120) > 110) //Every pin should have been turned off by this time. But there is probably some better way to exit the loop.
break;
}
Then all of the I/O pins will be turned off.
5) Now you have about 20ms to do stuff like receive inputs and change the servo position values accordingly.
6) Start again.
That code won't work if you compile it, i just guessed with some of the terms, but it should be understandable. Its a kinda half pseudocode