Page 1 of 1

How fast can you trigger an event

Posted: Thu May 11, 2017 4:58 pm
by pndjones
Hi all,

I am fairly new to the raspberry pi micro computer and I am working on a project which I would like to count up to 8000 RPM. Currently I have the program to running however when RPM gets about 5800-6000 I begin to drop signals.
My code:

import time
last_time=0
this_time=0
rpm=0
calc=0

def RPM(channel):
global rpm,this_time, last_time,calc
if GPIO.input(channel) >0.5:
this_time = time.time()
rpm=(1/(this_time-last_time))*60
last_time=this_time
print(rpm)

GPIO.add_event_detect(24,GPIO.RISING,callback=RPM)

My question is am I doing something fundamentally wrong or is is my code inefficient, or is the pi just not able yo keep up at that rate?

Thanks for your help in advance

Re: How fast can you trigger an event

Posted: Thu May 11, 2017 8:10 pm
by JMK8
Maybe you should think about implementing your programme in a compiled language if you are concerned about execution speed, C for example?

Apart from that have you considered that a micro-controller may be more appropriate for your application rather than a general purpose computer like the Raspberry Pi?

-JohnK.

Re: How fast can you trigger an event

Posted: Thu May 11, 2017 8:24 pm
by joan
My pigpio may be better suited to such a usage.

Try http://abyz.co.uk/rpi/pigpio/examples.h ... ead_RPM_py

Re: How fast can you trigger an event

Posted: Thu May 18, 2017 3:17 pm
by pndjones
Thanks for your response it turns out that I was at the limit of my sensor. I purchased a faster one and now the GPIO is picking up 10k+ signals per min. That is beyond what I need for this project however I just wanted to update the community in case this comes up later.