is it possible to do something else during adc reading ?

Discussion related to "under the hood" OpenMV topics.
User avatar
chrisPyres66
Posts: 138
Joined: Mon Jul 16, 2018 9:22 am
Location: France

is it possible to do something else during adc reading ?

Postby chrisPyres66 » Tue Jan 21, 2020 3:14 am

Dear all,

i try to sample an analog signal at 40khz with adc but i dont success to do it in real time in this code :

Code: Select all

import time, pyb
from pyb import ADC

adc = pyb.ADC(pyb.Pin("P6"))        # create an ADC on pin P5
tim = pyb.Timer(6, freq=40000)         # create a timer running at 10Hz
buf = bytearray(5)                # creat a buffer to store the samples

while(True):
    # The ADC has 12-bits of resolution for 4096 values.
    print("----------")
    adc.read_timed(buf, tim)            # sample here
    i=1
    for val in buf:                     # loop over all values
        print(i, val)                      # print the value out
        i=i+1
    time.sleep(1000)
because i cant do anything else when adc.read_timed(buf, tim) is working.
Do you have another way to do this ?

Thanks,
User avatar
iabdalkader
Posts: 1085
Joined: Sun May 24, 2015 3:53 pm

Re: is it possible to do something else during adc reading ?

Postby iabdalkader » Tue Feb 04, 2020 7:12 am

That's not how this function works, it reads n samples and then returns. If you want to do something else while sampling the closest you can get is sampling in a timer callback.

Return to “Technical Discussion”

Who is online

Users browsing this forum: No registered users and 7 guests