About Us Knowledge Base Community Forum Electronics Toolbox FAQ Shipping & Delivery

Community Forum

Share your projects and post your questions

Search
Register or Sign In
Forum

max sampling rate

750 Views - Created 24/09/2018

24/09/2018

Posted by:
mallok05

Users Avatar

Hi, I wanted to know, if there´s some experience and maybe examples of evaluating the possible speed to get out of the MCP3208 with python.

I´m totally aware about pythons overhead but it´s required for my project. As I saw for the ADC DAC board it states that with python 12ksps would be possible. Those boards are comparable, or am I misstaking? 

I did some basic testing of sampling one channel with 512 samples and timed it. If I break it down to one sample it results in ~21ksps.

Just wanted to double check if some experienced simimlar performance or can give me some guidance. 

Thanks  & greetings

 

 

N=512
test = np.zeros(N)
adc = ExpanderPi.ADC()
adc.set_adc_refvoltage(4.096)

while True:
    T_start = datetime.datetime.now()
    for n in np.arange(0, N):
        test[n] = adc.read_adc_voltage(1, 0)
    T_end = datetime.datetime.now()
    T_sample_all = (T_end - T_start).total_seconds()
    T_sample_one = T_sample_all/N
    f_sample= 1/T_sample_all
    f_sample2=1/T_sample_one

 

 

24/09/2018

Posted by:
andrew

Users Avatar

Location:
United Kingdom

Users Twitter  Users Website  

Hi

21Ksps will be about the average for the Expander Pi ADC when using a Raspberry Pi 3.  I have uploaded a speed test demo to our github repository which works similar to your code.  You can find it at https://github.com/abelectronicsuk/ABElectronics_Python_Libraries/blob/master/ExpanderPi/demos/demo_adcspeed.py

The sample rate will vary depending on several factors like Raspberry Pi model, whether you are using Python 2 or 3 and what other processes are running at the same time.  You will probably see about a 10% speed gain when using Python 2 instead of 3 as 2 seems to be better optimised.

The get the maximum sample rate out of the ADC you will need to use a compiled language like C or C++.  I have uploaded a new speed test to our Expander Pi C library so I could compare the results and the sample rate of the C demo is around 54Ksps, so more than twice the speed of the Python library.

AB Electronics UK Tech Support

24/09/2018

Posted by:
mallok05

Users Avatar

Hi Andrew,

 

thanks for your quick and helpful response!

Good to know about the better performance of python2. Yeah I'm aware about the variety of timing related on the by that comes with the Linux kernel scheduling. For the start I'll try to deal with it and hope isolation of cpu cores and the preempt_rt patch will provide me with satisfying performance.

Maximum sampling rate is not the main goal  rather to have it somehow stable at a certain sampling rate and 20ksps would absolutely fit my needs.

For now I'm kind of forced to stick to python because the project is meant to be a proof of concept to design a radar system(adc, dac and spectrum analysis). We'll see where it ends up :)

Thanks for your help  I really appreciate! 

 

Greetings 

Note: documents in Portable Document Format (PDF) require Adobe Acrobat Reader 5.0 or higher to view, download Adobe Acrobat Reader or other PDF reading software for your computer or mobile device.