Erratic readings with ADC

Status
Not open for further replies.

yconst

Member
Hi all,

I'm the proud owner of a Teensy 3.5 which is having issues with ADC. My simple code to read a value:

Code:
#include <ADC.h>

ADC *adc = new ADC();

void setup() {
  adc->adc0->setAveraging(16); // set number of averages
  adc->adc0->setResolution(16); // set bits of resolution

}

void loop() {
  int value = adc->adc0->analogRead(A5);

  Serial.println(value);

  delay(250);
}

This returns 65364 as an output, which is clearly unexpected. No pins are connected to anything and Teensy gets power from usb.

At first it seems like a fried ADC or something similar. digitalRead() works fine btw.

But then the wierdness starts: Connecting A5 to Analog GND gives me a fluctuating value. Here's an excerpt from the serial:

Code:
34867
34867
34867
34867
34867
39151
39151
34899
32725
30583
39215
32741
32723
37009
37057

Then I tried connecting A5 to digital GND, ie the top left pin next to pin 0. This gives me a steady value around 30550 with small fluctuations.

I've tried the same with A8, A9 and A7 and got the same results so I believe that it is a general phenomenon.

All in all the above is quite puzzling to me so I'd like some help. I'm on Arduino 1.8.4 with teensyduino 1.41

First I'd like to know if possible: Is the ADC fried beyond recovery? Btw other chip functionality (such as PWM, i2c) seems fine at first glance.
Secondly, and if the answer to the first is no: What is going on and how can I get a reliable reading from the analog pins.

Thank you.
 
I just did that, so now my sketch is just Serial.println(analogRead(A5)); in loop(). This gives me 1023 whether I have the pin shorted to ground or not.

I've tried to run adc_test from the repo you linked but there's an error in compiling (undeclared ADC_ERROR)
 
What version of TeensyDuino is installed? I see ADC_ERROR defined and used in the current 1.42 code and on the github sources that haven't changed in at least 7 months. That may be new if you have an older install?

I just compiled the example for T_3.6 that comes from the installed: ..\hardware\teensy\avr\libraries\ADC\examples\adc_test
And it compiles for me without error. This was from installed : File / Examples / ADC / adc_test

Perhaps install or re-install Current version 1.41 or current Beta 1.42 and please post a more complete verbose compile output if that doesn't help.
 
I'm on Arduino 1.8.4 with teensyduino 1.41. The sketch I copy pasted from github so the error is probably a 1.42 beta thing.

I also see that the ADC library got updated..

I'm not on a fast connection right now so it'll have to wait to download the beta and new arduino ide till tomorrow. I'll keep you posted with progress.
 
Last edited:
might work from the 1.41 version installed examples until you can get the latest. Beta 6 likely out soon ...
 
Seems adc_test is a new one in 1.42 with the updated ADC library because I can't find in the examples.

I tried the readallpins example and got this:

A0: 3.30. A1: 3.30. A2: 3.30. A3: 3.30. A4: 3.30. A5: 3.30. A6: 3.30. A7: 3.30. A8: 3.30. A9: 3.30. A10: 3.30. A11: 3.30. A12: 3.30.
A13: 3.30. A14: 3.30. A15: 3.30. A16: 3.30. A17: 3.30. A18: 3.30. A19: 3.30. A20: 3.30. A21: 3.30. A22: 3.30. A23: 3.30. A24: 3.30.
Differential pairs: 0: -3.30.
Temperature sensor (approx.): : -1492.65 C.


This is again Arduino 1.8.4 with teensyduino 1.41. Not very encouraging I guess... :(
 
Hopefully there is some pending change that will work better in your case - With IDE 1.85 and TD 1.42 b5 on my T_3.6 readallpins compiles and gives this:
A0: 0.67. A1: 0.77. A2: 1.56. A3: 1.67. A4: 1.55. A5: 1.50. A6: 1.65. A7: 1.31. A8: 1.48. A9: 1.77.
A10: 1.57. A11: 1.91. A12: 2.25. A13: 2.08. A14: 1.96. A15: 1.70. A16: 2.19. A17: 2.22. A18: 2.09. A19: 2.18. A20: 2.17. A21: 1.65. A22: 2.07.
A23: 2.19. A24: 2.17.
Differential pairs: 0: 0.04.
Temperature sensor (approx.): : 37.66 C.
 
Status
Not open for further replies.
Back
Top