Using the comparator (COMP), sourced from AIN1 (+) and AIN3 (-, external reference) in the nRF52832 SoC

Hi All,

I'm trying to use the COMP module for detecting when a signal from AIN1 input crosses up or down a reference voltage set at the AIN3 input from an external source.

I haven't found any sample code but managed to use the driver's API (nrfx_comp.h) to initialize the module.

What I'm facing is the LPCOMP/COMP IRQ handler (nrfx_comp_irq_handler) is not linked into the application, so the COMP IRQ is trapped as a spurious IRQ and handed over to the k_sys_fatal_error_handler() function, which in turn resets the device.

In my prj.conf I've enabled CONFIG_NRFX_COMP=y, so the driver code is enabled, but looking at its code (nrfx_comp.c), the IRQ handler function is surrounded by another optional compilation, see code excerpt below:

#if NRFX_CHECK(NRFX_PRS_ENABLED)
if (nrfx_prs_acquire(NRF_COMP, nrfx_comp_irq_handler) != NRFX_SUCCESS)
{
   err_code = NRFX_ERROR_BUSY;
   NRFX_LOG_WARNING("Function: %s, error code: %s.", __func__, NRFX_LOG_ERROR_STRING_GET(err_code));
   return err_code;
}
#endif

How do I enable the IRQ handler for the LPCOMP/COMP module? My SDK version is nRF5_SDK_17.1.0_ddde560.

BR

Parents
  • After not quite a short swimming-into-the-code and documentation session, I've got to these:

    - COMP and LPCOMP share the same resource ID, 19, which is a mostly useless number. Pdf document "nRF52832 Product Specification v1.8" mentions the PRS module, but provides just too little information and the word "box" which is used in the context of PRS drivers source code, does not show up until you reach the "Ordering Information" section.

    - COMP and LPCOMP are linked to PRS Box # 3. Needed to go to header file nrfx_prs.h and check the #defines there: #define NRFX_PRS_BOX_3_ADDR NRF_COMP.

    - using the Kconfig utility it was not possible to modify the enabled state for any of the PRS boxes, always reverted to disabled during build.

    - After adding the line CONFIG_NRFX_PRS_BOX_3=y to the end of prj.conf, the nrfx_prs_acquire(...) function was enabled, during debug the call to function prs_box_get(...) in nrfx_prs.c (line 116) succeeded, all the initialization process went smoothly, no errors, apparently.

    But I still get the fatal error complaining about a spurious interrupt.

    Is there any other step I must take for installing that missing interrupt handler?

    BR

Reply
  • After not quite a short swimming-into-the-code and documentation session, I've got to these:

    - COMP and LPCOMP share the same resource ID, 19, which is a mostly useless number. Pdf document "nRF52832 Product Specification v1.8" mentions the PRS module, but provides just too little information and the word "box" which is used in the context of PRS drivers source code, does not show up until you reach the "Ordering Information" section.

    - COMP and LPCOMP are linked to PRS Box # 3. Needed to go to header file nrfx_prs.h and check the #defines there: #define NRFX_PRS_BOX_3_ADDR NRF_COMP.

    - using the Kconfig utility it was not possible to modify the enabled state for any of the PRS boxes, always reverted to disabled during build.

    - After adding the line CONFIG_NRFX_PRS_BOX_3=y to the end of prj.conf, the nrfx_prs_acquire(...) function was enabled, during debug the call to function prs_box_get(...) in nrfx_prs.c (line 116) succeeded, all the initialization process went smoothly, no errors, apparently.

    But I still get the fatal error complaining about a spurious interrupt.

    Is there any other step I must take for installing that missing interrupt handler?

    BR

Children
  • Missing bolt here was to install the driver's interrupt handler. This example here (https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/boards/nrf/nrfx_prs) was helpful.

    For just in case it could later be useful for someone trying to do something similar:

    - Created a node in my dts for enabling the comparator: &comp { status = "okay"; };

    - Added an alias, just for convenience: comp = ∁

    - Added the prs driver's include file in my code file: #include <drivers/src/prs/nrfx_prs.h>

    - defined this macro, just for convenience, again: #define COMP_NODE DT_ALIAS(comp).

    - And added following code before completing the comparator's initialization, just to make sure the IRQ was not raised before handlers were installed:

        IRQ_CONNECT(
          DT_IRQN(COMP_NODE),
          DT_IRQ(COMP_NODE, priority),
          nrfx_isr,
          nrfx_prs_box_3_irq_handler,
          0
        );

    BR

Related