Page 109 - Build Your Own Quadcopter_ Power Up Your Designs with the Parallax Elev-8
P. 109
88 Bu il d Y o ur O w n Q u a d c o p t e r
Figure 4.17 Picoscope Model 3406B USB oscilloscope.
Pulse-width Modulation and Servo Example
This next example introduces pulse-width modulation (PWM) in which the pulse-on time is
much shorter than the total waveform period. The pulse-on time is normally based upon a
program input, while the total waveform period is kept constant. PWM is the technique
used to control servo motors and is central to the Elev-8 flight-control scheme.
The demonstration program and Top Object are named 1 Center Servos and are part of
the Parallax Learn Propeller Code tutorials. Two more component objects named Propeller
Board of Education and PropBOE Servos are also required to run the Top Object. Running
the Top Object creates a continuous waveform repeating at a 50-Hz rate with a pulse-on time
of 1.5 ms. Figure 4.18 is a screenshot of the waveform measured by the USB oscilloscope
connected to pin 14. The figure shows a 1.5-ms pulse that is repeating at 50 Hz, equivalent to
a 20-ms waveform period.
The very simple 1 Center Servos program is shown in Figure 4.19. Looking at the code
in the 1 Center Servos program shows that the author(s) was not terribly interested in
thoroughly commenting or documenting the code. This lack of comments is a shame because
it makes it hard for anyone using the code to understand how it is supposed to function.
Admittedly, it is a very small program, but it still should have more comments. Having said
that, I will proceed to discuss the program and show you how I made changes to demonstrate
the PWM function.
There is only one method named Go in the program, and this is where the program
starts executing. Yes, it should have been named Main, but as I mentioned earlier, it is a
convention not a mandatory requirement. The first statement in the Go method is:
system.Clock(80_000_000)