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

Thread: AnalogRead - random values teensy 3.6

  1. #1
    Junior Member
    Join Date
    Jun 2020
    Posts
    10

    AnalogRead - random values teensy 3.6

    Hi,

    I'm trying to get readings on the voltage of my battery. Since the voltage of the battery exceeds 3.3V, I'm using a voltage divider with two 25 kohm resistors. See the attached picture for the schematic.
    Before using the battery, I tried with a benchtop power supply so I can play with the voltage. I plugged the output voltage to the analog pin A16 (pin number 35) on my teensy 3.6 but when I use the analogRead() function, I keep getting random values. I then tried to put a 0.1 uF capacitor in between the + and GND but that did not resolve the problem.

    Here is the simple code I used. And I keep getting random values. Can someone help me?

    Thank you!
    Roman

    PS: I tested the voltage output with a multimeter and I had a very stable voltage of 3V after the divider, which should give me readings near 1000.

    Click image for larger version. 

Name:	volt_div_analog_read.jpg 
Views:	4 
Size:	20.6 KB 
ID:	21888

    Code:
    void setup()
    {
    Serial.begin(9600);
    }

    int val;

    void loop()
    {
    val = analogRead(A16);
    //val = analogRead(35);
    Serial.print("analog is: ");
    Serial.println(val);
    delay(250);
    }

  2. #2
    Senior Member
    Join Date
    Feb 2018
    Location
    Corvallis, OR
    Posts
    205
    It would help a bit if you defined what you mean by "random values". Do you get values from 0 to 1023 (the full scale for 10-bit resolution), or random over some smaller range near the expected count.

    Two suggestions:

    1. put the 0.1uF capacitor between the ADC input pin and ground, not between + and ground. Put the capacitor as close to the Teensy pin as possible.
    2. Add "pinMode(A16, INPUT_DISABLE)" to your setup code. This disconnects any keeper resistors that might affect the analog input.

    Even after you've done these things, you can still expect 4 or 5 counts of variance in your values. If you want a more stable output, like your multimeter,
    you need to average the signal over several tenths of a second.

  3. #3
    Senior Member
    Join Date
    Aug 2013
    Location
    Gothenburg, Sweden
    Posts
    306
    Do you have a ground connection, there is none on your diagram ?

  4. #4
    Junior Member
    Join Date
    Jun 2020
    Posts
    10
    Dear mborgerson and mlu,

    Thank you so much for your answers. I finally managed to solve the problem. My Analog GND pin was indeed not grounded!
    Now, I have a very clear and stable signal.

    Thank you!
    Roman

Posting Permissions

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