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 

  • Vkadal

    Ok I know I have to use NRF_TIMER1 (for example) but I do not see a complete example of how to set this up and use it. I want a simple example that just shows me how to start it, stop it, and read the values. I do not need interrupts. I just need something very simple. I am very confused with the examples you have pointed me to. The GPIO is generating the interrupt so I just want be able to read the timer value in the interrupt handler.

    something as simple as the following:

    init timer

    clear timer

    start timer

    delay x ms or us

    read timer

Reply
  • Vkadal

    Ok I know I have to use NRF_TIMER1 (for example) but I do not see a complete example of how to set this up and use it. I want a simple example that just shows me how to start it, stop it, and read the values. I do not need interrupts. I just need something very simple. I am very confused with the examples you have pointed me to. The GPIO is generating the interrupt so I just want be able to read the timer value in the interrupt handler.

    something as simple as the following:

    init timer

    clear timer

    start timer

    delay x ms or us

    read timer

Children
Related