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

Thread: Teensy 4.0 analogRead bug

  1. #1

    Teensy 4.0 analogRead bug

    Hallo friends

    I'm starting with Teensy 4.0 and I have a little problem.

    I want to control the frequency of a waveform with a potentiometer on analog input A0. The potentiometer is connected to the 3.3V supply voltage and GND. The internal reference voltage for the ADC is 3.3V

    The problem: There is a jump at one point in the frequency sweep. The jump in the ADC value can also be seen on the serial plotter. I used a different analog input. It's the same problem. I also tested different ADC resolutions. Without success.


    My hardware


    ADC digital input values




    PHP Code:
    #include <Audio.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>

    // GUItool: begin automatically generated code
    AudioSynthWaveform       waveform1;      //xy=1123,493
    AudioOutputI2S           i2s1;           //xy=1304,494
    AudioConnection          patchCord1(waveform10i2s10);
    AudioConnection          patchCord2(waveform10i2s11);
    AudioControlSGTL5000     sgtl5000_1;     //xy=1252,563
    // GUItool: end automatically generated code

    void setup() {
      
    Serial.begin(38400);
      
    AudioMemory(20);
      
    sgtl5000_1.enable();
      
    sgtl5000_1.volume(0.65);
      
    waveform1.begin(WAVEFORM_SINE);
      
    waveform1.amplitude(0.5);
    }


    int val_1;

    void loop() {
      
    val_1 analogRead(A0);
      
    waveform1.frequency(val_1);
      
    Serial.println(val_1);
      
    delay(10);

    Greetings Rolf

  2. #2
    Senior Member
    Join Date
    May 2015
    Location
    USA
    Posts
    647
    I'd check with volt and ohm meters.

  3. #3
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,407
    That is perhaps the hysteresis break over point. It has been discussed before in other post(s)

    What version of TeensyDuino is installed? 1.53 is the current.

    Not sure if that was fixed on the analog setup is subsequent releases? If using the latest and still seeing the same result - perhaps prior notes will help.

  4. #4
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,407
    See this post Teensyduino-1-49-Beta-4

    more notes on page 2 of that thread

  5. #5
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,407
    Also not sure of using AnalogRead with audio system?

  6. #6
    Senior Member
    Join Date
    Jul 2020
    Posts
    398
    And what value potentiometer are you using?

  7. #7
    Hallo

    I have installed Arduino 1.8.13 and Teensyduino 1.53. I have change resistor from 50K to 10K. Its same Problem.

    The adc resolution ist 10Bit. I will set Oscillator parameters with an poti in my teensy programm.

    reading ADC
    https://youtu.be/PPT20mn968U

    Greetings Rolf

  8. #8
    I do not understand.
    What is the problem with reading an ADC register

  9. #9
    I do not understand.
    What is the problem with reading an ADC register


    The ADC value (10bit resolution) is Interruption from 492 to 656. The following values from 656 up to 4095 are ok.

  10. #10
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,407
    That is not the hysteresis point which is at midrange - was just guessing not reading the plotted data values correctly.

    If the same code is done without Audio Library in use in a simple sample does that work?

  11. #11
    Thanks for your help. I will test this

  12. #12
    Here the test without audio interface. I read only ADC input (10Bit). Its same problem.

    code
    Code:
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    
    // GUItool: begin automatically generated code
    
    // GUItool: end automatically generated code
    
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(38400);
      analogReadResolution(10);
      analogReadAveraging(20);
      
      //ADC_CONVERSION_SPEED(VERY_LOW_SPEED);
      
    
      // adc->setAveraging(16); // set number of averages
      // adc->setResolution(12); // set bits of resolution
      // adc->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_LOW_SPEED); // change the conversion speed
      // adc->setSamplingSpeed(ADC_SAMPLING_SPEED::MED_SPEED); // change the sampling speed
     
    }
    
    int adc_value;
    
    void loop() {
      adc_value = analogRead(A0);
       Serial.println(adc_value);
        delay(20);
    }
    Click image for larger version. 

Name:	ADC-11.jpg 
Views:	10 
Size:	53.6 KB 
ID:	21721

  13. #13
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    22,757
    Try adding pinMode(14, INPUT_DISABLE) at the beginning of your program. Does that help at all?

  14. #14
    Do you have an example for me Thanks

  15. #15
    Senior Member+ defragster's Avatar
    Join Date
    Feb 2015
    Posts
    12,407
    Quote Originally Posted by PaulStoffregen View Post
    Try adding pinMode(14, INPUT_DISABLE) at the beginning of your program. Does that help at all?
    That was linked/noted in post #4 above ...

    Quote Originally Posted by defragster View Post
    See this post Teensyduino-1-49-Beta-4

    more notes on page 2 of that thread

  16. #16
    Yes. It works. Thanks a lot

    Code:
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>
    #include <SerialFlash.h>
    
    
    // GUItool: begin automatically generated code
    
    // GUItool: end automatically generated code
    
    
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(38400);
      analogReadResolution(10);
      analogReadAveraging(20);
      pinMode(14, INPUT_DISABLE);
      
      //ADC_CONVERSION_SPEED(VERY_LOW_SPEED);
      
    
      // adc->setAveraging(16); // set number of averages
      // adc->setResolution(12); // set bits of resolution
      // adc->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_LOW_SPEED); // change the conversion speed
      // adc->setSamplingSpeed(ADC_SAMPLING_SPEED::MED_SPEED); // change the sampling speed
     
    }
    
    int adc_value;
    
    void loop() {
      adc_value = analogRead(A0);
       Serial.println(adc_value);
        delay(20);
    }

    Click image for larger version. 

Name:	ADC-ok.jpg 
Views:	12 
Size:	46.2 KB 
ID:	21722
    Last edited by Rolfdegen; 09-14-2020 at 05:43 PM.

Posting Permissions

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