This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM335x - Input capture mode

Hello,

I work with the AM335x based Beaglebone as well as another AM335x based board. Both use Linux as the OS (e.g. ubuntu on the Beaglebone).

I am currently working on capturing an input signal and to measure the pulse width of its several pulsesI want to calculate the width of the pulse in  microseconds, because I have to calculate a bitrate out of it (non-standard baudrates, so an approximation of a not well measured pulse does not work). The speed is >10kBaud, which results in worst case pulses of approx. 8-100us. Right now I read the signal on a GPIO pin (the UART2 pin, configured as GPIO when in measuring mode).

My first approach was to poll the GPIO pin and whenever I determine a signal change this means an edge. I take the timestamp at all edges and used already different methods to obtain a timestamp, but none of them worked well:

#1: utilize clock_gettime() (with the individual timers possible)

Get a timestamp when an edge occurs and when all expected edges are collected calculate the time in between the edges. All calculations are done afterwards to avoid additional run-time.

Result: Does not work, because the resolution of any used timer is always 30.517 microseconds = 1/32768Hz, even that the reportes resolution is 1ns (but this seems only to reflect the resolution of the timer variable). Therefore the granularity is not good enough to calculate the pulse width.

#2: use the CPU timestamp

This utilizes the same logic as for #2, but counts the CPU ticks instead of the time. THis requires enabling the timestamp in the Cortex A8. Prior to collecting the ticks of the pulse I determined how many ticks are used for 1 microsecond by running a calibration loop where I counted the ticks for 1 second several times in a row and calculated the ticks_us based on this.

Result: Does also not work, because of CPU frequency adjustments, function calls (during calibration and when timing is measured) and OS activities the counted ticks can vary.

Now I thought to use a dedicated input capture functionality of the AM335 (as known from old micros) where the value of a free running timer is stored whenever a configured edge occurs on an input. Usually also an interrupt is generated.

I have not found solutions/application notes/handlings in the www so far and I appreciate any input! The questions I have are:

  • How can one perform an input capture on the AM335x where any edge on a dedicated input causes to capture a free running timer value (e.g. real ns-Resolution) and may also generate an interrupt?
  • If possible, can this be handled in user space or must it be done on kernel space? For both: How?
  • Is there e.g. an application note for "input capturing" available which shows methods on how to measure incoming signals timing wise and provides detailed hints for the implementation?

I can imagine that this kind of measurement can be found in different applications/areas as well and that there are solutions available which could help to do the implementation. Thanks a lot in advance for your feedback on this!

Regards,

Thomas