Best way to measure time between falling/rising edges (NCS, Zephyr, NRF52840)

Hello everyone,

is there a safe way to measure the time between rising and falling edges (accuracy +-1µs, duration of the pulses are 50µs or more) on a GPIO(TE) pin? If so, can you please show me?

I am using a custom board with a NRF52840, running NRF Connect SDK and Zephyr RTOS.

I stumbled across other forum entries, of which some are several years old and where I do not know if they are are still valid.

I found another forum entry here:  How to define a direct GPIO IRQ in zephyrbut I am afraid to use gpio interrupts as they might interfere with Zephyrs "under the hood" use of nrfx gpio library.

In another forum entry ( RE: Needed example code of GPIOTE port event on NRF5340 ) you recommend to use zephyr/samples/boards/nrf/nrfx example, but in its README, it says, that Zephyr GPIO driver is disabled. I do not want to disable my Zephyr GPIO driver, as the remaining program is using it.

I am already using a hardware timer (timer3) with nrfx library to set and clear a pin which works.

Kind regards,

Dom

Parents
  • Hi,

     

    is there a safe way to measure the time between rising and falling edges (accuracy +-1µs, duration of the pulses are 50µs or more) on a GPIO(TE) pin? If so, can you please show me?

    Yes, it is possible to do this with:

    * 2 * GPIOTE IN channels (one for rising, one for falling)

    * TIMER CC

    * PPI channels

     

    Since two GPIOTE channels are required here, you should route your signal to two GPIOs.

     

    The algorithm would look something like this:

    * Configure GPIOTE ch #1 as IN low-to-high (ie. rising)

    * Configure GPIOTE ch #2 as IN high-to-low (ie. falling)

    * Setup TIMER in 16M resolution

    * Use PPI to start timer on rising edge

    * Use PPI to capture and stop timer on falling edge

     

    Now you can read the CC register and get the value in 16M units. Remember to clear the nrfx timer instance on each read.

     

    Here's an example of such a setup:

     timed_signals_ncs240.zip

     

    Kind regards,

    Håkon

Reply
  • Hi,

     

    is there a safe way to measure the time between rising and falling edges (accuracy +-1µs, duration of the pulses are 50µs or more) on a GPIO(TE) pin? If so, can you please show me?

    Yes, it is possible to do this with:

    * 2 * GPIOTE IN channels (one for rising, one for falling)

    * TIMER CC

    * PPI channels

     

    Since two GPIOTE channels are required here, you should route your signal to two GPIOs.

     

    The algorithm would look something like this:

    * Configure GPIOTE ch #1 as IN low-to-high (ie. rising)

    * Configure GPIOTE ch #2 as IN high-to-low (ie. falling)

    * Setup TIMER in 16M resolution

    * Use PPI to start timer on rising edge

    * Use PPI to capture and stop timer on falling edge

     

    Now you can read the CC register and get the value in 16M units. Remember to clear the nrfx timer instance on each read.

     

    Here's an example of such a setup:

     timed_signals_ncs240.zip

     

    Kind regards,

    Håkon

Children
Related