The Beam and Ball Project - Part 2 Servo Control
Software (continued) Servo Control To control the servo the microcontroller need to produce this 50 Hz waveform shown below. The resolution is defined by the microcontroller because the servo is an analog device. There are mainly three ways of doing it. Delays Set output, then do delay. This is a bad way of doing it. The program is halted for every delay. However if you want to mash up some code to test your servo, this is the way to go. Consumes the whole CPU Good and quick technique to test servos. Hardware PWM The most positive about hardware PWM is that the overhead is 0. The CPU usage is practically zero, and only one or two instruction cycles are used to set a new pulsewidth. Running the PWM at 50Hz demands that the PIC16F887 is ran in max 1 MHz due to max prescaler settings. So at the beginning of the project I went with 1 MHz. The 10bit capable Hardware PWM uses a CCPx module, and TMR2. TMR2 is 8 bit, however the remaining two least significa...