nRF51 SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
PWM example

Modules

 main.c
 PWM Example Application main file.
 

Detailed Description

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.

Setup

Instructions on how to set up the nRFgo Motherboard: nRFgo Motherboard Setup (nRF6310).

LED assignments:

Button assignments:

Testing

The PWM Example Application can be tested as follows:

  1. Compile and program the application.
  2. LED 0 should give a low light intensity.
  3. Press and hold Buttons to check if the LED light intensity changes. A higher value should give a higher LED light intensity.