I have here some C code I wrote for a PIC chip to run up to 9 servos smoothly, simultaneously, and very importantly, in the background of the main program. It uses two interrupts to do the timing of the pulse widths. There are two slightly different versions. The first, and more basic, allows you to control the absolute angle of the n'th servo using set_angle(int8 ang, int8 n). Everything else is dealt with by the two interrupts. The second version requires an extra timer. In addition to the set_angle function, there is the set_move(signed int8 m, int8 n) function, which sets the movement variable of the n'th servo. This variable is then added to the absolute angle of the n'th servo every movement interrupt. This allows for smooth, constant speed rotation with minimal effort elsewhere in the program.
Here is a schematic to show what the timers are doing. It could be done with only one timer, but I didn't think of it at the time. I'll change it if I ever need more timers for the main program.
I use the PCH CSS command line compiler for linux. I can't imagine it would be very hard to port to something else. Here's an example using the simple version of the driver, servoabs.c (there's a link to a .zip containing all files near the bottom of the page). It accepts four bytes from UART, and then updates the absolute positions of the servos accordingly:
And here (below) is an example using the slightly beefed up servoext.c. It accepts four bytes from UART: With the first two, it adjusts the movement variable of the first two servos. The first argument of set_move is a signed int8, where 0 corresponds to no movement, positive numbers move it one direction, and negative numbers the other direction. The magnitude of the number corresponds to the speed. The absolute position of the servo will halt at the upper bound of 255 and the lower bound of 0 (ie. will not roll over). The second two variables set the absolute position of the third and fourth servos, as in the previous example. Take note of the second line of code. Without giving timer3 interrupt priority, movement will be very jerky. This is because timer2 would always be interrupting timer3, thus prolonging the length of some servo's pulse width.