Quick into: been loving Teensy for a couple years (5x boards, T3.2, T3.5, T4.0), doing various things with analog and digital sensors, LCD screens and relays/SSRs. My background is ME, but I've been tinkering with Arduino since 2008ish.
Issue: I'm exploring analogReadRes() on a T4.0, and getting very odd results. In void loop() I increment analogReadRes() from 6 to 16 by 1, and cycle at 2Hz, with a basically constant input voltage. Results sent to serial monitor are mostly a long way from expected. I've searched/read this and other forums for over an hour, and consulted an EE friend, all verifying my understanding and resultant confusion.
Details: hardware: T4.0 with Adafruit phototransistor collector connected to 3v3 upper right pin, emitter connected to A9 / 24k Ohm resistor, which is connected to G (upper right pin). Over 10sec, a DMM shows voltage at A9 varies between 3.1629V to 3.1634V (±0.008%)
Details: code: from Arduino IDE 1.8.9, using Teensyduino 1.48-beta1 (don't judge the coding. It's very simple, evolved from the first unexpected discovery and could/should be much more efficiently done. It is valid though, I believe.)
Details: analysis: Theory would suggest the following outputs: (sorry, can't make the table justify correctly )
Res 6 7 8 9 10 11 12 13 14 15 16
Max Counts 63 127 255 511 1023 2047 4095 8191 16383 32767 65535
V_ref 3.2987
V 3.1630 60 121 244 489 980 1962 3926 7854 15709 31419 62839
but here's what i get:
65535
Teensy Output 6 7 8 9 10 11 12 13 14 15 16
t=000ms 3934 3934 245 3934 983 3934 3934 3934 3935 3934 3934
t=500ms 3934 3935 245 3934 984 3934 3934 3934 3934 3934 3934
t=1000ms 3934 3933 246 3934 983 3935 3934 3936 3933 3934 3933
t=1500ms 3932 3935 245 3934 983 3935 3934 3935 3934 3933 3933
Read Error 3874 3813 1 3445 3 1973 8 -3919 -11775 -27485 -58906
Everything I read (both Arduino and Teensy reference and forum sources) indicates I should be able to set from 1 to 16 bit resolution, and get the correctly scaled ADC count. The results above seem to indicate that I can only use 8, 10 and 12 bit resolution. I welcome another clear illustration of my (well established) stupidity, but please include a bit of edumacation, just to ward off a few more forehead bruises
Issue: I'm exploring analogReadRes() on a T4.0, and getting very odd results. In void loop() I increment analogReadRes() from 6 to 16 by 1, and cycle at 2Hz, with a basically constant input voltage. Results sent to serial monitor are mostly a long way from expected. I've searched/read this and other forums for over an hour, and consulted an EE friend, all verifying my understanding and resultant confusion.
Details: hardware: T4.0 with Adafruit phototransistor collector connected to 3v3 upper right pin, emitter connected to A9 / 24k Ohm resistor, which is connected to G (upper right pin). Over 10sec, a DMM shows voltage at A9 varies between 3.1629V to 3.1634V (±0.008%)
Details: code: from Arduino IDE 1.8.9, using Teensyduino 1.48-beta1 (don't judge the coding. It's very simple, evolved from the first unexpected discovery and could/should be much more efficiently done. It is valid though, I believe.)
Code:
#define lsPin A9
void setup() {
Serial.begin(9600);
analogReadAveraging(32); //testing aReadAvg function
delay(500);
uint32_t digitsTest = 65535; // checking for roll-over or other variable size badness
Serial.println(digitsTest);
Serial.println("6\t7\t8\t9\t10\t11\t12\t13\t14\t15\t16"); // header
}
void loop() {
analogReadRes(6);
Serial.print(analogRead(lsPin)); Serial.print("\t");
analogReadRes(7);
Serial.print(analogRead(lsPin)); Serial.print("\t");
analogReadRes(8);
Serial.print(analogRead(lsPin)); Serial.print("\t");
analogReadRes(9);
Serial.print(analogRead(lsPin)); Serial.print("\t");
analogReadResolution(10);
Serial.print(analogRead(lsPin)); Serial.print("\t");
analogReadResolution(11);
Serial.print(analogRead(lsPin)); Serial.print("\t");
analogReadResolution(12);
Serial.print(analogRead(lsPin)); Serial.print("\t");
analogReadResolution(13);
Serial.print(analogRead(lsPin)); Serial.print("\t");
analogReadResolution(14);
Serial.print(analogRead(lsPin)); Serial.print("\t");
analogReadRes(15);
Serial.print(analogRead(lsPin)); Serial.print("\t");
analogReadResolution(16);
Serial.println(analogRead(lsPin));
delay(500);
}
Details: analysis: Theory would suggest the following outputs: (sorry, can't make the table justify correctly )
Res 6 7 8 9 10 11 12 13 14 15 16
Max Counts 63 127 255 511 1023 2047 4095 8191 16383 32767 65535
V_ref 3.2987
V 3.1630 60 121 244 489 980 1962 3926 7854 15709 31419 62839
but here's what i get:
65535
Teensy Output 6 7 8 9 10 11 12 13 14 15 16
t=000ms 3934 3934 245 3934 983 3934 3934 3934 3935 3934 3934
t=500ms 3934 3935 245 3934 984 3934 3934 3934 3934 3934 3934
t=1000ms 3934 3933 246 3934 983 3935 3934 3936 3933 3934 3933
t=1500ms 3932 3935 245 3934 983 3935 3934 3935 3934 3933 3933
Read Error 3874 3813 1 3445 3 1973 8 -3919 -11775 -27485 -58906
Everything I read (both Arduino and Teensy reference and forum sources) indicates I should be able to set from 1 to 16 bit resolution, and get the correctly scaled ADC count. The results above seem to indicate that I can only use 8, 10 and 12 bit resolution. I welcome another clear illustration of my (well established) stupidity, but please include a bit of edumacation, just to ward off a few more forehead bruises