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
  • You need to use timer for this purpose. You shall use GPIO pin which can create an interrupt. Create an interrupt when the pulse changes high low and start the counter. Stop the counter when the pulse goes  low. This will give you the pulse width

    Similarly to measure period, start the counter when the pusle goes from high to low and stop it in the next hight to low

    This is standard procedure for any  micro 

  • nRF 9160 operates at 64MHz, Then the resolution of one clock / tick is around 16 nS. So you shall be able to measure the same. Look for some prescalar or post scalar setting of the timer you are using.  You should be able to measure to the level of accuracy you are looking for. 

  • Vkadal

    I am using the nRF9160 internal built in timers that count at SYS_CLOCK_TICKS_PER_SEC (32768). I can change that to higher but that is the system clock and there is a big pop up screen that says there are severe limits on what values you can put there. they show millisecond resolution. I belive this value is used by many other things and it will change the system timing everywhere.

Reply
  • Vkadal

    I am using the nRF9160 internal built in timers that count at SYS_CLOCK_TICKS_PER_SEC (32768). I can change that to higher but that is the system clock and there is a big pop up screen that says there are severe limits on what values you can put there. they show millisecond resolution. I belive this value is used by many other things and it will change the system timing everywhere.

Children
Related