Hey Folks,
i have an issue that i cannot solve myself anymore.
I read lots of forum posts and tried the ideas but no solution until now
I have a teensy 4.0 project that gets power from a 12v lipo. I want to measure the voltage to avoid damaging the lipo.
Power Supply is as follows:
12v lipo-> |-> step-down-converter -> 5v -> Tensy 4.0
................|-> voltage divider -> Teensy ADC PIN
To measure the voltage i convert the 12v by a voltage divider so that there will be max. 3,3 volts at the teensy adc pin, because that should be the maximum the pins can handle.
i calculated with a max. voltage of 27v and have a 33 kOhm and a 4.7 kOhm resistor, so that there are max. 3.3v @27v at the adc pin. All that works fine. i checked with my voltage meter.
setup:
=====
pinMode(LIPO_PIN, INPUT);
volt = analogRead(LIPO_PIN);
voltageSmooth = map(volt, 0, 1023, 0, 270); // 270 shall represent 27.0 volts
loop:
=====
volt = analogRead(LIPO_PIN);
voltageSmooth = 0.7 * voltageSmooth + 0.3 * map(volt, 0, 1023, 0, 270);
The measurement happens only once every second!
"0.7 * voltageSmooth + 0.3 * ...." is used as a smoothing function.
As far as is understand i should get a measured value of 1023 when my input voltage is 27v and the pin has 3.3v. but there are 2 problems:
1) the measured value is fluctuating very strongly and is unstable.
2) i never measure something near 1023 @3.3v at the pin:
........27v input: volt: 870 - 930 instead of 1023 / voltageSmooth is around 210
........12v input: volt: 300 - 340 / voltageSmooth: around 165
........8v input: volt: 140 - 160 / voltageSmooth: around 150
Why does this not work as expected/intended?
Any help is appreciated !!
thx a lot!
bye
andre
i have an issue that i cannot solve myself anymore.
I read lots of forum posts and tried the ideas but no solution until now
I have a teensy 4.0 project that gets power from a 12v lipo. I want to measure the voltage to avoid damaging the lipo.
Power Supply is as follows:
12v lipo-> |-> step-down-converter -> 5v -> Tensy 4.0
................|-> voltage divider -> Teensy ADC PIN
To measure the voltage i convert the 12v by a voltage divider so that there will be max. 3,3 volts at the teensy adc pin, because that should be the maximum the pins can handle.
i calculated with a max. voltage of 27v and have a 33 kOhm and a 4.7 kOhm resistor, so that there are max. 3.3v @27v at the adc pin. All that works fine. i checked with my voltage meter.
setup:
=====
pinMode(LIPO_PIN, INPUT);
volt = analogRead(LIPO_PIN);
voltageSmooth = map(volt, 0, 1023, 0, 270); // 270 shall represent 27.0 volts
loop:
=====
volt = analogRead(LIPO_PIN);
voltageSmooth = 0.7 * voltageSmooth + 0.3 * map(volt, 0, 1023, 0, 270);
The measurement happens only once every second!
"0.7 * voltageSmooth + 0.3 * ...." is used as a smoothing function.
As far as is understand i should get a measured value of 1023 when my input voltage is 27v and the pin has 3.3v. but there are 2 problems:
1) the measured value is fluctuating very strongly and is unstable.
2) i never measure something near 1023 @3.3v at the pin:
........27v input: volt: 870 - 930 instead of 1023 / voltageSmooth is around 210
........12v input: volt: 300 - 340 / voltageSmooth: around 165
........8v input: volt: 140 - 160 / voltageSmooth: around 150
Why does this not work as expected/intended?
Any help is appreciated !!
thx a lot!
bye
andre