Sorry, I am not explaining clearly.
When you measure the charging current all you are doing is reading the voltage across the 0.22Ω resistor. Using Ohms law, you should drop 0.22 Volts per Amp of current and by using this voltage your software can calculate how many Amps were flowing.
For example, if 1 Amp flows, the resistor will have 0.22V across it, if the current was 3 Amps you would read three times as much, 0.66V.
The ATmega32 has a 10-bit ADC so you can get 1024 different values out of it from zero to ARef (pin 32 voltage which in your schematic is 5V) giving 0x3FF. Assuming you are using ARef and not the internal reference, this means that at the maximum 5A current, the voltage across the resistor will be (5x0.22) = 1.1V which uses less than one quarter of the ADC range. Looking at it the other way around, each change of one digit in the ADC reading equates to just over 22mA of current.
The purpose of the 741 is to amplify the voltage dropped across the resistor so more of the ADC range is used and therefore each step in reading is made smaller. This also makes the in-built inaccuracy of the ADC appear smaller which is good. The drawback is that any noise in the system, including ripple from the rectifiers is also amplified and the sample point of the ADC could catch a peak or dip in the noise, giving random readings.
Two things come to mind - the noise really could be so much that the reading fluctuates or, the ADC is not sampling properly. You say that shorting the input to ground results in an ADC reading of zero, do you mean you shorted out the 0.22Ω resistor at the input to the amplifier or you shorted out the ADC pin on the ATmega?
If shorting out the resistor made the ADC read zero, something is wrong with the resistor or you are reading a voltage drop somewhere else in the wiring. If it only went to zero when pin 20 of the ATmega was grounded, there is noise in the amplifier stage.
I would suggest trying this:
1. Change the amplifier for a better one, I suggest either a TL071 or TL081. These have better performance, lower noise and are direct drop-in replacements.
2. If idea 1 doesn't work, rather than averaging lots of readings, try adding a delay between selecting the ADC channel and taking the measurement. The ATmega only has one ADC and you are switching it between different measurement pins, try selecting the current measurement pin, waiting for 1mS then measuring to see if settling time is the problem.
3. Involves hardware, add a 470Ω resistor in line with the ADC measurement pin on the ATmega and add a capacitor of 100nF from the pin to ground as close as possible to the IC itself. This will electrically filter some of the noise and should help to average out rapid voltage changes.
Let me know the outcome.
Brian.