nRF51 SDK - S210 SoftDevice
|
The PWM Example project shows how the PPI and a freerunning timer can be used to output a PWM waveform over a GPIO. The GPIO pin could for example drive a small speaker.
This example generates a variable duty cycle pulse train on the selected GPIO pin. The duty cycle is read as a byte taken from the state of the buttons and will vary between 1-255. Notice that the value 0 is omitted, this is because of a problem with having two events trigger at the same time only causing 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 happening every CC1 at the 0(or 256) mark for the period. This interrupt will increase CC1 with one more period and every turn change between setting CC0 and CC2 to the value retrieved from the state of the buttons. The program will emit light on LED0 corresponding to what value is pressed in with buttons, where Button "BUTTON_START" is LSB bit and Button "BUTTON_STOP" is MSB bit of a byte. With a higher value the LED will emit brighter light.
Instructions on how to set up the nRFgo Motherboard: nRFgo Motherboard Setup (nRF6310).
LED assignments:
Button assignments:
The PWM Example Application can be tested as follows: