0

Count duration a GPIO is high (or low) ?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Count duration a GPIO is high (or low) ?

by ichrysomallis on Fri Mar 22, 2019 8:51 am

Hello,

I'm using a Beaglebone black micro-controller with ROS (melodic, code in rospy) and Adafruit_BBIO library installed. Is there any way to receive the exact duration is ns/us/secs a GPIO is high? Currently, I want this feature so I can accurately convert a signal beaglebone receives from a sonar sensor, into distance.

Thanks in advance,

Jason C.

ichrysomallis
 
Posts: 1
Joined: Fri Mar 22, 2019 8:50 am

Re: Count duration a GPIO is high (or low) ?

by drewfustini on Sat Mar 23, 2019 8:35 pm

You could create some logic using GPIO.input(PIN) and timestamps to calculate the amount of time the pin was high. This might work if you are interested in millisecond resolution but I'm not sure how precise it will be.

The BeagleBone's TI AM3358 processor does have a peripheral for measuring input pulses called eCAP. The Adafruit_BBIO library does not support this due to there being no upstream Linux kernel driver for it. However, there a library called libpruio which supports eCAP. It targets the PRU (Programmable Real-Time Units) in the AM3358 processor:
http://users.freebasic-portal.de/tjf/Pr ... p_8py.html

drewfustini
 
Posts: 920
Joined: Sat Dec 26, 2015 1:19 pm

Please be positive and constructive with your questions and comments.