john1998
Newbie level 6
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.
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')