Inconsistent readings on T4 A0

Status
Not open for further replies.

marcoconti

New member
Hi,

I am testing the below code with the latest stable version of Teensyduino 1.51 on Arduino 1.8.12.
The code reads 100 times Pin 14, it averages the output data, the used time and it prints the results.

I noted the following behaviors:

1) No voltage source is connected to Pin 14: readings are close to 4,095 -[1,100]
2) 3.3V Pin is connected through a 100 KOhm resistor to Pin 14: readings 4,095 -[1,30]
3) Ground Pin is connected through a 100 KOhm resistor to Pin 14: 0 +[1,14]

The above results are as expected although not precise despite the stable connection between pins. A first request of information is: how can I have more precise and consistent readings?

What is not expected is that if I ground Pin 14 as in case 3) for a few seconds or minutes and then I disconnect Pin 14, readings do not return to 1 immediately). They become erratic for an unpredictable time in which it seems that they are working normal because they show values between +1 and +300, which can be the humid air's voltage. However, if I touch the 100Kohm resistor's terminal with my finger (which can have a 30-50mV charge) Pin 14 starts reading from 3,800 up and then sets on around 4,000 values as in case 1) of start without any voltage source connected.

Why Pin 14 does not return reading values between +1 and +300 after I detach my finger and no voltage source is connected? Why it switched on values as in case 1)? Note I tried the below code also without #define VREF (3.292) and nothing changed.

Where am I wrong?

Regards,

Marco


Code:
#define VREF (3.292)         // ADC reference voltage (= power supply)
//#define VINPUT (1.328)       // ADC input voltage from NiCd AA battery
#define ADCMAX (4095)        // maximum possible reading from ADC
//#define EXPECTED (ADCMAX*(VINPUT/VREF))     // expected ADC reading
#define SAMPLES (16)      // how many samples to combine for pp, std.dev statistics

unsigned int analogInPin = A0;  // Analog input is  (Teensy4 pin 14)
const int LED1 = 13;         // output LED connected on Arduino digital pin 13

int sensorValue = 0;        // value read from the ADC input
unsigned long StartTime=0;
unsigned long TotTime=0;
unsigned long ReadTimeUnit=0;
unsigned int x=0;
unsigned int i=0;
unsigned long avgVolt=0;
void setup() {    // ==============================================================
     
    
      pinMode(LED1,OUTPUT);       // enable digital output for turning on LED indicator
      // analogReference(EXTERNAL);  // set analog reference to internal ref
      analogReadRes(12);          // set ADC resolution to this many bits
      analogReadAveraging(SAMPLES);    // average this many readings
     
      Serial.begin(115200);       // baud rate is ignored with Teensy USB ACM i/o
      digitalWrite(LED1,HIGH);   delay(1000);   // LED on for 1 second
      digitalWrite(LED1,LOW);    delay(3000);   // wait in case serial monitor still opening
     
      Serial.println("# Teensy ADC test start: ");
} // ==== end setup() ===========

void loop() {  // ================================================================ 
     
      
             
      StartTime = micros();   // record start time in microseconds
          
      for (i=0;i<100;i++) {
                              x = analogRead(analogInPin);
                              avgVolt=avgVolt+x;
                              } 
      TotTime = micros()-StartTime;   // record duration in microseconds
      
      ReadTimeUnit=TotTime/i;
      avgVolt=avgVolt/i;
      
      Serial.print("Microseconds/ADC-Read: ");
      Serial.print(ReadTimeUnit,DEC);
      Serial.print("     ADC VALUE: ");
      Serial.print(avgVolt, DEC);
      Serial.println();
      
      i=0;
      x=0;
      ReadTimeUnit=0;
      avgVolt=0;
      
      delay(1000);      
            
            }
 
Last edited by a moderator:
Please understand that these ADCs are SAR ADCs. Which means that (short and simplified) the time is counted which the input voltage needs to charge or to discharge an internal capacitor. Thus, the ADC input pin does not have a constant impedance but the latter varies over the sampling and measuring cycle. That's why NXP recommends two things in an application note : First, make sure that your source impedance is as low as possible, but never above 10kOhm (using for example 4.7k resistors instead of the 100k in your test setup will already give better results). Second, to buffer the load current switching peaks, NXP recommends connecting a small capacitor (between 1 and 10nF) in parallel with the source from the ADC input pin to ground.
 
Giving consistency to T4 Pin 14 (A0) Readings

Please understand that these ADCs are SAR ADCs. Which means that (short and simplified) the time is counted which the input voltage needs to charge or to discharge an internal capacitor. Thus, the ADC input pin does not have a constant impedance but the latter varies over the sampling and measuring cycle. That's why NXP recommends two things in an application note : First, make sure that your source impedance is as low as possible, but never above 10kOhm (using for example 4.7k resistors instead of the 100k in your test setup will already give better results). Second, to buffer the load current switching peaks, NXP recommends connecting a small capacitor (between 1 and 10nF) in parallel with the source from the ADC input pin to ground.


Understood. Thank you!

Marco
 
Status
Not open for further replies.
Back
Top