Yet Another Battery Charger (YABC)

BradenBurton

New Member
Hi all,
I Know - another Battery Charger :)

I thought I would give a Solar Charger/Controller a go and here are the results.
This is the first time using a micro controller (unless you count the couple of hours with a Basic Stamp 5 Years ago).
This is a VERY BASIC Charger only. All seems to work as a charger. Trying to minimize component count and cost

Calibration/Setup (08M)
Note: Batt+ (I) and Batt+ (II) are actually the same connection but on setup treat them as seperate - they are NOT Connected (there will be a jumper in the final solution)
  1. Put 14V on Batt+(I) while holding down SW1 and then release it once it starts blinking.
  2. Adjust R1 until both LEDs are off (about 4.6V on Pin 3 PICAXE)
  3. Press and release SW1 again - Green LED Should Light (after Red blink)
  4. Put 16-18V on PV+
  5. Adjust R2 until Batt+(II) reads the Float voltage for the battery (add 0.1-0.2V to this reading)
  6. Disconnect Test Voltage supplies and connect to PV and Battery
Notes:
This only has 1 stage - float, but will disconnect if greater than 13.8V and reconnect at below 13.7V.
There should probably be some protection diode at Pin3 to Gnd to stop higher than 5V put on pin.
The LED Bar Connector connects to a 10LED array/LED Driver - SW1 will also actually connect power to this aswell - if it always connected it sucks power like anything.

Just a few Questions:
Please tell me im using the MOSFET correctly in respect with the PICAXE (I know this is a pet peve of some people - and rightly so).

I've been looking at the Solar Panel power curves (IV). I'm not sure about the Voltage Reg as a voltage source (I know better results would come from a switched reg, but that is the next step). Will the panel give as much current it can at the set voltage and drop the V it to give more current, or is it just a set current at a set voltage. If anyone could please point me in the right direction - I can't seem to find it anywhere.

When the battery gets to about 13V (Using a 9Ah SLA for testing) it really slows down its charge (more than I would expect). With no battery connected, point Batt+(II) is set at 14.5V (Cycle Charge Voltage). With battery connected, about 40mA flowing into battery - seems not to go much higher than 13V.

Also any pointers on the code would be useful aswell - but I am hoping that it is ok (246 out of 256 full).

Code:
'' BATTERY CHARGER
''  POWERED BY SOLAR POWER
''     m_ = memory, c_ = constant, i_ = input, o_ = output, p_ = parameter (passed to functions)
''     i, j = general counters for loops



''''' MEMORY 

' bit0 - bit7
symbol m_Charging                   = bit6 ' There seems to be feedback on ADC when PWM
symbol m_PwmInProgress              = bit7 ' There seems to be feedback on ADC when PWM
symbol m_SetupInProgress            = bit5 ' Set when the ShowVoltage is Pressed when startup
symbol m_BatteryActuallyCharging    = bit4 ' There may not be enough sun
Symbol tmpBit                       = bit0 ' Holds Temp Vars


' b1 - b5
symbol i                = b1
symbol m_TimeCounter    = b2 ' used for timing (seconds)
symbol p_ledBlinkCount  = b4
symbol tmpB             = b5 ' just holds tmp vars - 1 to 2 lines code max scope


' w3 - w6
symbol m_VoltagePrev    = w3
symbol m_Voltage        = w4 ' Contains input Voltage ADC [c_VoltageMinADC-c_VoltageMaxADC]
symbol m_LedBars        = w5 ' Contains output Percentage ADC [0-600] -> [0V-3V]
symbol tmpW             = w6 ' just holds tmp vars - 1 to 2 lines code max scope


''''' CONSTANTS
symbol c_VoltageOffset     = 727  ' Taken odd ADC reading to
symbol c_SleepProcessor    = 2  ' x * 2.3sec
symbol c_LedBarShowTime    = 2000 ' How long to display the LED Bar

symbol c_VoltageReferenceADC = 942 ' 14.0V -> 4.60V - ADC Value = 942 - USED FOR SETUP

symbol c_VoltageLedMaxADC    = 851 ' 12.65V -> 4.18V
symbol c_VoltageLedMinADC    = 760 ' 11.3V -> 3.70V
symbol c_VoltageLedThreshold = 855 ' The threshold where it shows the overcharged battery
symbol c_VoltageLedMinADC_O  = 841 ' 12.5V
symbol c_VoltageLedMaxADC_O  = 929 ' 13.8V

symbol c_SlowPulseCharge     = 0   ' Turn the Charger on and off - not overheat the regulaturs

symbol c_ChargerOn           = 922 ' Lowest Float Charge - turn charger on - 13.7V
symbol c_ChargerOff          = 929 ' Highest Float Charge [MUST BE BELOW ACTUAL FLOAT CHARGE] - turn charger off- 13.8V


''''' INPUTS
symbol i_Voltage = 4
symbol i_ShowVoltage = pin3


''''' OUTPUTS
symbol o_LedGeneral   = 0 ' Just a LED for information to the programmer
symbol o_ChargeSwitch = 1 ' Turns the charger on and off
symbol o_PwmVoltage   = 2 ' Pin 5 but pwm 2

symbol o_SetupRed   = 0   ' Startup Led
symbol o_SetupGreen = 1   ' Charger LED - Is INVERSE



''''' BOOTING

Initalize:
    ' Clear Stuff
    let pins = %00000000
    pwmout 2, off
    
        
    ' Check in Setup Mode
    ' If Turned on with Show Voltage Button Pressed - go into Setup Mode
    if i_ShowVoltage = 1 then
        gosub FlashLed
        goto SetupMode ' Infinate Loop
    endif
    
 
    ' Show Normal Boot Sequence
    let p_ledBlinkCount = 6
    gosub FlashLed
        
    ' Show Initial Voltage Display
    readadc10 i_Voltage, m_Voltage
    gosub Calculate
    gosub SetLEDVoltageDisplay
        
    
    
''''' MAIN EVENT LOOP

MainEventLoop:
    ' Indicate a loop start
    let p_ledBlinkCount = 1
    gosub FlashLed
    'pause 1000
    
    ' Load Battery Voltage
    readadc10 i_Voltage, m_Voltage
        
    ' Run Calculations
    gosub Calculate
        

    ' Setup interrupt - Show LED Meter - Sleep ignores it - The interrupt itself does NOT reset it
    if i_ShowVoltage = 1 then ' Change to 0 when using interrupt
        gosub SetLEDVoltageDisplay
        'setint %00001000, %000001000 ' Pin 3
    endif


    ' Turn Charger On/Off
    gosub Charger
    
    'disablebod
    pause 3000 ' c_SleepProcessor
    goto MainEventLoop

    

''''' MAIN FUNCTIONS

Calculate:
    ' Calculate LEDBar Value in percentage of 5V - 0V-3V [0-600] actual output
    
    
    ' Show Normal Battery Charge - Below 12.65V
    if m_Voltage < c_VoltageLedThreshold then
        m_BatteryActuallyCharging = 0
        let tmpW = c_VoltageLedMaxADC - c_VoltageLedMinADC ' Get delta

        let m_LedBars = m_Voltage - c_VoltageLedMinADC * 100 / tmpW * 6 ' The *100 and *6 make it fit within 16bits

        
    else ' Show Charger Battery Voltage - Up to 13.8
        m_BatteryActuallyCharging = 1
        let tmpW = c_VoltageLedMaxADC_O - c_VoltageLedMinADC_O ' Get delta

        let m_LedBars = m_Voltage - c_VoltageLedMinADC_O * 100 / tmpW * 6 ' The *100 and *6 make it fit within 16bits

    endif


    let tmpW = m_LedBars
    let m_LedBars = m_LedBars MAX 650
    let m_LedBars = m_LedBars MIN 80
    
debug


    return


    
Charger:

    if m_Voltage <= c_ChargerOn then 
        let m_Charging = 1
        low o_ChargeSwitch
        let tmpBit = c_SlowPulseCharge
        if tmpBit = 1 then
            pause 5000
            high o_ChargeSwitch
        endif

    endif
    if m_Voltage >= c_ChargerOff then 
        let m_Charging = 0
        high o_ChargeSwitch
    endif 
    return
    
    
SetLEDVoltageDisplay:
Interrupt:
    let m_PwmInProgress = 1
    
    
    if m_BatteryActuallyCharging = 1 then
        high o_LedGeneral
    endif

    pwmout 2 , 249, m_LedBars ' 0V-3V

    pause c_LedBarShowTime
    
    pwmout 2, off
    
    if m_BatteryActuallyCharging = 1 then
        low o_LedGeneral
    endif

    let m_PwmInProgress = 0

    
    return ' Reset in Main Loop

    

    
    
''''' UTILITY FUNCTIONS
    
SetupMode:
    ' Set Main Voltage to 14.0V  - Turn until both leds are off
    '              Red   - Decreade Voltage R1
    '              Green - Increase Voltage R1
    '  NOTE One of the LEDS is Revesed so Low is ON - (Charge Led)
    
    do while i_ShowVoltage = 1 ' Debounce
        high o_LedGeneral    
        pause 100
        low o_LedGeneral
        pause 100
    loop
    pause 100
    
    
    readadc10 i_Voltage, m_Voltage
    if       m_Voltage > c_VoltageReferenceADC then high o_SetupRed
    else  low o_SetupRed
    endif    
    if      m_Voltage < c_VoltageReferenceADC then low o_SetupGreen
    else high o_SetupGreen
    endif

    if i_ShowVoltage = 1 then
        let p_ledBlinkCount = 4
        gosub FlashLed
        low o_ChargeSwitch
        stop
    endif
    
    goto SetupMode
    return
    

    
        
FlashLed:
    for i = 1 to p_ledBlinkCount
        high o_LedGeneral
        pause 100
        low o_LedGeneral
        pause 100
    next
    return
Thanks to all on this forum - I have been watching it for a while now and learning a lot, I only hope I can be of help to others. This is a hobby for me so I have only learn't electronics off the web - I'll create a post with some of the resources I have used - they are really good.
Braden

PS: Sorry about the hand drawn diagram - I havn't found a quick designer yet thats free - I find it a lot quicker by hand (tried Eagle, but too slow for really simple diagrams)


Disclaimer: I am not a Electrical Engineer, this is just a sample circuit - use at your own risk
.
 

Attachments

Last edited:

BeanieBots

Moderator
Your FET is OK as long as it is just for ON & OFF.
Trying to PWM in that way would not work very well.

Not too sure what the LM317 is meant to be doing.
Why bother with any regulation on the PV when you have the PICAXE controlling the battery potential. It just wastes your precious PV resource.

A PV is essentially a constant current source.
The circuit equivalent is a constant current source fed into a 'sloppy' zenner diode of around 17v (for 12v nom. PV) with a highish value resistance across it.
 

BradenBurton

New Member
Thanks for the reply.

Yep, the FET is only a On/Off switch (Not PWM).

And there is my question - I put the LM317 there to get the PV Voltage down do a nice level for the battery (eg. 13-14V). All the PICAXE is doing is switching it on when the battery is below 13.7 and Off when above 13.8 (no PWM - well not in the real meaning). I thought that the voltage you feed into the battery (not the actual reading on the battery while charging) was what was important.

So your telling me there is no need for the Regulator and that the PV will try to feed as much current to the battery while at sloppy 17V (12-14V nominalish) which is ok for most if not all SLA and Lead Acid batteries with no regualtion required at all - as long as it is disconnected at a battery (while charging) voltage of 13.8V

Thanks so much for your reply it has been a help :rolleyes:
Braden
 

BradenBurton

New Member
Current Control

Currently the Panel is matched to the battery (eg. C/10 of battery is 900mA, solar panel about 650mA for voltages 0-14V (10W Panel at peak).

For higher wattage or multiple panels I'm thinking the best way to regulate the current is via a switched regulator in current mode or would this also waste too much power.
I was hoping for a simpler solution with pwm and a mosfet (via picaxe programming) or something (basically a switched regulator anyway) - I guess there is no way around a inductor of some sort is there ?

I could go the resistor way, but I wasn't really wanting large wattage resistors (power loss) and I needed them variable so I can match them to any battery without manual switches for selection.

In commercial controllers what method do they use - if anyone knows, i'll set my learning off in that direction.

Thanks all
Braden
 

sPuDd

New Member
Braden,
I think you'll find that the N-channel MOSFET won't like being used in a high side configuration without the correct drive setup with respect to the source pin. Look up "High Side MOSFET Driver" as an IC, or make one from discrete components. In the attached pdf, High Side for N-channel starts on page 20.

And the LM317 is not required. The battery will regulate quite well, just let the set points do their job.

sPuDd..
 

Attachments

BeanieBots

Moderator
OOPs, didn't spot the N-channel used in a P design.
Well spotted sPuDd.

No, that won't work. Use a P-Fet in that type of circuit.

I don't want to sound too rude here, but you don't seem to understand either the charging requirements of a battery or the nature of a PV circuit.
That will make designing a PV battery charger a little tricky!

As mentioned earlier, a PV can be considered as a constant current.
A Pb battery requires constant current until the 'float' voltage is reached after which constant voltage is required.

If you look in the LM317 datasheet, it has an application circuit which does just that. No need for the PICAXE at all.
OR, use a PICAXE and NOT the 317.

The BEST method is to use a switcher which gets the most out of your PV.
That's a whole different ball-game altogether and has been covered many times on this forum. Do a search for "MPPT".
It is NOT simple and will require a full understanding of how PV work as well as full understanding of Pb charge requirements long before any attempt can be made at designing a MPPT charge controller.
 

BradenBurton

New Member
Thanks sPuDd,
I'll have another look into the workings of the MOSFET, I knew that they needed some sort of driver IC for PWM, but not as a switch. Thanks for the PDF, a bit of reading - will definitely look at and hopefully redesign.
Thanks again
Braden
 

BradenBurton

New Member
Don't worry, that's not rude :)

Heres me thinking I had a reasonable grasp on the whole setup, but obviously not. I really thought I knew the charging requirements of the battery - all the stages and the constant current / constant voltage stages - I was trying to keep it simple at this stage (eg only 1 stage). I have looked high and low for the details of how a PV works in respect to voltages and currents, but nothing so far (everything is just selling PV's or basicly run it through a controller)

I noticed the constant current setup in the LM317 Spec, but thought voltage was more important, will look again

Again, your not being rude - how else will I learn this stuff, just happy you have pointed me in the right direction. As I said before the people on this forum seem to be more helpful than they really should - if that makes any sense.

Will update this thread with any progress - hopefully a more correct design

Thanks
Braden
 

jglenn

Senior Member
There is an easy way to make an efficient (95% maybe), reliable, cheap, and most importantly, SIMPLE solar charger. I did it 2 summers ago, have an 18V panel that puts out a couple amps. You have to aim it at the sun to get the max power.

To charge a 12V batt, consider a float charger, which may only work with lead acid batts, not sure. You set the dc/dc convertor output voltage to the fully charged level of the batt, about 14V. It can put out a couple amps, so if the batt is discharged, will pump in the amps, but when charged, it just "floats" and does not overcharge.

Look up the Sharp PQ1CG3032FZ, a 5 pin power tab kind of package. You will need an inductor, fast recovery diode, a couple caps and res. I use a pot to be able to vary the output voltage, a 20 turn trimpot. Use high freq layout techniques, ground plane pays dividends.

Maybe add a PICAXE for monitoring and steering at the sun tasks! :D
 
Last edited:

BradenBurton

New Member
Hi jglenn,
Well that is exactly what I thought I was doing (Constant Voltage). But it looks like I'm using the MOSFET wrong (still going through the MOSFET Document from sPuDd) and the LM317 was the voltage setter (not a constant current source which is REALLY what it should be doing to get the battery to the float voltage)
The PICAXE is monitoring the voltage (while on charge) and switching it off when at float Voltage.
I was going to do the Constant Current thing next

Thanks for your information and i'll look into the PQ1CG3032FZ (looks interesting), I'm guessing a bit more knowledge on my part first.
 

jglenn

Senior Member
Your concept is basically sound, but may not be optimum for low cost and simplicity. The power supply problem, which a battery charger is a special case, has been solved in the billion lot, every cell phone needs one. Someone else paid to put it on a chip. Why do it with discrete parts? Save your computer for cooler things, add ons that you can't buy in a chip.

I have toyed around with power converters, for fun, and on jobs, that cover 50mW output to more than 20KW. There are many ways to get in trouble with these things, I remember a problem with Volt Second imbalance in some push pull ferrite cores, a transformer running at 50HKz. To247 fets, an array of them.

When the xfmr saturated, in microseconds, the current ramped up to infinity, the fets blew up with the force and sound of a .45 shell. I learned rapidly to wear safety glasses! :cool: Another way to make a solar charger is the linear mode, but that can waste a lot of power, need heat sinks on the transistor.
 

jglenn

Senior Member
Addendum:

On current limiting and regulation. Sure nicads they say to charge at a 1/10 C rate, great. Lead acid may like some fancy 3 mode profile. But you don't really need that for a solar charger. A decent 4 AH or bigger batt will not be hurt by a 2A charge current, as long as it tapers off as it charges, which with a precisely regulated constant voltage, current limited source, it will. For free.

Lead acid are the easiest batts to charge. Nicads and NIMH take more care.
Lithiums are in another ballpark. I like the story of early fast chargers, for Eplanes, which I fly, if you pick the wrong # of cells in the pack, leave it on your computer desk upstairs, and go down to eat dinner, it would light up and burn a hole thru the floor. :eek:
 

BradenBurton

New Member
Hi jglenn,
Yep - I know this simple problem has been solved 1000 times before and i can probably get it for a few dollars (or $50 final boxed solution).

I really took this on as a learning project. I figured this would give me a good introduction to voltages and currents aswell as standard components.

Judging by your experience with other power applications, that is the real reason I don't really want to go near anything inductor like (at least until I get a lot more experience), I know they are just little things, but they can get out of control very quickly if not used correctly - as you know :eek:

Thanks for the comments
 

BeanieBots

Moderator
The PV can only supply a certain amount of current. THAT is your current limit. If that is too much, then either your PV is too big or your battery is too small.
The LM317 does the voltage limit for a single stage Pb charger. The PICAXE is not required.

If you want to use the PICAXE, then lose the LM317.
Have the PV connected direct to the battery.
When the battery gets to float voltage, disconnect the PV.
When it's below flaot voltage, re-connect it.

Current is limited by the PV. Voltage is controlled by the PICAXE.
Absolutley no point doing both. If your LM317 is set to float voltage, it can't go over-voltage so the PICAXE is redundant in such a circuit.
 

Dippy

Moderator
Oh just do a buck.
Constant current, constant voltage, float/trickle whatever you want to call it.
Piece of cake.

Then, after that, you can get BB all aggitated by asking about MPPT. :)
He'll break his slide-rule one of these days.
 

BradenBurton

New Member
Hi BeanieBots,
Yep, that is how I will do version one of this project - once I sort the MOSFET
Looks like the P-FET is the best way to go for a high side load switch (now that I know what a high side load switch actually is). I actually understand them a bit better now - defiantaly no expert though :(
I needed to monitor the voltage for stage 2 of the project which is why I'll go for the PICAXE solution - and it fits into Dippy's idea.

The stupid thing I was doing (as you pointed out and obvious now) was using both for control, but setting the voltage level on the LM317 to about 0.1-0.2V above float and having the PICAXE switch it off at float - which really essentially is what the LM317 is doing anyway - It helps to understand the PV better - that was what confused me with the amount of voltage being supplied by it - I mainly disregarded the current because I knew it was under what the battery would handle, I thought the voltage was too high, but its not:).

@Dippy:
It looks like that is what I may try next - a lot easier than I first thought

@BeanieBots:
Whats a MPPT, and how do I make one.................
... Just kidding BeanieBots I won't anoy you about that.... yet ;)
You can keep that slide rule in one piece for now

@Everyone:
Thanks for the help and a push in the right direction

.
 

BeanieBots

Moderator
Looks like you've got head around it now:)

Dippy is of course right about using a buck regulator.
They are one of the simplest types of switchers to understand and design so could be a good way forward for a future design.

We'll save MPPT for when you have a working buck regulator;)
 
Top