Hello,
I am trying to configure COMP peripheral on my NRF54L15 DK.
I am using P1.11 pin (AIN4) as single ended input for this purpose. For now I am trying only to evaluate this peripheral so I connected a potentiometer to this pin. Other two potentiometer terminals are connected to GND and VDDIO - so I am able to set a voltage in range 0.0V - 1.8V on P1.11.
I managed to get the COMP working using default configuration (that means down threshold = 0.5V and up threshold = 1.0V). It triggers nicely when going UP. However when going down I always get both NRF_COMP_EVENT_DOWN and NRF_COMP_EVENT_UP.
Below is all my code from main.c
/*
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
*/
#include <zephyr/kernel.h>
#include <zephyr/sys/printk.h>
#include <nrfx_comp.h>
#define NRF_COMP_INPUT_AIN4 NRF_PIN_PORT_TO_PIN_NUMBER(11U, 1)
#define COMP_INPUT_PIN NRF_COMP_INPUT_AIN4
static nrfx_comp_config_t comp_config = NRFX_COMP_DEFAULT_CONFIG(COMP_INPUT_PIN);
static void comparator_handler(nrf_comp_event_t event);
static nrfx_comp_event_handler_t comp_event_config = comparator_handler;
void comparator_handler(nrf_comp_event_t event)
{
switch (event)
{
case NRF_COMP_EVENT_READY:
printk("NRF_COMP_EVENT_READY\n");
break;
case NRF_COMP_EVENT_UP:
printk("NRF_COMP_EVENT_UP\n");
break;
case NRF_COMP_EVENT_DOWN:
printk("NRF_COMP_EVENT_DOWN\n");
break;
case NRF_COMP_EVENT_CROSS:
printk("NRF_COMP_EVENT_CROSS\n");
break;
default:
break;
}
}
static void configure_comp(void)
{
//INTERRUPT
IRQ_CONNECT(DT_IRQN(DT_NODELABEL(comp)),
DT_IRQ(DT_NODELABEL(comp), priority),
nrfx_isr, nrfx_comp_irq_handler, 0);
// initialize comp driver
nrfx_err_t err = nrfx_comp_init(&comp_config, comp_event_config);
if (err != NRFX_SUCCESS)
{
printk("Error COMP init: %08x", err);
return;
}
nrfx_comp_start(NRFX_COMP_EVT_EN_CROSS_MASK |
NRFX_COMP_EVT_EN_UP_MASK |
NRFX_COMP_EVT_EN_DOWN_MASK |
NRFX_COMP_EVT_EN_READY_MASK, 0);
}
int main(void)
{
configure_comp();
k_sleep(K_FOREVER);
return 0;
}
And below is the output from serial terminal I get when I rotate my potentiometer. I added my comments to elaborate that every time there is proper DOWN event there is also false UP triggered.
*** Using Zephyr OS v4.0.99-77f865b8f8d0 *** NRF_COMP_EVENT_READY NRF_COMP_EVENT_UP // proper UP event NRF_COMP_EVENT_CROSS // proper CROSS event NRF_COMP_EVENT_DOWN // DOWN event NRF_COMP_EVENT_UP // false UP event generated - i don't know why NRF_COMP_EVENT_CROSS // proper CROSS event NRF_COMP_EVENT_UP // proper UP event NRF_COMP_EVENT_CROSS // proper CROSS event NRF_COMP_EVENT_DOWN // proper DOWN event NRF_COMP_EVENT_UP // again: false UP NRF_COMP_EVENT_CROSS // proper CROSS event
What I tried:
- change speed of the COMP to the slowest
- change voltage reference of the COMP to VDD
- change threshold voltages to 0.9 down and 1.0 up
- add 40mV hysteresis (besides the different up and down thresholds)
I thought that maybe there is some signal integrity problems. I measured the voltage on P1.11 during the experiment using my saleae pro with 5MHz BW. It shows little to no noise at all (i don't have any better equipment). Anyway if that would be the case then i think i would be getting also false DOWN events and the effect would be more random... So at this moment I think there is some code bug.
If anyone needs any additional information I will give it to You.
If anyone would try to test my code on DK please mind that You also need to add dts overlay to Your project:
&comp {
compatible = "nordic,nrf-comp";
status = "okay";
};