Managing a servo motor
To show you how to use a PWM generator in order to manage a peripheral, we can use a servo motor. This is a really simple motor where we can set a specific gear position by setting a proper duty-cycle of the PWM signal (another example of how to use a PWM in order to generate a clock signal has been reported in the Using an external controller section, in Chapter 14, Controller Area Network - CAN, and the Detecting a gas section, in Chapter 17, Analog-to-Digital Converters - ADC ).
In the following image, you can see the servo motor used in this example:
Note
The device can be purchased at http://www.cosino.io/product/nano-servo-motor or by surfing the Internet.
The datasheet is at http://hitecrcd.com/files/Servomanual.pdf .
First of all, we've to setup the electrical connections. In the following diagram, the correspondence between BeagleBone Black's pins and the servo motor's cables are shown:
By taking a look at the datasheet...