Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

How to take inputs faster using Raspberry Pi

Status
Not open for further replies.

John Manuel

New Member
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.

Python:
#!/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')
 
Why are you going via an ADC and then I²C? Can't you read the frequency as a square wave on a single pin?

Mike.
 
Why are you going via an ADC and then I²C? Can't you read the frequency as a square wave on a single pin?
I am trying to make a digital lock-in amplifier, so the input signal which I get will be mostly sinusoidal. Is it possible to detect such signals on a single GPIO pin?
 
I am trying to make a digital lock-in amplifier, so the input signal which I get will be mostly sinusoidal. Is it possible to detect such signals on a single GPIO pin?
Mostly or always? Because if you know it's always going to be a sinusoid than you don't actually need to read it in as a sinusoid. You could strip it down and just read in key features that would let you know the period because you already know it is a sinusoid.. You could clamp it with diodes (behind a resistor so the original signal is not clamped) and the period between rising and/or falling edges. Or use a comparator simiarly.

At 10MHz though it still might not be very accurate with a true GPIO...you'd want an input capture or something like that. Latency is not the Rapsberry Pi's strong suite so interrupts would not be ideal. Definitely not with Python.
 
1) Using the Pi with a Real Time Operating System is something like using Windows on a PC and expecting to get 100% of the CPU. The system will go away for a while and do something on the hard drive.
2) PYTHON is a script and is slow. It is not compiled.
3) A PLL like the CD4046 can convert frequency to voltage in real time. Just read the voltage.
4) A counter like the 74HC4040 will take a frequency link 10mhz and hand you 5m, 2.5m, 1.25m, 626k, etc. Divide the 10mhz down to some frequency that the Pi can count. The 4040 can divide down to 2^12. Also look at CD4020 and 4060. The last one has some buffers on the front end that might help with "analog" to digital.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top