pndjones
Posts: 7
Joined: Thu May 11, 2017 4:29 pm

How fast can you trigger an event

Thu May 11, 2017 4:58 pm

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

JMK8
Posts: 42
Joined: Tue Apr 28, 2015 10:00 am

Re: How fast can you trigger an event

Thu May 11, 2017 8:10 pm

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.

User avatar
joan
Posts: 14887
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: How fast can you trigger an event

Thu May 11, 2017 8:24 pm

My pigpio may be better suited to such a usage.

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

pndjones
Posts: 7
Joined: Thu May 11, 2017 4:29 pm

Re: How fast can you trigger an event

Thu May 18, 2017 3:17 pm

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.

Return to “General discussion”