Nrfx timer capturing/comparing

Hi, 

I'm aiming to develop a custom two-wire serial interface (TX, RX). To achieve this, I'm planning to implement output capture for TX and use GPIO interrupts for RX. For the RX side, I'll need to read a microsecond timer to measure the time duration of each signal level.

Here’s what I've implemented so far:

 

These few lines of code should generate a wave on the TX pin and read the same wave on the RX pin. The wave generation works correctly (verified with an oscilloscope), but the microsecond values that are read in the GPIO interrupt are incorrect. The difference between consecutive samples in the microsecond readings should equal the time of the signal level, but they don't.

Here’s what the logs show:

  • Hi!

    I implemented a "pulse detector" some years ago, it measures the time, and gives the frequency of the input signal. Maybe that can be useful in what you are trying to do: https://github.com/sigurdnev/ncs-playground/blob/master/samples/pulse_detector/src/main.c

  • You did this for a very old version of nrfx. One thing I forgot to mention is that I have it working with nRF Connect SDK 1.8, but I'm encountering problems while trying to migrate to the newest version. Previously I was using input capture to measure input pulse, this one I decided to start with something more simple.

    Major question is: Why I read so bad values from channel 1 if it is not used to nothing more, and it looks like is reseted when channel 2 is captured...

  • trafficode said:
    One thing I forgot to mention is that I have it working with nRF Connect SDK 1.8, but I'm encountering problems while trying to migrate to the newest version.

    You are testing with NCS 2.7.0 ?

  • trafficode said:
    Major question is: Why I read so bad values from channel 1 if it is not used to nothing more, and it looks like is reseted when channel 2 is captured...

    Looking at the code, you have e.g. this line:

    nrfx_timer_extended_compare(&TimerInst, NRF_TIMER_CC_CHANNEL2, cc + us,
    NRF_TIMER_SHORT_COMPARE2_CLEAR_MASK, true);

    So you have a shortcut between the compare event on the channel and the timer CLEAR task