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

Thread: Inconsistent readings on T4 A0

Threaded View

  1. #1
    Junior Member
    Join Date
    Oct 2019

    Inconsistent readings on T4 A0


    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?



    #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, 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);
          TotTime = micros()-StartTime;   // record duration in microseconds
          Serial.print("Microseconds/ADC-Read: ");
          Serial.print("     ADC VALUE: ");
          Serial.print(avgVolt, DEC);
    Last edited by Frank B; 03-25-2020 at 09:29 AM. Reason: Added missing code tags

Posting Permissions

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