I have been working with Raspberry pi 4 to acquire analog signals. I get AD/DA High Precision Board by Waveshare (ADS1256 A/D) to convert analog input and I downloaded python source code from Waveshare to read samples from ADC. The board communicates with Raspberry through SPI. I tried to make a test: I acquired the equivalent in samples of 10s of signal and measured time elapsed reading those samples. I used time.time(). I repeated the test setting different sampling frequencies but I found out that increasing sampling rates resulted in increasing error and delay: at 100 Hz I got 10.34s instead of 10s, at 1000Hz I got 13.20s instead of 10s, at 15kHz I got 57.74s instead of 10s. SPI max speed has been set to 2MHz. Why there's such a delay? Here's the code:
import time
import timeit
import ADS1256
import RPi.GPIO as GPIO
try:
ADC = ADS1256.ADS1256()
ADC.ADS1256_init()
fs = 5 #here I set the value of sampling frequency which has been previously changed in module ADS1256.py
value = 0
start = time.time()
for i in range(10*fs): #cycle of 10s that only reads
value=ADC.ADS1256_GetAll() * 5.0 / 0x7fffff
end = time.time()
print('time',end-start)
except:
GPIO.cleanup()
print("\r\nProgram end ")
exit()