Connect with us

How to take inputs faster using Raspberry Pi

Discussion in 'Microcontrollers, Programming and IoT' started by John Manuel, Jul 4, 2018.

Scroll to continue with content
  1. John Manuel

    John Manuel

    Jun 7, 2018
    I am trying to detect different frequency signals using a Raspberry Pi and an ADC converter (PCF8591). My initial guess was the highest frequency I could detect would be limited by the speed of the I2C bus (which is about 400000 bauds). But when I run the setup, I could only get sampling speeds of around 10000 samples/sec. This value lies very close to the time taken to run an empty for loop in python (which is about 10^(-5) seconds which is equivalent to 10^(5) samples/sec).

    I wanted to reach higher frequency domain (around 10 MHz) and using a better ADC won't be of much help since the limitation is set by the program itself. I wanted to know if my conclusion is correct or not. I have a feeling I am very wrong and doing something stupid. Any guidance will be much appreciated. Below is the python code I am using for signal detection.

    # -*- coding:utf-8 -*-
    import smbus
    import time
    import matplotlib.pyplot as plt
    start = time.time()
    address = 0x48
    A0 = 0x40
    A1 = 0x41
    A2 = 0x42
    A3 = 0x43
    bus = smbus.SMBus(1)
    bus.write_byte_data(address,0,0b00010000)#control byte to tell ADC to act as a differential input
    voltage_value = [ ]
    time_value = [ ]
        while True:
            value = bus.read_byte(address)
            #print("AOUT:%1.3f  " %(value*3.3/255))
    except KeyboardInterrupt:
        voltage_value = [x*3.3/255 for x in voltage_value]
        with open('output.txt', 'w') as f:
            for v,t in zip(voltage_value,time_value):
                f.write(str(v)+' '+str(t)+'\n')
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    Nov 17, 2011
    Python code is interpreted and much too slow to detect a 10 MHz signal. You'l also have to take into account that the Raspi runs Linux which is not a real time operating system and as such not suitable for such measurements. The 10000 samples/s are probably as much as you can get. Using C instead of Python you may crank a few more samples out of the Raspi, but not 10 MHz.
    To measure in that range you'll need additional circuitry. Try "frequency measurement raspberry" in your favorite search engine for some suggestions.
    hevans1944 and John Manuel like this.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day