I noticed that there is a slight "problem" if using pinMode(Pin,INPUT).
I am using a voltage divider to measure 12V on a Teensy 3.5.
I know similar issues has been discussed before in
https://forum.pjrc.com/threads/69367-Issues-with-voltage-measurement-on-Teensy-4-0?highlight=pinmode+input+problems
and
https://forum.pjrc.com/threads/67341-T3-2-AnalogRead()-gives-wrong-values?highlight=voltage+measurement
but it does not really solve the problem.
The circuit looks like this:
R1 = 4MOhm, R2 = 1MOhm, Vin= 12V, Vout should be roughly 2.4V
Applying Vout to A0 - A9 while using pinMode(Pin,INPUT) for each pin increases the measured Voltage up to close to 3V
Applying Vout to A10, A11, A25 and A26 with the same settings does not mess up the measurement.
If R1 = 1kOhm, and R2 is 1kOhm the error is just a couple of mV on the A0-A9
Those high resistor values are needed for a low power application.
I measured Vout directly on the divider as well as on the pins, no difference...
As mentioned in other threads just not to use the pinMode function for any analog read solves this problem, but what causes it?
I am using the ResponsiveAnalogRead library and had to find out the hard way(again) that I need to comment the pinMode(pin, INPUT ); in the ResponsiveAnalogRead.cpp file to make sure everything works as intended.
Is there no fix or anything to make sure that declaring any analog pin as input will not mess up the measurements?
For now I am happy to use the "custom" ResponsiveAnalogRead library since I do not use this in any other projects, but in the long run it would be nice to use this library on all platforms without the need to manipulate this.
In my opinion declaring any analog pin as INPUT should not influence the measurement. Using INPUT_PULLUP or INPUT_PULLDOWN works as expected, why does INPUT then do stupid things?
Cheers
I am using a voltage divider to measure 12V on a Teensy 3.5.
I know similar issues has been discussed before in
https://forum.pjrc.com/threads/69367-Issues-with-voltage-measurement-on-Teensy-4-0?highlight=pinmode+input+problems
and
https://forum.pjrc.com/threads/67341-T3-2-AnalogRead()-gives-wrong-values?highlight=voltage+measurement
but it does not really solve the problem.
The circuit looks like this:
R1 = 4MOhm, R2 = 1MOhm, Vin= 12V, Vout should be roughly 2.4V
Applying Vout to A0 - A9 while using pinMode(Pin,INPUT) for each pin increases the measured Voltage up to close to 3V
Applying Vout to A10, A11, A25 and A26 with the same settings does not mess up the measurement.
If R1 = 1kOhm, and R2 is 1kOhm the error is just a couple of mV on the A0-A9
Those high resistor values are needed for a low power application.
I measured Vout directly on the divider as well as on the pins, no difference...
Code:
void setup() {
// initialize the pin as an input.
pinMode (A0,INPUT);
pinMode (A1,INPUT);
pinMode (A2,INPUT);
pinMode (A3,INPUT);
pinMode (A4,INPUT);
pinMode (A5,INPUT);
pinMode (A6,INPUT);
pinMode (A7,INPUT);
pinMode (A8,INPUT);
pinMode (A9,INPUT);
pinMode (A10,INPUT);
pinMode (A11,INPUT);
pinMode (A25,INPUT);
pinMode (A26,INPUT);
}
void loop() {
}
As mentioned in other threads just not to use the pinMode function for any analog read solves this problem, but what causes it?
I am using the ResponsiveAnalogRead library and had to find out the hard way(again) that I need to comment the pinMode(pin, INPUT ); in the ResponsiveAnalogRead.cpp file to make sure everything works as intended.
Is there no fix or anything to make sure that declaring any analog pin as input will not mess up the measurements?
For now I am happy to use the "custom" ResponsiveAnalogRead library since I do not use this in any other projects, but in the long run it would be nice to use this library on all platforms without the need to manipulate this.
In my opinion declaring any analog pin as INPUT should not influence the measurement. Using INPUT_PULLUP or INPUT_PULLDOWN works as expected, why does INPUT then do stupid things?
Cheers