LiFePO4 Constant Current charging circuit with micro controller
If your solar panel limits the current to less than the maximum safe charging current then you don't need a current limiter, because the panel already is one!

What you do need is a voltage limiter. The maximum charge voltage for a 4 cell LiFePO4 battery is 14.6V (3.65V/cell). Above this voltage the battery will either become overcharged, or shut down if it has a built in protection circuit module (PCM). 

One way to limit charging voltage is to simply turn the charging current off when the battery voltage reaches the maximum allowed voltage, then turn it on again after the battery voltage drops back down. Assuming you are using an MCU to measure the voltage via an analog input (with suitable voltage divider), you should switch the high side so that battery negative is always connected to common ground. 

The high-side switch can be a P channel power MOSFET rated for at least 30V. The FET is turned on by negative voltage relative to the solar panel's positive terminal, so you need a level shifter (Q1 in the circuit below) to translate the lower voltage (eg. 3.3V or 5V) from your MCU output. This driver also inverts the signal so the FET will turn on when the MCU's output pin is high. Most MOSFETs can only take 20V maximum on the Gate, so for safety its Gate-Source voltage should be limited with a resistor divider and/or Zener diode.        







simulate this circuit &ndash; Schematic created using CircuitLab

If you want to monitor charge and discharge current then you can install a current sensor into either battery lead. This should have low resistance to keep voltage loss down, and to do both charge and discharge it needs to measure current flow in both directions. The ACS712 is a good choice because it has very low insertion resistance, is isolated, measures both positive and negative currents, and its output is biased to half the supply voltage for use with a unipolar ADC. 

At a sensitivity of 185mV/A you would only get about 37 levels per Amp with a 10 bit ADC, so some amplification is probably desirable. How much depends on the ADC's input range and what currents you want to measure. For example if you want 0~5V from +-2A the gain required is 2.5V/(0.185V/A*2A) = 6.76. Using a standard non-inverting opamp circuit the feed back resistors need to have a ratio of (6.76-1) = 5.76:1. The actual values should be high enough to avoid loading down the opamp's output, but not high enough to be affected by bias current or noise.      

More importantly, you should choose an opamp with rail-to-rail outputs and a good input range (preferably also rail to rail), eg. MCP6021. The TL081 is not a good choice for applications like this because it doesn't have rail-to-rail outputs, and its inputs need to be least 3V above the -ve supply. 

CMOS inputs have negligible bias current, so we can choose relatively high value feedback resistors, eg. 10k and 57.6k. Since the Zero Amps reference point is 2.5V we also need to set the amplifier's 'ground' input reference to 2.5V. We can use a resistor divider to derive this from the +5V supply, and by using 2 x 20k they also form the Thevenin equivalent of 10k (this saves one resistor and reduces current draw). Adding a capacitor across the 57.6k feedback resistor reduces the gain to 1 at high frequencies to avoid amplifying noise.







simulate this circuit

To get an accurate Zero Amps value you will probably have to calibrate it (since any zero offset from the ACS712 will amplified by 6.76). This could be done by putting a small value trimpot in the center of the voltage divider to adjust the reference voltage (and reducing the values of R2 and R3 to maintain the total resistance), or by reading the current at some time when the actual Amp draw is known (eg. at startup with charger and load switched off).