nRF51 SDK - S120 SoftDevice
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
Motor Control Example

The Motor Control Example project shows a PWM waveform generation where the timer resets after each full period. It generates a variable duty cycle pulse train on selected GPIO pin. By default the PWN waveform generation will have a duty cycle of 1/256. If Button 1 is pressed the duty cycle is set to 224/256. If only Button 0 is pressed duty cycle is set to 32/256. This example application could be controlling a step motor. It uses the hardware delivered in the nRF51822 Development Kit.

The application starts with configuring the GPIOTE by setting inputs and outputs, and setting channel 0 to toggle pin 8 (LED 0). The PPI peripheral is configured to toggle pin 8 (LED 0) on every Timer 2 COMPARE[0] and COMPARE[1] match. The Timer 2 is initialized and the interrupts are enabled.

Setup

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

LED assignments:

  • LED 0 is used to show the generated duty cycle.

Buttons assignments:

  • Button 0 is used to set the duty cycle to 224/256.
  • Button 1 is used to set the duty cycle to 32/256.

Testing

The Motor Control Example Application can be tested as follows:

  1. Compile and program the application.
  2. Observe that LED 0 is lit with a very low light intensity.
  3. By pressing Button 0, LED 0 should light with a higher intensity.
  4. By pressing Button 1, LED 0 should light with an even higher intensity.