adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.1k stars 1.22k forks source link

DMA'd ADC for high-speed sampling -> buffer #487

Closed ladyada closed 2 years ago

ladyada commented 6 years ago

for some applications, we want to grab a chunk of samples from ADC at 'fast' (16KHz!) fixed periods. lets think of a way we can request an array of 16-bit values that will be popped off the ADC pin at samplerate

EDIT: Implemented as analogbufio for raspberrypi -- Thanks @latkinso42!! I will open separate issues to implement analogbufio on each other port and close this general one.

tannewt commented 6 years ago

Perhaps this would be AudioIn? To correspond with AudioOut

tdicola commented 6 years ago

This would be used for lots of things beyond audio though--sampling any signal from the ADC, like a piezo, light sensor, load cell, etc.

ladyada commented 6 years ago

Yah - i think its the mirror. technically its not just for Audio, and i dont think we'd do WAV translation? but maybe we would?

ladyada commented 4 years ago

@jepler this might be a good one to pick up soonish (since ulab would be a good pairint)

kevinjwalters commented 4 years ago

I'm interested in this too. Here's some previous forums discussions where this has come up:

I'm not sure if it's related but I've noticed some demand for performant circular buffers discussed in CircularBuffer equivalent in CircuitPython?.

It would be great to be able to choose the 14bit ADC mode on the nRF52840. I'm curious if that gives better results than doing it in software. It's certainly more efficient in terms of CPU cycles.

dhalbert commented 4 years ago

I would like to add more control over the ADC on all ports, such as specifying oversampling, averaging (if available), maybe even differential mode, etc.

The native nRF52840 ADC accuracy is 12 bits. You can set it to 14 bits, but that just shifts the result over if oversampling is not enabled. But with oversampling, you can get 14 real bits.

kevinjwalters commented 4 years ago

I've just put some graphs of the nRF52840's 12 bit mode in action in CircuitPython 5.2.0 in Changing ADC to over-sampling mode for higher resolution?.

kevinjwalters commented 4 years ago

Added some performance data on a few different ways to read and sometimes store samples in https://forums.adafruit.com/viewtopic.php?f=60&t=164758 - nothing better than 21-21kHz on a CLUE.

latkinso42 commented 2 years ago

Please review https://github.com/latkinso42/circuitpython branch adcdma as a possible solution or possible solution to this issue. Thanks!