Teensy 4.0 analogRead bug

Status
Not open for further replies.

Rolfdegen

Well-known member
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
Teensy.jpg


ADC digital input values
ADC-out.jpg




PHP:
#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(waveform1, 0, i2s1, 0);
AudioConnection          patchCord2(waveform1, 0, i2s1, 1);
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
 
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.
 
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

Greetings Rolf
 
I do not understand.
What is the problem with reading an ADC register :confused:


The ADC value (10bit resolution) is Interruption from 492 to 656. The following values from 656 up to 4095 are ok.
 
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?
 
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);
}

ADC-11.jpg
 
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);
}


ADC-ok.jpg
 
Last edited:
Status
Not open for further replies.
Back
Top