Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

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

  1. #1
    Junior Member
    Join Date
    Mar 2018
    Posts
    15

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

    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?

  2. #2
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,056
    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.

  3. #3
    Junior Member
    Join Date
    Mar 2018
    Posts
    15
    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?

  4. #4
    Senior Member+ Theremingenieur's Avatar
    Join Date
    Feb 2014
    Location
    Colmar, France
    Posts
    2,056
    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.

  5. #5
    Junior Member
    Join Date
    Mar 2018
    Posts
    15
    Quote Originally Posted by Theremingenieur View Post
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •