I'll use a voltage divider with two 100k resistors to analogread the 7.4V batttery's voltage with an Digispark Attiny85 (that's also powered by this battery).
I can't find anymore the post that said something about having to add a capacitor to "stabilize" the readings when using high values of resistors in this Voltage Divider.
So, If I want to keep current draw at minimum (using this 100k + 100K resistors), which capacitor and how should I connect it? Apart from adding this capacitor, are there any other reasons I shouldn't use resistors in this 100k range? And adding this capacitor then things are as normal (in terms of measuring voltage) as using for instance two 10k resistors?
johnerrington:
What are you using as your voltage reference?
Well, i just did the math for the voltage divider, with no other reference. Is there a reference in the attiny85 that requires no extra pin to compare with?
For voltage measurements you should use one of the internal references of the Attiny85.
It has a ~2.56volt reference and a ~1.1volt reference.
For the 2.56volt one you could use a 10:22 divider (10k + 22k or 100k + 220k).
And set Aref to 2.56volt in setup.
Leo..
The capacitor to smooth the voltage would go between the joint in the voltage divider (input pin) and GND, correct? Could it be a Ceramic SMD capacitor, not electrolytic?
Johnerrington said 10-100nF is a good value. Does it change (the capacitor value) if the voltage divider is in the 100k range, or 1M range?
Anything between 10-100n ceramic (pin to ground) is fine, also if you use high value resistors.
A double read of the analogue pin, and use the second reading, also helps stabilise things when high resistor values are used.
Do use one of the internal Aref voltages for stability.
Leo..
The internal sampling cap of the Arduino ADC is about 14pF according to the datasheet. You can make the calculations. If the filtering cap is 1000 times larger the error is 1/1000 of full scale in the worst case. In other words ADC it will be negligible for the cap > 10nF. Size of the capacitor and resistors determine response speed and may be important if your application have short bursts of large current draw and you want to measure the battery voltage under load.
CrossRoads:
"I have no spare pins left to control the FET...."
Are your analog input pins used? Those can also be used as digital pins to drive a FET.
Unfortunately all Attiny 85 pins are used in this project... no other left.... Two For I2C, one for PWM a 3W led, two for a red/green led (battery level led), one for reading voltage.. all 6 are used...
Wawa:
Anything between 10-100n ceramic (pin to ground) is fine, also if you use high value resistors.
A double read of the analogue pin, and use the second reading, also helps stabilise things when high resistor values are used.
Do use one of the internal Aref voltages for stability.
Leo..
Could I use the DEFAULT reference, or it must be an internal one? There are the 1.1 and 2.56V internal ones in the Attiny85.
Smajdalf:
The internal sampling cap of the Arduino ADC is about 14pF according to the datasheet. You can make the calculations. If the filtering cap is 1000 times larger the error is 1/1000 of full scale in the worst case. In other words ADC it will be negligible for the cap > 10nF. Size of the capacitor and resistors determine response speed and may be important if your application have short bursts of large current draw and you want to measure the battery voltage under load.
There's indeed variation in load, when the 3W led is turned on and off. It changes the voltage readings. I have done a " "correction" array so that the red/green bat level indicator gives the same output as when the 3W led is on and off. And the "correction" is different for different levels of PWM on the 3W LED. I used 6 levels of intensity, and each one shows a different voltage reading. I used a multimeter to measure each level when on and off.
As for the resistors, if using the 100K + 100K or 1M + 1M, the capacitor value would be the same? Or is there a "formula to calculate it ?
I'll take readings from 5 to 5 seconds only, and there's no need for great precision. I'll have six bat levels only to display.