I want to use LPCOMP in nrf52832 to detect a rising edge of voltage. And my code is:
static void lpcomp_event_handler(nrf_lpcomp_event_t event)
{
ret_code_t err_code;
if (event == NRF_LPCOMP_EVENT_UP)
{
NRF_LOG_INFO("up!");
}
}
static void lpcomp_init(void)
{
uint32_t err_code;
nrf_drv_lpcomp_config_t config;
config.input =NRF_LPCOMP_INPUT_0;
uint32_t ref = NRF_LPCOMP_INPUT_1;//NRF_LPCOMP_REF_SUPPLY_4_8
config.hal.reference = (nrf_lpcomp_ref_t)ref;
config.hal.detection = LPCOMP_ANADETECT_ANADETECT_Up;
config.hal.hyst = LPCOMP_HYST_HYST_Hyst50mV;
err_code = nrf_drv_lpcomp_init(&config, lpcomp_event_handler);
APP_ERROR_CHECK(err_code);
nrf_drv_lpcomp_enable();
}
I set the reference as NRF_LPCOMP_INPUT_1 or NRF_LPCOMP_REF_SUPPLY_4_8, the event is not triggered only when the input pin is not connected to anything or grounded.
Even if it's connecting a wire or inputting a high level, it will continuously trigger events. It triggered too many rising edge events, this is very confusing for me.
I noticed this: when I use a voltmeter to measure the voltage at the input pin, it's not zero. Should I connect a pull-down resistor or do you have any other suggestions?

