nRF51 SDK - S110 SoftDevice
|
The PWM Example shows how the Programmable Peripheral Interconnect (PPI) and a free running timer can be used to output a PWM waveform over a GPIO. The GPIO pin could drive a small speaker, for example.
This example generates a variable duty cycle pulse. The duty cycle is changed by buttons and will vary between 1 and 255. Note that the value 0 is omitted because it would cause two events to be triggered at the same time, which would result in only one toggle of the output pin. Timer 2 is used to dispatch GPIOTE toggle events on every compare match. CC1 will set the output pin high, while CC0 and CC2 will toggle it low every other turn, ending a duty cycle. These compare timings will be set by an interrupt that happens every CC1 at the 0 (or 256) mark for the period. This interrupt will increase CC1 with one more period. Also, this interrupt will set CC0 or CC2 to the value retrieved from the state of the buttons. If CC0 or CC2 is set changes every turn.
The application will emit light on LED 1, corresponding to the duty cycle. With a higher value, the LED will emit brighter light.
The name of the example is pwm_pca10028. If you are not using the Keil Pack Installer, you can find the source code and project file of the example in the following folder: <InstallFolder>\Nordic\nrf51\examples\peripheral\pwm
LED assignments:
Button assignments:
Test the PWM Example application by performing the following steps: