Friday, July 5, 2013

A simple, effective, yet inefficient solar charge controller.

A friend of mine had an immediate need for a way to safely charge a lead-acid battery from a 29 volt solar panel.  Because it was the evening before he was to leave - and there was NO WAY to get a commercially-made controller either via post or from a local source - he asked me to throw something together in a hurry.

This was in preparation for a week of vehicle camping while providing enough power for a CPAP machine or two and to keep cell phones and cameras charged, but because the use of a generator was not allowed charging the battery that way was just out of the question.  The power usage of the CPAP machine was rather significant (1-2 amps while running) so a fairly large solar panel - and a decently large storage battery - was required in order to maintain a positive energy budget over the period.

A quick back-of-the-envelope calculation showed that for 8 hours of operation of a single CPAP machine and the charging of a cell phone, at least 30 watts of available energy would be required, taking into account the charge efficiency of a typical battery and the fact that whatever panel one chose it would, on average, only produce about 60% of its peak power during daylight hours - assuming a nice, clear southern view of the sky with minimal obstruction toward the east or west and the occasional cloudiness.

To that end, he obtained a 215 watt solar panel at a very good price - much more than twice the capacity than what was actually needed, but it was likely to provide the energy budget even on a cloudy day - were it used efficiently.  Again, on such short notice a suitable charge controller that could handle the panel's output (about 9 amps at 29 volts) wasn't available.  Very quickly I saw that without a highly-efficient (switching-type MPPT) controller I would be able to utilize less than half of the panel's wattage, but it looked as though there would be more than enough current.

"What if I were to use this with a '12 volt' panel?"

That would be preferable, of course!  The panel that my friend obtained would not be usable for only this particular outing, but for future plans on a small solar energy farm at his home.

If one were to use the descrived charge controller with a "12 volt" solar panel (e.g. one with an open-circuit voltage of about 16-20 volts instead of around 39 volts) that would place the "optimum" power point of the panel closer to 14 volts.  In this case, this sort of simple on/off controller would be be able to capture much more of the panel's total available power since the "voltage mismatch" between it and the battery would be far less.

Read more about "optimum power" elsewhere in the article, below.

Figure 1:
The charge controller with connecting leads.

Controlling current flow without heat:

Here's the thing about efficiently switching current on and off:  If you have a switch, you need to have it firmly "on" so that the current flowing through it doesn't generate heat due to resistance - and a high-current power FET will do this nicely.  The one that I chose had no more than 0.02 ohms of "ON" resistance and with 10 amps, this would produce a measly 2 watts of heat.  Conversely, when the FET is off it isn't passing any current at all so it isn't even thinking about getting hot.

It's in that "in-between" state that the problem lies:  If there is resistance - say, from the FET not being turned on fully - the FET will immediately get hot and if one can't get rid of that heat, it will be destroyed.  One must switch the FET on and off quickly so that it spends as little time in that "in-between" state as possible.

On my first version of this controller using a TL431, this could happen fast enough that the FET was being turned on/off very quickly, spending too much of its time midway between "on" and "off" and getting hot.  After a few initial attempts to slow things down with the addition of some capacitors and adding a bit of hysteresis using a few resistors, I realized that in order to make it work it would have to get more complicated, so I decided to scrap the initial version for something "simpler."

Instead, I would use a computer!  See the diagram in Figure 3.

At first glance it would seem that the use of a computer was not going in the direction of avoiding complexity, but standing back for a moment let's take a look at what is needed for a simple PIC microcontroller-based solar charge controller:
  • A PIC.  I would use the 8-pin PIC12F683 which has an onboard A/D converter, watchdog timer and clock oscillator.
  • A voltage regulator.  To allow the PIC to run from the 12 volt battery being charged, I would use a 78L05 to provide 5 volts which I would also use as a voltage reference.
  • A power FET.  This would be used to connect/disconnect the solar panel from the battery, depending on the state-of-charge (voltage) on the battery.
  • A status LED.  Just because I could, I decided to use a red/green LED to indicate that the unit was powered up and actually doing something.  Separate LEDs could be used if that's all you have.
  • Other circuitry.  There was a 10-turn potentiometer for voltage calibration, a pair of transistors to drive the FET and a few miscellaneous resistors and capacitors.
The real magic was to be done in software and I decided to make it work like this:
  • Measure the voltage on the battery.
  • If the battery voltage is above 13.8 volts, disconnect the solar panel from the battery and make the status LED glow green.  Wait for at least 1/2 second before doing anything else - such as reconnecting the solar panel for additional charging.
  • If the battery voltage is below 13.2 volts, connect the solar panel to the battery and wait for at least 1/1000th of a second before doing anything else to the battery.  When in this state, make the LED glow red for at least 1/20th of a second (even if the battery was disconnected 1/1000th of a second later) so that even a brief flash would be more visible.
  • Every 5 seconds, the charging switch (FET Q3) would be opened and the device will measure the solar panel's open-circuit voltage.  If it was too low - which would happen if there was no sun - the unit would stop charging and indicate this to the user by briefly flashing the LED yellow every 2 seconds.
In other words, the unit could immediately (after 1/1000th of a second) disconnect the solar panel from the battery if the voltage on the battery were above the "full charge" voltage, but it would wait for at least 1/2 second before deciding to reconnect the solar panel if the battery were too low.   

(Note:  Practically speaking, R1/R2 and C3 slow the response to the changing voltage somewhat so it probably doesn't respond quite as fast as 1/1000ths of a second.)

Figure 2:
A close-up view of the controller in its protective case.

The reason for the immediate response if the voltage were on the high side would be to minimize the time that the battery and/or the equipment connected to it was exposed to voltages that might be in excess of, say, 14 volts.  If the battery to which the unit is connected, this is unlikely since the capacitance of the battery alone - not to mention the electrochemical processes - would prevent the voltage from increasing too rapidly.

The reason for the 1/2 second delay if the voltage were on the low site would be to allow the battery voltage to settle down when the charging current was removed, but also to prevent the FET from being turned on and off too quickly and too frequently.  As we know from above, if the FET is fully on or off it's not going to generate much heat at all and by minimizing the rate at which it will switch between those states, heat generation can be minimized.

These two thresholds (13.2 and 13.8 volts) weren't chosen by accident.  If a healthy 12 volt lead acid battery ever does reach 13.8 volts, it is guaranteed to be at least mostly (if not fully) charged. If this same battery is allowed to "float" (e.g. no load) at this same charge level, it will take some time to drift back down to 13.2 volts. If the battery still has a bit of charging to do it will rather quickly drop back down to (and below) 13.2 volts - particularly if there is a load.

Figure 3.
Schematic diagram of the solar charge controller.  The circuit shown is intended for
"12 volt" (6-cell) lead-acid batteries.
It can be constructed using the PIC12F675 instead - see notes, below.
See notes and text for additional details about this circuit and its use.
Click on the image for a larger version.

So, there you have it, a very simple charge controller!

The .HEX files for programming a processor yourself:

Two .HEX files have been produced:  One for the PIC12F683 as described in the text, and another using the PIC12F675.  These files are NOT interchangeable or likely to be appropriate for other devices.

For the .HEX files, go to the page indicated by the link, below:
Web page with .HEX files for solar charge controller  (link)

If you cannot program a processor yourself and are interested in obtaining one, contact me.

Additional comments:

How it's connected to the battery:

As can be seen in Figure 1 large alligator clips are used to connect the battery.  Because the FET switch is in the negative lead, the positive terminal of the battery and the positive terminal of the solar panel are connected together at the battery.  It is recommended that short, heavy leads connect this unit directly to the battery to maximize charge efficiency and to best allow the controller itself to measure the battery voltage:  Long, skinny leads would cause a voltage drop, making the unit "think" that the battery was more-fully charged than it actually was.

A few warnings about the battery connection:

Because there is not extensive protection against high or reverse-applied voltages it is recommended that one connect the charge controller to the battery and then connect the solar panel, and when you are done, do the reverse - disconnect the solar panel then disconnect the battery.

Another extremely important point:  Make certain that the device being powered by the battery is firmly connected to the battery!

Because this device could put the full solar panel voltage across the terminals (in this case, 39 volts) a 12 volt device could be destroyed immediately by over voltage!  If you are using a battery that is in any sort of reasonable condition, this should never happen, but if your battery connections were loose - say, you had alligator clips from the device being powered connected to the battery and you had alligator clips from the charger connected to those clips - and the first set were to accidentally fall off, you could destroy your devices.

It is for this reason that you should always use the "permanent" connections to the battery to connect your devices (e.g. the battery posts.) so that you cannot accidentally have a connection to the solar panel without having the battery in the circuit.

Also, there's no "high-voltage" disconnect to protect the battery and the connected devices should the charge controller accidentally get "stuck" (due to the FET being damaged by lightning, for example) in the "on" state and continually applying current to the battery.  If this were to happen it is likely that the battery could be destroyed by gross over charging and the devices attached to it may be damaged as well.  In this circuit, the FET is reasonably well-protected against such things, certainly not against a very nearby or direct hit!

Explanation of the voltage thresholds:

In software, the battery is connected if its voltage drops below 13.2 volts and is disconnected if the voltage is higher than 13.8 volts:  In between these two voltages, the state is undetermined:  If the voltage had been below 13.2 volts, the panel will be connected (to charge the battery) but if the voltage had been above 13.8 volts, the panel will be disconnected.  Generally speaking, the panel will be connected as soon as the voltage is applied since it is unlikely that a battery that had been sitting for more than a few hours and not connected to a charger as its voltage will likely be well below 13.2 volts.

One could also use this same circuit for charging 6 volt and 24 volt systems as the ratio of the two voltages (on and off) would be correct for lead-acid batteries in this situations, too.  To do this, one may have to select an appropriate value for R1 as well as take into consideration the fact that U1, the voltage regulator, may not operate properly.

For example, at 6 volts unless a low-dropout regulator were used, or one used a different regulator to operate U2 at a lower voltage - say, 3.3-4 volts.  For 24 volts it may be wise to use a regulator that can withstand high voltages (>30 volts) for U1 or put in series with it a 10-15 volt Zener diode, taking care to leave the "top" end of R1 at the battery potential.   If you do change the voltage a which the PIC operates, you'll need to take into account that the voltage scaling resistors (R1/R2 for the battery voltage and R10/R11 used for monitoring the solar panel's open circuit voltage) are appropriately adjusted.

For other types of batteries (e.g. lithium-ion, NiCd or NiMH) this same sort of scheme could also be used, but very different charge-control schemes and voltage thresholds would have to be used to do this safely and this would imply a modification of the code.  Especially if you have several different types of battery chemistries, you may be better off having a small-ish lead-acid 12 volt battery to which these other chargers are connected to function as a low impedance "ballast".

In other words:  Do not use this circuit for any battery types other than lead-acid!

Why switch the panel in/out via its negative lead?

For this design I decided to put the power switching transistor in the negative lead of the solar panel rather than the positive lead and the reason for this is simple:  It was easier to do!

To have put it in the positive lead would have required one of two things:
  • The generation of a "boost" voltage.  I could have used an N-channel FET between the solar panel positive lead and and the battery's positive lead, but I would have trouble driving it.  The reason for this is that in order to turn on an N-channel FET fully, I would need to apply a gate voltage that would be at least 5-10 volts higher than the battery voltage.  Unfortunately, we cannot use the higher open-circuit solar panel voltage for this because if the FET were turned fully on, our solar panel V+ voltage would be the same as the battery V+ voltage.  In order to make this work we'd need to have a circuit that would generate a voltage that was higher than the positive battery voltage.
  • The use of a complementary device.  I could have used an opposite-polarity device such as a P-Channel power FET.  By doing so I could have "pulled down" on the gate/base and turned on the transistor, but there's a problem:  P-Channel FETs are harder to find, a bit more expensive, and typically have higher "ON" resistance than their N-Channel counterparts.  In other words, you can more easily and cheaply find N-channel FETs.
Why use a FET instead of a bipolar transistor in the first place?  Power FETs have the nice property that if you elevate the gate potential far enough "above" the source potential, they essentially turn into a low-loss "on" switch without requiring any drive current.  A bipolar power transistor, on the other hand, would require 1-5 percent (or more!) of the total device current being drawn through its base lead to make it fully conduct, and it would still drop more voltage across it and generate more heat than a FET.

Again, by switching the negative lead of the solar panel I could use a standard N-Channel FET:  Since the source lead of that FET would be pulled down and "away" from the +12 volt terminal of the battery (even to a potential that is negative with respect to the battery minus lead) by the solar panel - and since the PNP driving it was at the battery + potential, we already had a ready-made source of drive voltage for it.

How the circuit works:

U1, a 78LO5 3-terminal voltage regulator supplies a clean source of 5 volts for the microcontroller - and also serves as the voltage reference to determine the charge state of the battery.  The raw battery voltage is scaled first with R1 and then with potentiometer R2, the latter being adjustable so that the "on" and "off" thresholds for charging can be calibrated.

If U2, the PIC12F683 (or PIC12F675) microcontroller sees that the voltage is too low (nominally below 13.2 volts) its sets pin 5 (GP2) high which turns on NPN transistor Q1 which, in turn, pulls "down" on the base of PNP transistor, Q2 to turn it on.  Resistor R4 limits the base current in both Q1 and Q2 while R3 guarantees that if U2's output is in a high-impedance state (such as during startup) that Q1 is turned off by default:  R5 performs a similar function for Q2, respectively as well as speeding up the rate at which it can be turned "off".

When Q2 is turned on, approximately "Batt+" volts (nominally the battery voltage - in the 12-13 volt area) appears at its collector which pulls up on the junction of R7 and R8 which, if the sun is shining, was already at a voltage that is equal to the open-circuit output voltage of the solar panel minus the battery's present terminal voltage:  In the case of the solar panels chosen, the open-circuit, full-sun voltage is around 39 volts so if the battery is at 12.5 volts, the drain of Q3 will have been at -26.5 volts with respect to "ground" - the negative terminal of the battery, or close to the full 39 volts of the solar panel's open circuit voltage.

Pulling the gate of Q3 "upwards" (e.g. making it positive) will turn it on, connecting the negative lead of the solar panel to the negative battery lead.  At this point the gate voltage will drop to about 12-13 volts, but this is sufficient to keep the device chosen fully turned on.  Because the gate-source voltage could conceivably exceed 20 volts or so - the (typical) maximum rating for such a device at the instant that we turn it on - Zener diode D1 in conjunction with R7 form a simple shunt regulator to limit its maximum voltage to a safe level.

Once the voltage rises above 13.8 volts, U2, the controller, sets Pin 5 low which turns off Q1 and Q2 and allows R6 to pull Q3's gate voltage down to its source voltage and turn it off, disconnecting the solar panel from the battery.  C4, a 0.1uF capacitor, is placed across the FET so that any "ringing" or transients generated by the FET's being turned on and off are suppressed as well as providing a degree of RFI and static protection.

For this circuit to work properly, Q2 must be rated for the voltages that it will encounter so an MPSA55 was used which has a rating of 60 volts.  Q3 must also be rated for the expected voltage, low "on" resistance and several times the maximum current expected from the panel so a 100 volt, 50+ amp device was used to provide plenty of margin.

The reason for the use of both Q1 and Q2 is so that one can apply the battery voltage to the gate of Q3 when it is "on" to make certain that its resistance (and loss) is as low as possible:  Were Q2 driven directly by U2, we could only attach its emitter to the +5 volt supply and it was turned on, only about 5 volts could have been applied to Q3's gate which, for "normal" N-channel power FETs, may not be enough to drive it into full conduction and minimize its ON resistance.

In looking at Figure 1 and Figure 2 you may note that there is no obvious heat sink on Q3.  In actual operation, with 5-9 amps of current, it ran only very slightly warm but there was plenty of convection coupling (air cooling) as well as heat conduction via the heavy wire (#10-#12 AWG) that was soldered directly to the tab of Q3, its Drain lead which, in turn, connects to the negative lead of the battery.

Added later (after the pictures were taken) is the circuit consisting of R10, R11 and C5.  Forming a voltage divider, this allows the measurement of the voltage across the solar panel when Q3 is turned OFF to determine if there is any usable light falling on the solar panel.  If there is not, the computer will keep the solar panel disconnected and occasionally flash LED1 yellow to indicate that there's presently no power available from the solar panel.  To do make this determination while it is charging (e.g. the LED is red) the panel will occasionally be disconnected for a very brief moment to measure the voltage across the panel.  Of course, if it is not charging (LED is green) it doesn't need to disconnect the solar panel at all to make this reading.

If the panel is being illuminated and Q3 is off, the "Panel -" voltage will go negative with respect to the PIC's ground and via R11, pull U2, pin 6 down from the +5 volt supply   If the voltage on pin 6 of U2 is below about 4.0 volts when the panel is disconnected via Q3 - which indicates that the panel is capable of providing at least some charging current - we know that it is worth attempting to charge the panel.  If the voltage is higher than 4.0 volts when the panel is disconnected via Q3 we can safely assume that there is too little light to bother with and this will put the controller in a mode where it will not attempt to charge the panel and cause the LED to flash yellow every two seconds or so.  (If you have two separate LEDs, both will flash at the same time.)

Calculating the value of R11:

Note that the value of R11 should be chosen for the type of panel to be used.  Nominally, the voltage at pin 6 of U2 should be 4 volts (or lower) at the voltage at which the panel outputs maximum power (this is usually listed in the specs) and R11 should be high enough that at when the panel is open-circuit in full sun, that maximum voltage (often noted as "Voc" in the specs) is not high enough to try to drag pin 6 below ground.

On the diagram are two values shown:  33k for a panel typically used to charge 12 volt batteries directly (e.g. maximum power at around 14-17 volts, 24 volts open-circuit, maximum) and 68k for the panels that we used here (29 volts at maximum power, 39 volts or so open-circuit.)  On the diagram the formula:

R11 = (( Voc - Vbatt ) + 4 ) / 0.000213

Is given.  Since the supply voltage is 5 volts - and we want 4 volts at Pin 6, we want 1 volt of drop across R10 which yields approximately 213 microamps as noted in the above equation.  Kirkhoff's law dictates that the same current must flow through R11 to obtain that same voltage drop across R10 so we add 4 volts to the difference between our expected solar panel open-circuit voltage and get about 31k:  33k is chosen since that is the nearest common resistor value, yielding a "low voltage cutoff" of about 16 volts open-circuit panel voltage.

The "Vbatt" term is one that we must approximate:  If we used precision, fixed resistors for R1/R2 we would know the precise divisor ratio and be able to calculate the battery voltage and subtract it from the open-circuit panel voltage - but since this circuit doesn't do that, we must pick R11 to suit our needs.  In general, if we assume Vbatt to be 13.2 volts, the charge-cutoff circuitry will work fine for a "12 volt" lead-acid battery regardless of its charge state - as long as it is above 6 volts or so since we must have at least enough battery voltage to power our PIC circuit.

  • Charging a completely dead battery:  If you were to have this circuit connected to a completely dead battery, charging would never start since the PIC would not be powered from the battery.  Were this to happen - and the solar panel was producing power - one would temporarily connect the Panel - and the Battery - connections together to provide a "bootstrap" charge to the battery.  It may take several minutes for the battery to have enough charge voltage to keep the circuit operational - and this would be true only if the battery was good.  A few warnings if you do this:  Disconnect EVERYTHING ELSE from the battery as it may be bad, and the full panel voltage may appear across the battery if you connect it directly to the panel.  If you do connect the panel directly to the battery, do not walk away - keep monitoring the voltage until it reaches the low-mid 12 volt area.  Finally, be careful when connecting/disconnecting battery connections as sparks may cause hydrogen/oxygen gas explosions.
  • If you were to use a 29 volt panel to charge a 12 volt battery (read below about the efficiency losses in doing so!) there would be no harm in keeping the battery connected if that panel's open circuit were allowed to drop to 16 volts or so - as might happen at dawn/dusk or if the panel were partially shaded or damaged.  At 29 volts, however, the voltage a pin 6 will attempt to go negative, but diodes within U2 will prevent it from going much below -0.6 volts.  While in some cases this excursion beyond the supply rails can cause unexpected effects on the PIC's A/D input MUX and affect other A/D channels, that did not seem to occur in the prototype and it functioned fine - but your results may differ.
  • When in "Inhibit charge" mode (e.g. open-circuit panel voltage too low and charging is discontinued) the prototype, using a 78L05, consumed about 5.5 mA average battery current.  Much of this is the quiescent current of the voltage regulator, but some of it is also the LED occasionally flashing yellow to indicate that it is in a "not charging" mode.  When charging, the circuit will consume around 25 mA, most of this being drawn by the LED and the circuitry that turns on Q3.

Set-up notes:

Setting this circuit up is slightly tricky, but not difficult if instructions are followed.
  • As noted above, please be aware of the hazards associated with high voltage and/or current!
  • Preset R2 to the middle of its range.
  • Connect a variable voltage power supply across the Battery (+) and Battery (-) terminals and set it for 13.20 volts.
  • When first connected, the LED will cycle Green-Red-Yellow if you are using a dual-color LED.  It may then be either a solid color, of flashing.  If it cycles RED-Green-Yellow the LED's leads are reversed!  If you used separate LEDs instead of a single, dual-color LED, both will be on instead of displaying yellow.
  • Make sure that the LED(s) is/are properly connected and/or identified via the power-up color sequence.  The colors represent:  Red = charging, Green = not charging, Yellow (brief flash) = Charging voltage not available.
  • With the power supply connected across Battery (+) and Battery (-) set to precisely 13.2 volts, adjust R2 so that the voltage on its wiper (which is also connected to Pin 7 of U2) is 51.6% of the 5 volt power supply's voltage.  If the power supply were precisely 5.0 volts, this would be 2.58 volts.  It is normal for the output of the 78L05 regulator to be between 4.9 and 5.1 volts due to manufacturing tolerances:  It is recommended that you measure it precisely and calculate the 51.6% voltage.  This sets the charge cut-in threshold voltage.
  • If you set the power supply voltage to precisely 13.8 volts, the voltage measured on U2 pin 7 would be 54.0% of the PIC's 5 volt supply voltage, or 2.70 volts.  This is the charge cut-out threshold voltage.
Operation notes:
  • Using the value specified for R11 (33k), if the battery voltage is 13.2 volts and the open-circuit solar panel voltage is below 16 volts, the unit will determine that there is not enough energy from the panel to effectively charge it and in this mode, the LED will be mostly dark, flashing yellow every 2 seconds.  (If you used separate LEDs, they would both light up during the flash.)  Every 5 seconds during charging, the unit will open Q3 and briefly measure the voltage - a process that takes less than 100 milliseconds.
  • If the open-circuit panel voltage is above 16 volts, normal charging will occur with Q3 being closed.  If the battery is discharged and its terminal voltage is below 13.2 volts, the LED will glow red.
  • Once the battery voltage has exceeded 13.8 volts, charging will be stopped, Q3 will be opened and the LED will glow green.
  • Once a battery has achieved full charge, it is normal for the LED to be mostly green, occasionally flashing red - perhaps as often as twice per second.  It is also normal for the voltage to stabilize near 13.2 volts and slowly move upwards over a period of hours or days:  At 13.2 volts, a 12 volt lead-acid battery is "mostly" charged.  Because this controller can only turn charging "on" or "off", it is rather difficult to precisely obtain a charge voltage.
If lead-acid batteries are used other than 12 volt lead-acid, the above steps would be modified accordingly, but note the following:
  • The input to U1, the 78L05, must be at least 6.5 volts for the circuit to work properly.
  • U1 cannot tolerate much above 30 volts, so accommodations must be made if this can happen to protect it.
  • Keep in mind the voltage ratings of Q2 and Q3:  The rating of each should be at least the battery voltage plus the open-circuit panel voltage for a good safety margin.
  • If a different voltage panel is used you will need to properly calculate the value of R11 as noted elsewhere in this text.
  • R2 would be adjusted to 51.6% of the 5 volt supply to set the threshold for the battery voltage  below which charging would be started.  Again, the termination of the charge occurs at 54.0% of the 5 volt supply.  If the battery voltage is increased, it may be convenient to increase the value of R1 appropriately to better-scale the threshold voltages within R2's adjustment span.

"No diode in series with the panel?!?"

It should be noted that there's no "reverse polarity" diode in shown on the diagram as being in series with the controller to prevent the battery's charge from being applied to the panel when the sun is absent.  As it happens, almost all modern, manufactured panels have these diodes built in, anyway - but it would be a good idea to closely check the specifications.

If, when you connect your panel (shaded from the sun, or in the dark) across your battery and you see more than a few 10's of milliamps flowing into the panel then you might consider adding a series diode to prevent this.

More Comments:
  • While an "MPPT" controller (see the very last section of this article, "By the way, what's an MPPT charge controller?" below, for an explanation) would have been nice, this just wasn't going to happen on such short notice so I threw together a simple "on/off" voltage controller to allow current to be safely thrown at the battery without worrying too much about overcharging it.
  • Charging a battery from a solar panel with a voltage that far exceeds the requirements is very inefficient.  As noted above, if one used a normal "12 volt" panel (those with an open-circuit voltage in the 17-22 volt area) this short of charging is much more efficient.
  • If you build/use this controller for yourself, remember that there are no guarantees that this circuit is either effective or safe.  YOU are responsible for becoming familiar with and implementing the appropriate safety measures and dealing with hazards associated with high voltages and/or currents.
  • Not shown in the diagrams/pictures are necessary fuses and other protection that one must include in a practical installation.

By the way, what's an "MPPT" charge controller?

The charge controller described here simply connect the solar panel to the battery to charge and then disconnects it when the battery has achieved full charge - essentially similar to the "old-fashioned" way solar panel chargers used to work.  Because the solar panel acts as a source of current, it doesn't really care if its output is shorted out or left open.

Given that our hypothetical solar panel that will output 9 amps at 29 volts we can see that at that voltage we could extract (9 amps * 29 volts =) 261 watts from it, but if we were to short out the panel we would get zero watts (e.g. 0 volts * 9 amps = 0 watts.)

With this on/off switch connecting/disconnecting our battery, we will obviously get 9 amps into the battery, but if the battery were at 13 volts and charging, that would only be (9 amps * 13 volts =) 117 watts of power - this, from a panel that could provide much more than this at a higher voltage.

Clearly we are leaving 144 watts "on the table" somewhere, so how would we make use of it?  One way would have been to charge two 12 volt batteries in series (for 24 volts) which would have yielded 234 watts (e.g. 9 amps * 26 volts assuming 13 volts per battery = 234 watts).  This is much better, but our equipment doesn't actually run on 24 volts and it would be awkward to drag along two 12 volt batteries, anyway.

The way around this is to have an intelligent switching voltage converter.

The way this works is that it has a computer (digital or analog) that will figure out, on the fly, how much current it can pull from the solar panel and automatically calculate the amount of power being pulled at the same time by doing the standards "volts*amps" calculation.

One way to do this is to slightly adjust the switching voltage converter - a circuit that can efficiently convert a higher voltage at lower amperage to a lower voltage at a higher amperage - so that it tries to output a little more current which, in turn, would cause the input to attempt to pull a little more current from the solar panel.  When it does this it does the "Volts * Amps = Watts" calculation of power  and if, when it increased the current being pulled from the panel, it actually did get more power, it would try to pull still more current from the panel, incrementally.

If, for some reason, the "volts * amps = watts" calculation showed that there was actually less power available when we attempted to increase the draw from the solar panel by trying to pull too much current and/or the solar panel's output has dropped due to cloudiness, setting sun and/or shading, it would incrementally back off on how much power it tried to pull - and keep doing so until it got to the point at which it, again, got to the maximum output from the panel.

In doing this slight incremental up/down and "feeling" to see if there is more power available from the solar panel, we would be able to extract the maximum amount of power from the panel based on the conditions at that instant.  This type of controller is called an "MPPT" or "Maximum Power Point Tracking" - so called because it constantly adjust itself and tracks the conditions of the charge source (the solar panel) to determine the maximum power that can be extracted from the solar panel and delivered to the load.


This page stolen from


  1. hello..if it is not a problem for you..i would like to ask for the hex file..because im keen to do this project as it is interesting and is challenging to construct

  2. First of all, thanks for the info that you've posted! It will certainly be a help to me as I attempt to build a solar charge controller of my own.

    Secondly I have a question that I hope answer. I'm just a beginning electronics hobbyist so it's probably just a misunderstanding on my part. I'm having trouble understanding how the R10 & R11 voltage divider helps you to measure the solar panel voltage. I can see that R10 is connected to the output from the 7805 so I would guess that the PIC pin 6 (GP1) would always measure some fraction of +5VDC and wouldn't necessarily have any correlation to the solar panel voltage. Or maybe that's your voltage reference? If so what is PIC pin 4 (GP3) used for?

    Thanks in advance!

    1. This comment has been removed by the author.

  3. You are right that the 7805 is used as the main voltage reference. The R10/R11 divider will measure the panel voltage *only* if Q3 is turned off and because that voltage goes negative with respect to the "ground" on the PIC, the R10/R11 voltage divider is configured so that the voltage is always positive and the precise open circuit voltage of the panel could, in theory, be calculated as an increasingly-negative voltage from the panel will drag the voltage down toward ground. You would have to take into account the battery voltage in making the calculation (e.g. the battery voltage plus the voltage difference between ground and the panel's V-) - but this is a computer, so that's easy to do!

    When the battery is fully charged, Q3 is open most of the time so measuring the open circuit panel voltage is pretty easy. When charging, however, it is necessary to occasionally (and briefly) turn off Q3 so that the open circuit panel voltage can be measured - a hundred milliseconds or so is all that is needed.

    Another function of pin 4 is the source of Vpp - the 13 volt (or so) programming pulse used when downloading code to this processor, so it must *never* go above Vdd or else the processor will do strange things.

    Perhaps because it must tolerate the Vpp pulses, this pin cannot be used as an output and it does not have a pull-up resistor, therefore it must be tied to either Vdd or Vss if it is not used. In addition to a general-purpose digital input, it could also be configured as !MCLR - a master reset, but I didn't configure it that way in this case.

    I chose to tie it to Vdd in the event that I might, in the future, enable !MCLR, but since the PIC has some built-in start-up circuitry of its own to assure that it will run - even if the voltage source is slow-rising, I probably don't need to use !MCLR.

  4. dear sir,
    Iam sudhindra vu3pwt from india. Kindly send the hex file and charge controller circuit.

  5. Hi,

    I want to know what happens to N-Channel Mosfet Q3's internal body diode, when the Mosfet is turned OFF, Panel current will continue flow into to Battery thru this body diode, Isn't it ? Or am i wrong ?

    1. For an N-channel FET that is turned off, current will not flow if the source is more negative than the drain.

      In the case of this circuit, an open-circuit solar panel will produce more voltage than the battery being charged: With the positive lead of the solar panel being permanently connected to the battery positive lead, the panel's negative lead would therefore be more negative than the battery's negative post.

      I could have designed this circuit with a FET in the positive lead - and this is admittedly a bit more intuitive at first glance. To make this work, however, I would have had to do one of the following:

      - Use a P-Channel FET. This would be wired with the source connected to the panel V+ and the charge controller would drag the FET's gate toward ground. The caution here is that one must put protection on the FET's gate - as was done in the above circuit - to keep the gate within 20 volts of the source lead or the FET would likely be damaged due to excess gate-source potential. I chose not use a P-Channel FET because N-channel FETs are far more common and generally less expensive.

      - Use an N-channel FET in the positive lead - the drain connected to the solar panel positive lead. The problem with doing this is that in order to turn on the FET, one must make the gate more positive by 10 volts or so than its source so this would require that one generate a voltage source that is always!

      It is mentioned in the post that current will flow backwards through the FET's intrinsic diode if there are not blocking diodes in an unilluminated solar panel, but most panels intended for charging batteries, those designed to be paralleled or those referred to as "shadow tolerant" typically have diodes already wired in. If your panel doesn't have a diode, or you are not sure if it does, then it's a fairly simple matter of covering the panel to prevent it from producing any current and connect it to the same voltage of battery as you intend to charge with a means of measuring current connected in series with one of its leads.

      Thanks for asking!

  6. As you may noticed, .HEX files for both the PIC12F675 and PIC12F683 have been made available.

    Good luck!

  7. thanks for a Excellent PIC based project, I was about to settle for NE555 based solar charge controller when I found this.
    With PIC already available with me I am more keen in building this to charge my 12V 150Ah battery.
    however I am in need to exactly know how many 12v 10W panel should I order to be able to charge the Heavy Home Inverter Battery.

    many thanks again for the excellent circuit and full explanation.


  8. Hi there! It's been almost a year after I asked my first question about this circuit, and now I'm back! I'm determined to build this project soon, and as such I'm determined to understand it entirely. I think that I now have a basic understanding of why your method of measuring the Voc works, but I'm having difficulties with your calculation for R11. No matter what values I choose for Voc & Vbatt, I'm just not getting anywhere near the 33K (or "about 31K" as you noted) or 68K using the formula that's provided.

    Can you let me know what values specifically you're using for Voc & Vbatt to arrive at the R11 value? I'm sorry to seem so dense, but I want to understand it and I'm just not getting anything near the same values.


    1. Hi Charlie,

      If I rewrite the equation and substitute 13.2 volts for Vbatt for a nominal battery voltage I get 23.684 volts for Voc when R11 = 68k and 16.229 volts when R11 = 33k.

      At least 23.7 volts should be expected if there is a reasonable amount of light falling on a "29 volt" solar panel when it is open circuit, so it is probably worth attempting to charge from it. Similarly, if you see at least 16.2 volts from an open-circuit "12-15 volt" solar panel then it will likely have at least some usable output.

      Remember that the idea here is that, when Q3 is open, will pull the bottom end of R11 down, the voltage across Q1 being the difference between the open circuit voltage and the battery voltage.

      When the junction of R10/R11 drops below 4 volts with Q3 open this will indicate that the open circuit voltage is adequate to attempt charging. Since we need only know "Voc" approximately to be able to determine if the panel is illuminated, we have a fair bit of latitude in this measurement and need only know Vbatt approximately as well.

  9. Hi KA7OEI.

    What do you mean by A simple, effective, yet inefficient solar charge controller! Specially the word inefficient.

    1. The section of this article, "By the way, what's an 'MPPT' charge controller?" explains the problem in detail.

  10. Hi KA7OEI,
    What is the maximum wattage of PV in 12v setup? And 24v setup?

  11. This circuit is known to handle the so-called "29 volt" (at maximum power) panels, which have a nearly 40 volt open-circuit voltage. For charging 24 volt battery systems, I wouldn't use higher than the same "29 volt" panels as that would exceed the voltage rating of the specified transistors and the capability of the U1, the voltage regulator.

  12. This comment has been removed by a blog administrator.

  13. Hi KA7OEI, would you be adding the MPPT feature to the solar charge controller in the near future ?

    1. This project was never envisioned to include MPPT, but if I were to design an MPPT solar controller, it would be a completely separate project - 'dunno when I might get around to that.

      Thanks for asking.



While I DO appreciate comments, those comments that are just vehicles to other web sites without substantial content in their own right WILL NOT be posted!

If you include a link in your comment that simply points to advertisements or a commercial web page, it WILL be rejected as SPAM!