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

Thread: Teensy 3.6 ADC use breaks Analogread

  1. #1
    Junior Member
    Join Date
    Jun 2017
    Posts
    17

    Teensy 3.6 ADC use breaks Analogread

    I'm trying to read the value of A3 and A12 at the same time. I want to use the audio library to read an input from an analog instrument and then a potentiometer to also be read to change values in the code. The pot works normally giving values from 0-1023 until I add the adc1 module. When I add 'AudioInputAnalog adc1;' the pot gives values from 12-65535 and stops going up in value at about the 12 oclock position Here's the code I've narrowed down:

    Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    // GUItool: begin automatically generated code
    
    //AudioInputAnalog         adc1;           //xy=623,339 <<<<-------this breaks A12
    
    // GUItool: end automatically generated code
    
    const int analogPin12 = A12;   // pot2
    
    void setup() {
      // put your setup code here, to run once:
    
     Serial.begin(9600);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      
    int read12 = analogRead(analogPin12); //Read pot2
    Serial.println(read12);
    
    }
    I did find this previous post about bit resolution:
    https://forum.pjrc.com/threads/41911...ADC-resolution

    But does that mean if we are using the adc module from the audio library none of the other analog reads will work?

    I did read in the side bar of the adc module:
    "analogRead() must not be used, because AudioInputAnalog is regularly accessing the ADC hardware. If both access the hardware at the same moment, analogRead() can end up waiting forever, which effectively crashes your program."
    but does that mean analog read on the pin your using as an adc or all analog pins?

    Sorry if this a dumb question I'm quite new to programming and the teensy.

    *just realized this should probably be in the technical questions catagory
    Last edited by cfredisded; 08-11-2018 at 11:30 PM. Reason: wrong category

  2. #2
    Senior Member+ manitou's Avatar
    Join Date
    Jan 2013
    Posts
    1,611
    Quote Originally Posted by cfredisded View Post
    But does that mean if we are using the adc module from the audio library none of the other analog reads will work?
    Correct. see https://www.pjrc.com/teensy/gui/?info=AudioInputAnalog

Posting Permissions

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