How to take inputs faster using Raspberry Pi

Thread Starter

John Manuel

Joined Jun 6, 2018
17
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.

Code:
#!/usr/bin/python
# -*- 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 = [ ]

try:
    while True:
        bus.write_byte(address,A0)
        value = bus.read_byte(address)
        voltage_value.append(value)
        time_value.append(time.time()-start)
        #print("AOUT:%1.3f  " %(value*3.3/255))
        #print(value)
        #time.sleep(0.1)
except KeyboardInterrupt:
    voltage_value = [x*3.3/255 for x in voltage_value]
    plt.plot(time_value,voltage_value)
    plt.ylabel('Voltage')
    plt.xlabel('Time')
    plt.show()

    with open('output.txt', 'w') as f:
        for v,t in zip(voltage_value,time_value):
            f.write(str(v)+' '+str(t)+'\n')
 

danadak

Joined Mar 10, 2018
4,057
10 Mhz one thinks of DMA approach into a buffer, then buffer
is processed after filling. Especially if you have other tasks to
perform and interrupts to process.

What do you want to do with a 10 Mhz sample data set ?

Regards, Dana.
 

nsaspook

Joined Aug 27, 2009
16,322
You won't be able to use the Pi to directly sample that fast. I've tested the limits on the four core model. I created a 'special' device for a protocol driver to test how the RPi3 4 core cpu handles fast (64MHz) serial transfers. The hardware memory transfer limits of the SOC will prevent 10Mhz sampling even at close to bare metal.
https://forum.allaboutcircuits.com/threads/fifo-logic-block-meta-stability.136284/#post-1143241
https://www.edn.com/design/test-and...lock-in-amplifier--Part-2--Design-methodology
 
Last edited:

Thread Starter

John Manuel

Joined Jun 6, 2018
17
You won't be able to use the Pi to directly sample that fast. I've tested the limits on the four core model. I created a 'special' device for a protocol driver to test how the RPi3 4 core cpu handles fast (64MHz) serial transfers. The hardware memory transfer limits of the SOC will prevent 10Mhz sampling even at close to bare metal.
https://forum.allaboutcircuits.com/threads/fifo-logic-block-meta-stability.136284/#post-1143241
https://www.edn.com/design/test-and...lock-in-amplifier--Part-2--Design-methodology
I am a total noob. So sorry for asking, but is there no way to increase the frequency range that I could detect with Raspberry Pi? Will adding any components like a FIFO buffer help? If not is there any other way by which Digital Lock in Amplification can be done for higher frequency range?
 

Thread Starter

John Manuel

Joined Jun 6, 2018
17
Thank you very much Dana! I have gone through the reference materials and many more. I am new to this field, hence most of it goes above my head.

Is my approach correct to make a digital lock-in amplifier using raspberry pi? I did not find any resource online which uses Rpi for digital LIA whereas I saw a few that uses Arduino. I am a bit concerned.
 

nsaspook

Joined Aug 27, 2009
16,322
I am a total noob. So sorry for asking, but is there no way to increase the frequency range that I could detect with Raspberry Pi? Will adding any components like a FIFO buffer help? If not is there any other way by which Digital Lock in Amplification can be done for higher frequency range?
The main bottleneck is raw hardware bandwidth limit to realtime I/O processing. Add a external FIFO won't improve processing speed even at the cost of increased latency of data acquisition.
 

nsaspook

Joined Aug 27, 2009
16,322
Thank you very much Dana! I have gone through the reference materials and many more. I am new to this field, hence most of it goes above my head.

Is my approach correct to make a digital lock-in amplifier using raspberry pi? I did not find any resource online which uses Rpi for digital LIA whereas I saw a few that uses Arduino. I am a bit concerned.
The problems are speed and timing, it will work (with optimized drivers and software), just not at 10MHz.
 

Thread Starter

John Manuel

Joined Jun 6, 2018
17
The problems are speed and timing, it will work (with optimized drivers and software), just not at 10MHz.
Forgive me for being so abrupt but can you please provide some guidance on how to optimize the drivers and software?

Also, say if I want a digital lock-in amplifier working at 10MHz. What should I use? Will a DSP work?
 

danadak

Joined Mar 10, 2018
4,057
Combination of DSP and FPGA.

Look online at some units that meet 10 Mhz or greater, download their
manuals, and read the theory of operation section as to how they did it.

Regards, Dana.
 

nsaspook

Joined Aug 27, 2009
16,322
Forgive me for being so abrupt but can you please provide some guidance on how to optimize the drivers and software?

Also, say if I want a digital lock-in amplifier working at 10MHz. What should I use? Will a DSP work?
The PI running Linux is not a real-time (even high priority routines can be interrupted or delayed) processing system. You can attempt to work within the confines of the OS to make things better with drivers and kernel level software (a complex subject for simple guidance) but it's not a good system for a pure DSP functionality.
 
Top