rtarb41323
Posts: 6
Joined: Sun Apr 05, 2015 5:21 am

GPIO and Interrupt speed

Sun Apr 05, 2015 5:32 am

Hi all!

I'm using an r-pi2 with python to read an analog-digital converter. Right now, the r-pi2 receives the "ready" signal from the ADC at a rate of 10Hz (I'm using GPIO-4 as the input pin), but in my interrupt function (associated with the rising edge on GPIO-4) is only activating about once a second.

Does anyone know the speed of the rpi2 and interrupt processing? It seems like I should be able to process interrupts a lot faster than I'm seeing.

Code: Select all

import RPi.GPIO as GPIO
import spidev
import time

import numpy as np
import math

GPIO.setmode(GPIO.BCM)

################################################
#Define our constants and global variables here:

interrupts_rec = 0
inter_func_counter = 0

#Since this is an interrupt function, it MUST take an arguement in
#called "channel":
def busy_to_ready(channel):
        global interrupts_rec
        global inter_func_counter
        GPIO.output(17, not GPIO.input(17))
        interrupts_rec += 1
        inter_func_counter += 1
        print "interrupts received: ", interrupts_rec
        print "interrupt function call: ", inter_func_counter



#GPIO4 = input = !BUSY
#GPIO24 = output = !RD
#GPIO25 = output = !START_CONVERSION
#GPIO17 = debug pin
_RD = 24
_start_conv = 25
GPIO.setup(4, GPIO.IN, pull_up_down = GPIO.PUD_UP)
GPIO.setup(_RD, GPIO.OUT)
GPIO.setup(17, GPIO.OUT)


#Initial output pin states:
GPIO.output(_RD, GPIO.HIGH)
GPIO.output(17, GPIO.HIGH)
#Attach interrupt to "ready - _busy" pin (which is pin 4):
GPIO.add_event_detect(4, GPIO.RISING, callback=busy_to_ready)

while True:   #Infinite program loop
        nop = 1


pretoriano
Posts: 3
Joined: Tue Jan 12, 2016 4:03 pm

Re: GPIO and Interrupt speed

Wed Mar 16, 2016 4:09 pm

Wow no answer for almost a year.
I am looking for an answer too. Did yo figure it out?

User avatar
mikronauts
Posts: 2709
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: GPIO and Interrupt speed

Wed Mar 16, 2016 4:26 pm

- 10Hz is not fast
- use pigpio for the interrupts

If you need > ~5000 samples per second, use C
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

User avatar
croston
Posts: 701
Joined: Sat Nov 26, 2011 12:33 pm
Location: Blackpool
Contact: Website

Re: GPIO and Interrupt speed

Thu Mar 17, 2016 7:02 am

Your infinite loop is using up all the CPU and that is why your code is running slowly.

Replace:

Code: Select all

while True:   #Infinite program loop
    nop = 1
with:

Code: Select all

while True:
    time.sleep(1)

Return to “Python”