High speed ADC code for M4
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- ltuser
- Posts: 14
- Joined: Wed Aug 28, 2019 2:53 pm
High speed ADC code for M4
I would like to use circuit python to capture audio. I would like to know if there is any existing code that I can use to capture 1 channel of audio. The sample rate of the M4 is around 1 Msps and I was looking for code that would get the highest sample rate with the Itsy Bitsy M4. Thanks in advance.
- mikeysklar
- Posts: 13946
- Joined: Mon Aug 01, 2016 8:10 pm
Re: High speed ADC code for M4
There are a few closed issues discussing ADC performance in the github repo for CircuitPython.
I recommend starting with the benchmark code that was originally used to see where you are at.
https://github.com/adafruit/circuitpython/issues/484
https://github.com/adafruit/circuitpython/issues
I recommend starting with the benchmark code that was originally used to see where you are at.
Code: Select all
import time
import board
import analogio
adc = analogio.AnalogIn(board.A1)
SAMPLES = 256
while True:
start = time.monotonic()
for _ in range(SAMPLES):
adc_val = adc.value
duration_secs = time.monotonic() - start
sample_secs = duration_secs / SAMPLES
rate = 1/sample_secs
print('Time per sample: {}ms rate:{} Total time: {}ms'.format(sample_secs*1000, rate, duration_secs*1000))
https://github.com/adafruit/circuitpython/issues
Please be positive and constructive with your questions and comments.