Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Using timer to count pulse width on interrupt pin

Hi! I'm trying to use a counter to count the pulse widths of an IR signal packet everytime it tirggers an event on a GPIO, however I've been going in loops without sucess. 

Here is my current code:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void timer_handler(nrf_timer_event_t event_type, void * p_context)
{
switch (event_type)
{
case NRF_TIMER_EVENT_COMPARE0:
if (timer_started){
timer_started = false;
NRF_TIMER0->TASKS_CAPTURE[0] = 1;
pulse_duration = NRF_TIMER0->CC[0];
//pulse_duration = nrf_timer_cc_read(m_timer.p_reg, NRF_TIMER_CC_CHANNEL0);
NRF_LOG_INFO("PULSE DURATION: %u", pulse_duration);
}
break;
default:
//Do nothing.
break;
}
}
void gpiote_handler(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

I've used both methods to count pulse_duration incluing the one currently commented, in the current case I always get 0, in the commented one I get a value "16777215" which seems to be an overflowing 24 bit timer, however mine is 16bit not 24. What am I doing wrong here, can someone help?

Thanks in advance.