ADC read frequency

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
mironk
Posts: 9
Joined: Sun Jan 26, 2020 10:27 pm

ADC read frequency

Post by mironk » Fri Feb 19, 2021 12:16 pm

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)
.........................................................

HerbV
Posts: 6
Joined: Sat Oct 27, 2018 1:33 pm

Re: ADC read frequency

Post by HerbV » 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

User avatar
Roberthh
Posts: 2454
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ADC read frequency

Post by Roberthh » 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.

mironk
Posts: 9
Joined: Sun Jan 26, 2020 10:27 pm

Re: ADC read frequency

Post by mironk » Sun Feb 21, 2021 1:08 pm

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.

mironk
Posts: 9
Joined: Sun Jan 26, 2020 10:27 pm

Re: ADC read frequency

Post by mironk » Sun Feb 21, 2021 1:09 pm

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

mironk
Posts: 9
Joined: Sun Jan 26, 2020 10:27 pm

Re: ADC read frequency

Post by mironk » Sun Feb 21, 2021 1:11 pm

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 :)

Post Reply