Skip to content
Advertisement

How to read the external timer counter on the BeagleBone Black?

I need to count the transitions of a 50KHz binary signal using a BBB. I think using the TIMER4 triggered by the external signal connected to the pin P8.07 would be the easiest way.

So, I issued the following commands to load the proper cape and setup the pin as a timer :

./config-pin overlay cape-universaln
./config-pin P8.07 timer

Everything seems to work and nothing appears in dmesg.

My question is : How can I read the value of TIMER4 ? I looked in SysFs and find nothing interesting. Nothing in /dev as well. How can I retrieve the value of the timer counter I just setup ? I’m open to a C/C++ solution as well, but I would like to avoid doing kernel-space programming.

I’m using the latest Ubuntu Linux for BeagleBone, kernel 4.1.10-ti-r21.

Advertisement

Answer

With a little googling I see a pps driver for the AM335x DMTimer subsystem here: https://github.com/ddrown/pps-gmtimer

It looks like it hasn’t been merged upstream and the README gives instructions on building it into the 3.8 kernel – you could revert back to 3.8, or you could adapt that for 4.1, in which case you may need to tweak the Device Tree overlay as well for the newer version of the dtc compiler that’s in 4.1.

You could also write a pulse counter firmware for the PRU (with only a 50KHz input it wouldn’t need to be very optimized at all to catch every pulse). You could send a signal to the ARM every so often and catch that in your userspace program.

Another option would be to directly access the DMTimer registers from userspace using mmap to map the /dev/mem file (example of this method for GPIO here), but that’s a pretty “hacky” way to do it, and it’s generally frowned upon in the GNU/Linux world to do that sort of stuff from userspace instead of from kernal space.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement