I want to charge capacitor (1F/5,5V) by my Arduino's Duemilanove PWM output. I have already accomplished that, but now I want to have control over charging current - simply by controlling the PWM.
My problem is getting the charging current value. I'm getting really weird readings, ie. 0.5mA while my (really cheap asian make) multimeter tells me 2.5 - 5mA or I can even get negative numbers (???).
I have everything connected as the image describes
with D9 as PWM charging A0 as capacitor voltage reading (and "after" resistor voltage) A1 to get voltage "before" the resistor (other parts are for discharging the capacitor and are driven by program)
Code is simple
cap_current_value = (analogRead(1) - analogRead(0)) * 1000 * 5 / (float)56 / (float)1024;
I get difference from both reading, which is voltage "lost" on resistor, divide by 1024 and multiply by 5 (both is done to convert to volts), then divide by 56 (ohms - the resistor)and multiply by 1000 (to get mA).
But why do I get such bad result? Right now the capacitor is charging at 3mA and I get reading of 0.263mA from Arduino.
Any help is greatly appreciated.