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

Pin interrupt polarity timing issue

I am using the GPIOTE driver to attach interrupts to a pin in a very timing critical environment (using sensors like this).

To me, it seems like there is quite the significant delay between the signal on the pin and the handler function call.

The interrupt listens for TOGGLE, so both directions should trigger.

Sometimes though, although HITOLO triggers the interrupt, by the time the interrupt vector is called, the sensor already reports HI.

Sadly, the nrf_gpiote_polarity_t only reports NRF_GPIOTE_POLARITY_TOGGLE, not the actual direction of the signal.

Now the question:

Is there any way to get the interrupt direction in an interrupt handler handling TOGGLE interrupts without reading the pin additionally?

Can i somehow hack the driver to report HITOLO/LOTOHI to the handler function with a TOGGLE interrupt instead of NRF_GPIOTE_POLARITY_TOGGLE?

Parents
  • Hi Daniel,

    do you use hi-accuracy mode for gpiote?

    The nrfx_gpiote driver is not optimized for very time-critical tasks, you can look at nrfx_gpiote_irq_handler in nrfx_gpiote.c to see the size of code it runs when interrupt is detected. Using gpiote peripheral directly (without nrfx layer), you can write much shorter code that only checks signal level on a single pin and clears interrupt status. Another thing - when BLE stack is enabled, you cannot ensure time constraints because softdevice interrupts always have higher priority, and if an input signal changes multiple times while gpiote interrupt is blocked, you'll receive only one event.

    If you need very precise timings, the best way is to pass an event to a timer or rtc via PPI to capture an exact timestamp by hardware.

  • I am not too worried about timing, I can live with a few milliseconds of delay.

    I am worried about the useless polaritiy passed to my interrupt handler.

    Is there any way to get the precise direction with a TOGGLE-interrupt handler?

  • With millisecond resolution, you can use low-accuracy mode. In this mode, toggle is emulated by library - it changes sense level every time an event is coming, and you'll get exactly the value that pin has at the time of an event.

Reply Children
Related