PWM
The BeagleBone's PWM subsystem contains three enhanced PWM (ePWM) modules and one enhanced capture (eCAP) module, all of which have their own two outputs, for a total of up to eight PWM outputs (refer to Appendix A, The BeagleBone Black Pinout to see which pins support PWM). We briefly covered what PWM is in Chapter 1, Before We Begin, but let's look at it in a bit more detail before we start using it.
For this, you will need:
Breadboard
1x 5 mm LED
1x 4.7 kΩ resistor
1x 68 Ω resistor
1x 2N3904 NPN transistor
Jumper wires
Let's start by wiring up an LED with an NPN transistor as we did in Chapter 3, Digital Outputs; only this time, we will drive it with the ePWM1 module's 'A' output on P9.14:
Now let's fire up the Python interactive interpreter and configure the PWM output at 50 percent duty cycle:
>>> from bbio import * >>> analogWrite(PWM1A, 50, 100)
You should see the LED turn on, but dimmer than if you had driven it with a GPIO pin. So what's going on here? The analogWrite...