Hello, can you please provide more information and instructions on how we configure the input capture on nrf52840 dev board using zephyr? All sample examples only cover pwm output. I have a square signal that I would like to capture the time associated with its rising and falling edges. According to the zephyr PWM driver documentation, I could do this by configuring the capture feature using the following function:
static inline int pwm_pin_configure_capture(const struct device *dev, uint32_t pwm, pwm_flags_t flags, pwm_capture_callback_handler_t cb, void * user_data)
In the function, I would use PWM_CAPTURE_TYPE_BOTH and PWM_CAPTURE_MODE_CONTINUOUS flags. However, it is not clear to me how do I configure which pin is the capture pin. I am assuming I need to create a DTS overlay file but not sure about the content. Thank you.
Hi,
The PWM port for nrf devices does not have capture capabilities:
https://github.com/nrfconnect/sdk-zephyr/blob/master/drivers/pwm/pwm_nrfx.c#L263-L266
Thus it will return an error code if you try to…
Thus it will return an error code if you try to call _capture() call:
https://github.com/nrfconnect/sdk-zephyr/blob/master/include/drivers/pwm.h#L221
The functionality you are after must be implemented using a TIMER, GPIOTE IN, and PPI, something like this one for nrf53/nrf91 (note: uses dppi, while the nrf52-series have ppi):
https://github.com/Rallare/fw-nrfconnect-nrf/blob/nrf9160_samples/samples/nrf9160/nrfx_timed_signal/src/main.c
Kind regards,
Håkon
Thank you for the info. Any plans to enable the input capture feature of the zephyr PWM driver?
Meanwhile, we have created the code to capture the time associated with input signal transitions referencing the nrfx example you shared. We got it working, but it is not exactly what we want. We need to capture the time of both the rising and falling edges of the same input signal. It looks like we can only generate one event per GPIO pin. The event can be either HItoLO, LOtoHI, or TOGGLE. The toggle event would have worked except when we route it through a PPI channel to a timer capture register; either transition will update the capture register. Any idea on how to do this? Thx!
moose said:Any plans to enable the input capture feature of the zephyr PWM driver?
There's no natural way of implementing this into the driver, without depending on other drivers and external setup.
moose said:The event can be either HItoLO, LOtoHI, or TOGGLE. The toggle event would have worked except when we route it through a PPI channel to a timer capture register; either transition will update the capture register. Any idea on how to do this? Thx!
Connect the signal to two GPIOs, one that is configured hitolow, and the second that is configured lotohi.