Skip to content
campbellsan edited this page Jun 26, 2014 · 6 revisions

Some servos will work with a simple PWM output, however the specification for driving servos is as follows, a pulse every 50 to 160 milliseconds. Pulse length between 1 and 2 mS. The pulse length is what specifies the required servo position, 1ms maximum anti clockwise and 2ms maximum clockwise rotation. To control the servo outputs, write the servo number (0 - 3) to the SPI, then write a pulse length value (0 - 255). 0 means 1 ms 255 means 2 ms. To control the 8 outputs, select the output register by writing 4 to the SPI, then follow with an 8 bit value to set the I/O.

Note the tiny blip at 15 ms in the above waveform. That is all you can see of the SPI data transfer. There is another transfer at around 20 ms, but that one is hidden under a ledger line. You can see the servo outputs changing after receiving new SPI data. If you were able to zoom into the area of the blip, you would see SPI data transfer with clocking just as for the PWM core linked above. The timescale is expanded in this waveform because, as you can see, the servo pulses are relatively far apart compared to the SPI clock speed.

As for the other cores with outputs, they are updated immediately as the bits come in. This results in a one serial clock (sclk) skew on each output bit.