I'm using an Arduino to track current coming out of a car battery. I can't work out how to track the current going back into the battery, when it's charging.
To track current flowing out, I've used an LM358 as a non-inverting amplifier to scale the 50mv max across a shunt resistor up to the 5v range the Arduino needs.
When current flows the other way, ie when my charging circuit is at a higher potential than the battery, the voltage across the shunt is negative. How do I read it?
I've tried using the other half of the LM358 (it's two op-amps in one, yay!) as an inverting amplifier but it doesn't seem to work. Does the op-amp need to have +ve and -ve rails (a bit of a problem) rather than +ve and 0v for this to work, or have I got it all mixed up?
Sorry about the sketchy schematic but it shows what I've tried so far. You can see I'm expecting to read load current on a separate ADC pin from charge current. At any one time, one of the inputs will be at 0.
(I've realised that because the Arduino's ground connection happens after the shunt resistor, but my op-amps are grounded before it, there will be a slight offset in the ADC readings but I can live with that. Makes my head hurt to try and work out if this is a more serious problem)
At least the voltage measurement works - as you can see (live!) at http://howiem.com/home ...
I'm new to opamps and new to arduino, and just learned how to play with them in LTSpice.
I fear your approach to measure loading / charging separately does not really help or makes things easier.
Rather add a positive offset, to map 0A current to 2.5V and scale from there to map 30A load to 5V and 30A charge to 0V or whatever your numbers are.
This is just a theroretical simulation, RL is making +-30A max current appear at 9 .. 15 V.
My theoretical opamp is wired to an amplification of ~ 50, no voltages outside 0..5V should appear around it, so any real type should do.
Not sure if you can use a shunt of 0.03 Ohm to get an input of +- 90 mV ( 3 W Power )
These were just the numbers I started playing with. It all is DC, so you can easily measure your actual numbers.
Not sure if real world electrics behave as smooth as the simulation.
Hope this helps anyway.
Playing with LTSpice is fun, too. (Thanks for your question)
Use an artificial "ground" of 2.5V from a resistive divider instead of Rg to ground (replace Rg to ground with a resistive divider made of two resistors of value 2xRg). Then the differential amp's output will be 2.5V for a zero input, greater than 2.5V for negative input and less than 2.5V for positive input. The opamp's inputs will be in the safe range.