nRF5 SDK v17.1.0
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.

You can find the source code and the 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 terminal emulator like PuTTY and connect to the used COM port with the following UART settings:
    • Baud rate: 115.200
    • 8 data bits
    • 1 stop bit
    • No parity
    • HW flow control: None
  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.02 with P0.04. This should indicate two events every second.

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


Documentation feedback | Developer Zone | Subscribe | Updated