0

ADC / DAC very slow
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ADC / DAC very slow

by wilsk on Sat May 25, 2019 10:08 am

I have a brand new Feather M4 Express. I ran some Python code to benchmark the ADC (A1) and DAC (A0) sample rates, to see what how far off the product marketing is. I sampled 100k times with something like this code:

Code: Select all | TOGGLE FULL SIZE
val = 0
for i in range(100000):
    val = my_adc.value


I get:

WRITE: 5.09302s / 19634.7ksps
READ: 8.10986s / 12330.7ksps


Performing a similar task via Arduino, DAC writes at 820ksps (40x faster) and ADC reads at 38.6ksps (3x faster) using plain old analogRead / analogWrite. Is this the fastest we can get via Python? Are there any libraries or settings I should look at to get higher sample rates or is CircuitPython just not able to get fast reads/writes? I'm aware of the performance limitations of Python vs C.

wilsk
 
Posts: 3
Joined: Sat May 25, 2019 9:47 am

Re: ADC / DAC very slow

by franklin97355 on Sat May 25, 2019 12:53 pm

Are you sure of your numbers? 19634 is 24x more than 820 and 12330 is 324x bigger than 38.

franklin97355
 
Posts: 22173
Joined: Mon Apr 21, 2008 2:33 pm
Location: Lacomb, OR.

Re: ADC / DAC very slow

by danhalbert on Sat May 25, 2019 1:07 pm

There is significant overhead with CircuitPython. We also run the converters relatively slowly to ensure accuracy. We have plans to do faster acquisition of multiple samples at once: https://github.com/adafruit/circuitpython/issues/487.

danhalbert
 
Posts: 2497
Joined: Tue Aug 08, 2017 12:37 pm

Re: ADC / DAC very slow

by wilsk on Sat May 25, 2019 6:57 pm

franklin97355 wrote:Are you sure of your numbers? 19634 is 24x more than 820 and 12330 is 324x bigger than 38.


Oops, obviously the initial results are in samples per second, not ksps.

danhalbert wrote:We have plans to do faster acquisition of multiple samples at once: https://github.com/adafruit/circuitpython/issues/487.


Thanks for the reply. Looks like I might have to port my libraries to C!

wilsk
 
Posts: 3
Joined: Sat May 25, 2019 9:47 am

Re: ADC / DAC very slow

by tannewt on Thu May 30, 2019 1:50 pm

wilsk, if you know C then you could tackle the issue Dan linked. :-) We'd love to have higher speed sampling in CircuitPython. Let us know if that sounds interesting.

tannewt
 
Posts: 2585
Joined: Thu Oct 06, 2016 8:48 pm

Re: ADC / DAC very slow

by wilsk on Fri May 31, 2019 1:53 am

tannewt2 wrote:wilsk, if you know C then you could tackle the issue Dan linked. :-) We'd love to have higher speed sampling in CircuitPython. Let us know if that sounds interesting.


I took a look at the docs to see how hard this would be last week, but as I'm pretty time poor these days I opted to rewrite my libraries in C instead. It was shorter to convert my library to C than to read through the docs :)

I did like the idea of simulating my code in Jupyter notebooks and then just dropping it on to device which I can't do using C, however at this point getting things up and running as fast as possible is my priority!

wilsk
 
Posts: 3
Joined: Sat May 25, 2019 9:47 am

Please be positive and constructive with your questions and comments.