TomGeorge:
Hi, I need to ask.
-
have you developed this program step by step, that is did you get the analog read and measuring the charge on the cap going first, then once that worked got the autorange implemented, if not then I suggest you start again. If you did can you show us some working sketches.
-
Why are you not measuring charge /discharge volts from the junction of the cap and charge/discharge resistors.
-
Is the reason for having the end of the cap connected to pin 13 so you can avoid diodes.
-
I also think that you will not get a capacitor fully discharged due to volt drop on switching components in arduino.
-
Can you tell me the pin status when you are charging the cap, if pin 13 is high then the analog voltage measurement will be 1023 all the time, if you move the analog input to where I suggest in 2) the voltage will be the charging volts but approaching 0 as it charges, to do that you will have to pull the charge pin low, but what about the influence of the other charge pins being held high?
Tom, I have already addressed all the points you raised in your first post , including the position of the AnalogRead connection and a discharge current limiting resistor.
Guilty as charged for bells and whistles, but of course I did start with a working sketch and always posted results.(see my previous)
Your statement 5) is just wrong. With my connection, the analogRead will only approach 1023 when the capacitor is almost fully charged. Its a question of timescale.
The last part of the statement makes no sense to me. There is only one charge pin and during charge it is set OUTPUT and HIGH.
A new basic skeltch is needed avoiding discharge to 0v. and rapid rate of charging except through multiMeg resistors.
In this post sketch I start by charging a cap to 5v. and then monitor leakage voltage.
As the voltage leaks to earth, “my connection” voltage falls from 1023, (see results)
Your connection does not vary from about 6 (see results-tom’s connx) over 61 loops while my
Connection falls from 5v. to 1v.
Remember that your connection is on the positive side of a 100k resistor pinned to earth (0v.)
Charge is going to leak from the positive plate.
Also the charge/discharge currents are flowing to both plates in the same (but charge opposite to discharge) direction,.
AnalogRead is measuring the voltage referenced to earth of the positive end of the 100k resistor
in your case, but including the ESR of the capacitor in my connection.
Kirchoff’s law does not apply to a charging or discharging capacitor ie not in equilibrium.
So plate currents do not have to be the same.
The charge leaks from the positive plate and its current is falling exponential. Not so the negative plate.
Lets stick to evidence based assertions.
pgc sketch to measure capacitance ranging over 2 ranges.
0-0.5 uF and 0.5-50000 uF (more if you are patient and increase charge time)
theory.
new revision switch ranging cap meter
Measures the time taken to leak discharge from 5v (sensorvalue1023) to 1v.(sensorvalue202)
uses the equation, T = -RC ln(V/Vo)
and C = -T/Rln(V/Vo) where C is farads T is seconds R is ohms.
thus C = -T/(Rln0.2) = T/(R*2.39)
prototype uses charge earth pin9 only
notes- It works,but it needs a "leak resistor" of 2Meg or switchable 4Meg permanently across the cap
Without this resistor I used finger touch across the cap to discharge it slowly.The led dimmed and went out and the
1v. level was triggered,but of course that is not quantitative.
(Curiously after I removed my finger, the led very slowly came back to full brightness.[could use for measurement of 0 to 63% charge])
I think this is leakage in the “charge” direction via the Arduino pins to the positive plate.(not seen with leakage resistor In place)
If ChargeGroundPin9 is set to INPUT, the 1v. trigger level is not detected, even if the capacitor starts off charged.
The 2 or 4 Meg resistor "underswamps" the inherant leakage resistance and can be used in the above equation to calculate the capacitance. (taking regard to the leak resistance value chosen)
Inspection of results shows that arduino detects my range of trigger points culminating in loop61
SensorValue 199 and ElapsedTime 4021 for my test capacitor of 0.33 uF
Loop time is about 150 Ms
The results are using a 2Meg leak resistor. With the 4Meg it takes about twice the loops and gives twice the ElapsedTime.
Mk6_cap_meter.ino (2.81 KB)
cap_meter_Mk6_pgc.pdf (53.4 KB)