Using eCap feature in Python

I would like to use the eCap feature to measure the frequency of a square wave, preferably with Python. I see examples for generating a square wave using the BBIO.PWM module but I can’t find anything for reading the eCap. The BBIO.Encoder module looks promising. Can I use this to measure the frequency of a single square wave or do I need a quadrature encoder? Thanks.

On Fri, 15 Dec 2017 09:05:30 -0800 (PST),
thomaslolson63@gmail.com declaimed the
following:

I would like to use the eCap feature to measure the frequency of a square
wave, preferably with Python. I see examples for generating a square wave
using the BBIO.PWM module but I can't find anything for reading the eCap.
The BBIO.Encoder module looks promising. Can I use this to measure the
frequency of a single square wave or do I need a quadrature encoder?
Thanks.

  Which "BBIO"? PyBBIO or Adafruit_BBIO?

  Based upon the documentation for the latter -- it is not a "frequency"
measurement but a counter (up/down) based upon the transitions of a
quadrature signal (ie; TWO square waves 90 deg out of phase). PyBBIO docs
look to be similar.

  A quick Google seems to lean towards either kernel module with
interrupts on GPIO pins, or using the PRU for a tight-loop counter, if
accuracy is needed.

  If some irregularity is acceptable, user-mode GPIO loop may be okay --
though probably by memory mapping the GPIO pins rather than using the sys
filesystem access. And both of these will likely not be fast enough if
using interpreted Python.

  Unfortunately, the PWM modules in the Python libraries are designed
solely for PWM output -- even though the eCAP hardware is part of the PWM
hardware. cf: TRM SPRUH73P section 15.3.3.1

/dev/ entry for ecap pwmss in Am335x beagle bone black - Processors forum - Processors - TI E2E support forums seems to imply the
eCAP could be accessible via the sys filesystem (but may need some work).
That could make the latency issue moot, if you can trigger a one-shot
capture (for four time-stamps?) and then read the time-stamps later to
compute frequency. OTOH,
https://e2e.ti.com/support/arm/sitara_arm/f/791/p/393325/1388948 implies
the kernel doesn't support eCAP...

We do have an iio ecap driver (IIO_TIECAP) in the v4.4.x-ti branch,
originally written-by Matt Porter, but it never made it to mainline:

https://github.com/RobertCNelson/ti-linux-kernel-dev/tree/ti-linux-4.4.y/patches/drivers/ti/iio

It needs to be re-ported to v4.9.x/v4.14.x, one of the GSOC users was
working on it last summer i believe..

Regards,

Using C code and the inotify interface, I was able to capture GPIO pulses on “/sys/devices/platform/ocp/44e07000.gpio/gpio/gpio26/value” up to 20kHz. It would be nice to use the eCAP registers though. Thanks for the feedback.