This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

LPCOMP Reference voltage switching

Hi Team,

      regarding my application I need to switch the reference voltage we are taking two deferent reference voltage Ex: one for 2.25 and another 0.75 so we have requirement if the voltage is crossing the 2.25 reference it will trigger the call back after trigger we need to change the reference to 0.75 once it changes the reference we want to get the down event again it should be repeat periodically.

1) can we able to do switching reference value?

2) is it supported to switching any other methods? 

  

static void lpcomp_init(void)
{

config.hal.reference = 5;
config.hal.detection = 1;
config.input = NRF_LPCOMP_INPUT_7;
// initialize LPCOMP driver, from this point LPCOMP will be active and provided
// event handler will be executed when defined action is detected

err_code = nrfx_lpcomp_init(&config, lpcomp_event_handler);

APP_ERROR_CHECK(err_code);
nrfx_lpcomp_enable();

}

Its rising one time after that not calling callback,

static void lpcomp_event_handler(nrf_lpcomp_event_t event)
{

//nrfx_lpcomp_uninit();
if (event == NRF_LPCOMP_EVENT_DOWN)
{
nrf_delay_ms(1000);
config.hal.reference = 3;
config.hal.detection = 2;
err_code = nrf_drv_lpcomp_init(&config, lpcomp_event_handler);
nrfx_lpcomp_enable();
//nrfx_lpcomp_uninit();
//nrfx_lpcomp_disable();
if(1)
{
printf(" Down Intruder detected\n");
}
}
else if (event == NRF_LPCOMP_EVENT_UP)
{
//nrfx_lpcomp_disable();
nrf_delay_ms(1000);
config.hal.reference = 1;
config.hal.detection = 1;
err_code = nrf_drv_lpcomp_init(&config, NULL);
nrfx_lpcomp_enable();
//nrfx_lpcomp_uninit();
//nrfx_lpcomp_disable();
printf("%d\n",config.hal.reference);
if(1)
{
printf(" Up Intruder detected\n");
}
}
else if (event == NRF_LPCOMP_EVENT_CROSS)
{

if((config.hal.reference == 1)||(config.hal.reference == 5))
{
printf(" crossing Intruder detected\n");
}

}
//nrfx_lpcomp_uninit();

}

}

Related