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

using PWM to measure input period and pulse width

I have an input signal of unknown period and pulse width on a GPIO. I want to use the PWM capture capabilities to  retrieve those parameters.

I see in the documentation there is

pwm_pin_configure_capture, pwm_pin_enable_capture, pwm_pin_disable_capture, pwm_pin_capture_usec, pwm_capture_callback_handler

I did not see an example how to use these. could you show me a simple example of what I need to do to  get the period and pulse width from an input signal using a PWM. The functions seem to be exactly what I need but the implementation is not clear in the documentation and I am getting a lot of compile errors. I am sure it is something simple I am missing. I appreciate any help you can give.

Parents Reply Children
  • Vkadal

    I need to measure pulse width and periods in the microsecond range.(20 - 400 us pulse width). I do not see a way to get the nRF9160 timers to count that fast with interrupts and the latency involved. I do not see a way to send an external clock into the nRf9160 timers. they need to be started with a given expire time. using the timers I can measure pulse width in the order of ~10ms. I set a timer expiration time of 1000ms and start the timer on the leading edge interrupt and stop the timer on the falling edge interrupt. I get the remaining ticks and subtract it from  (1000 * ticks/sec) this gives me the pulse width. this fails as I get below 10 ms.

    How can I get microsecond resolution?

Related