nRF51 SDK - S130 SoftDevice
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
LPCOMP Example

The Low Power Comparator (LPCOMP) Example demonstrates how to use the Low Power Comparator peripheral and the LPCOMP driver.

The example initializes LPCOMP to constantly monitor the level of the analog input 2 (AIN2). If the level falls below half of the power supply, the registered event handler is called.

Information about the detected events is forwarded to the registered LPCOMP event handler, which then increases counters. This event handler is called in an interrupt context; therefore, it should return as quickly as possible. If LPCOMP IRQ priority is set to NRF_APP_PRIORITY_HIGH, there is a limitation in calling SoftDevice functions from the event handler.

The name of the example is lpcomp_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>\examples\peripheral\lpcomp

Testing

Test the LPCOMP example application by performing the following steps:

  1. Compile and program the application.
  2. Start a COM listener like PUTTY and connect to the used COM port with the following UART settings:
    • Baud rate: 38.400
    • 8 data bits
    • 1 stop bit
    • No parity
    • HW flow control: RTS/CTS
  3. After reset, basic information about the example is output on UART.
  4. LED 2 starts flashing to indicate that the example is running. In addition, a wave is generated on P0.02.
  5. LPCOMP now monitors the analog input 2. If the voltage on AIN2 drops below half of the power supply, information is printed on UART. In addition, LED 1 toggles.

To generate a voltage change on AIN2, short pin P0.01 with P0.02. This should indicate two events every second.

On PCA10028, you can also connect pin P0.01 with pin P0.17, where Button 1 is connected. Every button press will then generate an event, and information should be output on UART.