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

Using Comparator as "Window" for potentiometer wake up.

I am trying to use the comparator to wake me up when a potentiometer is moved a certain amount.

Before I sleep I read the ADC value of the comparator and use this to set the upper and lower value of the comparator.

My issue is this only works when I move the POT down.  For some reason the UP direction is not working.

I am including the NRF_DRV_COMP_EVT_EN_UP_MASK in my nrf_drv_comp_start  command.  What else needs to be added to get an event when the voltage crosses the upper threshold?

This is using the nRF52832 , SDK14

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define COMPTH_MAX 63
#define COMPTH_INTERVAL 5
void zoom_comp_init(void)
{
uint32_t err_code;
nrf_saadc_value_t vdd, adcval;
nrf_drv_comp_uninit();
APP_ERROR_CHECK(nrf_drv_saadc_sample_convert(4, &vdd));
APP_ERROR_CHECK(nrf_drv_saadc_sample_convert(0, &adcval));
// hw_adc_disable();
float frac = (float)adcval / (float)vdd;
// ref_setting = frac*16.0;
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
static void comp_event_handler(nrf_comp_event_t event)
{
asm("nop;");
NRF_LOG_INFO("Comp Event.");
switch (event)
{
case NRF_COMP_EVENT_CROSS:
NRF_LOG_INFO("Comp CROSS Event.");
sysEvents.zoom_change = 1;
break;
case NRF_COMP_EVENT_DOWN:
// sysEvents.zoom_change = 1;
//if (update_zoom())
{
NRF_LOG_INFO("Comp DOWN Event.");
sysEvents.zoom_change = 1;
}
break;
case NRF_COMP_EVENT_UP:
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX