Analog read that won't slow down the main loop, is this possible?

Status
Not open for further replies.

CyberGene

Member
This is probably a very silly question but I am not familiar with how exactly the micro-controller stuff works, so my apologies. I work on a piano MIDI-controller and I scan through all the keys reading digital input data (in the dedicated thread I've explained that). This needs to be very fast and every microsecond counts. This is already done and works great. However I also need to read the sustain pedal position which isn't just a switch, it generates a continuous voltage, so I am thinking of using an analog input for it. I don't need this to be read as fast as possible, I can afford probing its current value much slower than the keys. However I prefer not doing that in the main loop because even a single analog read takes too much time and will slow down my main key logic. Anyway, in the Teensy documentation there's some explanation I couldn't quite comprehend that suggests there might be a way for the ADC to store the value in a buffer and then I can just poll the buffer from my main loop. What I am not sure is whether the ADC works in its own "separate thread" so to speak, which I seriously doubt, but just in case, is this possible? I mean, is it possible that the ADC works independently of the main loop and stores the value somewhere so that I can then fast read that value from memory in my main loop?
 
There is the ADC library for that. And there are different examples for autonomous sampling in the background and either filling a (ring) buffer or using DMA to return its readings without blocking the system.
 
Thanks. I believe you refer to what I also read and made me open this thread: https://www.pjrc.com/teensy/adc.html
I couldn't understand that page to be honest, but I will certainly read it a few more times and see whether I have any questions. If you meant any other page, could you please post a link to it?
 
I was referring to the ADC library and its examples which come with the Teensyduino installation and are accessible through the Arduino/Teensyduino IDE's menu. That's always the first place to look at. Some of the PJRC documentation pages are unfortunately outdated and thus not of great help. Look rather at this thread.
 
I was referring to the ADC library and its examples which come with the Teensyduino installation and are accessible through the Arduino/Teensyduino IDE's menu. That's always the first place to look at. Some of the PJRC documentation pages are unfortunately outdated and thus not of great help. Look rather at this thread.

Ahh, I see now! Many thanks! :)
 
Status
Not open for further replies.
Back
Top