Page 1 of 1
ADC read frequency
Posted: Fri Feb 19, 2021 12:16 pm
by mironk
Hi! What maximum adc rate is possible with RPI pico? I used the code below and 1e6 ADC reads takes about 60s. It is about 16kHz. Is there any method to obtain 0.5 - 1 MHz?
.....................................................
Code: Select all
import utime
import machine
time_start = utime.time_ns()
for i in range(1000000):
adc=machine.ADC(26)
val=adc.read_u16()
time_stop = utime.time_ns()
elapsed_time = time_stop-time_start
time_s = elapsed_time /1000000000.00
print(time_s)
.........................................................
Re: ADC read frequency
Posted: Sat Feb 20, 2021 9:48 am
by HerbV
Hi,
your code could be around 3 times faster, but still not 0.5 to 1Mhz
i
Code: Select all
mport utime
import machine
adc=machine.ADC(26)
time_start = utime.time_ns()
for i in range(100000):
val=adc.read_u16()
time_stop = utime.time_ns()
elapsed_time = time_stop-time_start
time_s = elapsed_time /1000000000.00
print(time_s)
Did you try that:
https://www.hackster.io/AlexWulff/adc-s ... ico-f883dd
Re: ADC read frequency
Posted: Sat Feb 20, 2021 1:01 pm
by Roberthh
According to the data sheet the maximum sample rate is 500ks/sec. The only way to transfer data at this rate is by using DMA. The rate at which the ADC runs can be configured. Python itself has no direct access to configure DMA and the ADC registers, but you can use viper code to do that. For DMA, examples are in this thread:
viewtopic.php?f=21&t=9697&start=20
You will need to refer to the RP2040 data sheet for proper settings.
Re: ADC read frequency
Posted: Sun Feb 21, 2021 1:08 pm
by mironk
HerbV wrote: ↑Sat Feb 20, 2021 9:48 am
Hi,
your code could be around 3 times faster, but still not 0.5 to 1Mhz
i
Code: Select all
mport utime
import machine
adc=machine.ADC(26)
time_start = utime.time_ns()
for i in range(100000):
val=adc.read_u16()
time_stop = utime.time_ns()
elapsed_time = time_stop-time_start
time_s = elapsed_time /1000000000.00
print(time_s)
Did you try that:
https://www.hackster.io/AlexWulff/adc-s ... ico-f883dd
Thanks. Your suggestion indeed improved the ADC rate.
Re: ADC read frequency
Posted: Sun Feb 21, 2021 1:09 pm
by mironk
Roberthh wrote: ↑Sat Feb 20, 2021 1:01 pm
According to the data sheet the maximum sample rate is 500ks/sec. The only way to transfer data at this rate is by using DMA. The rate at which the ADC runs can be configured. Python itself has no direct access to configure DMA and the ADC registers, but you can use viper code to do that. For DMA, examples are in this thread:
viewtopic.php?f=21&t=9697&start=20
You will need to refer to the RP2040 data sheet for proper settings.
Thanks
Re: ADC read frequency
Posted: Sun Feb 21, 2021 1:11 pm
by mironk
Roberthh wrote: ↑Sat Feb 20, 2021 1:01 pm
According to the data sheet the maximum sample rate is 500ks/sec. The only way to transfer data at this rate is by using DMA. The rate at which the ADC runs can be configured. Python itself has no direct access to configure DMA and the ADC registers, but you can use viper code to do that. For DMA, examples are in this thread:
viewtopic.php?f=21&t=9697&start=20
You will need to refer to the RP2040 data sheet for proper settings.
Thanks. I will try. But I am afraid it will be hard task to me. I am novice
