I've been playing with all kinds of circuits to limit the current when
charging a flat lead acid battery. I've been able to construct a 'dumb'
one with a HEXFET and quad opamp in a lowside configuration
thanks to great advice from the power electronics guru Bob Blick
himself. I also came up with a nice little high-side circuit driven from
a PIC12C508 and a quad opamp.
>From an adaptability point of view, I decided to go for the PIC
solution.
Background :
----------------
Supply is (Vsup) goes to the drain (D) of an IRF530. The source
(S) is connected to the positive side of the battery. The gate (G) is
pulled low with a 4k7 resistor.
To switch G, it is pulled high with a PNP tranny switch by a NPN,
which is switched by the PIC. As the current from D to S increases,
so does the voltage drop over DS because of the (low) internal
channel resistance. Thus the voltage on the positive battery terminal
dips slightly (150mV @ 1.5A typical) when it supplies current. By
measureing this drop, you can know what the current is.
To get this voltage to a more measureable level, you divide Vdrain,
as well as Vsource with similar voltage dividers to get the levels
down to a volt or two. This difference is then amplified by one
opamp in a LM324. The amplified level is compared by two other
opamps. The one will indicate 'overcurrent', and the other will
indicate 'undercurrent'. These outputs are fed to the PIC.
By now all the Bob Blicks of this wolrd will have wondered how
the heck I keep the FET switched on hard. I use two pins as a
charge pump to supply the gate tranny with a voltage 5V higher
than Vsupply. It works well.
To limit the current, I use a 4 bit (16 resolution) pulse train with the
high time variable from 0 (no current) to 15 full current. If the
'overcurrent' input is high, I decrease the high time. If the
'undercurrent' is high, I increase the high time. Every now and again
I invert the two charge pump pins to keep the gate switching supply
up.
When the current direction reverses, the PIC sees it as a very low
load, and swithes the FET on hard.
The Challenge :
---------------------
To get a gate switching frequency between 20kHz and 30kHz using
the 4MHz internal oscillator. This is not trivial and will require a good
few assembly tricks. With non-optimal C code I've been able to get
around 1.5kHz, but (as you can immagine) the circuit screams like a
banshee when you draw a few amps. The FET stays cold even at
loads up to 1.5A!
I AM NOT INTERESTED IN A BATTERY CHARGER CHIP.
It defeats the object of the challenge, and is, above all, 3X the
cost. There is also a diode in the return path which is a killer in low
voltage operation.
I will post the full solution with schematics, source code, and full
credits on my web page.
> To limit the current, I use a 4 bit (16 resolution) pulse train with the
> high time variable from 0 (no current) to 15 full current. If the
> 'overcurrent' input is high, I decrease the high time. If the
> 'undercurrent' is high, I increase the high time. Every now and again
> I invert the two charge pump pins to keep the gate switching supply
> up.
>
> When the current direction reverses, the PIC sees it as a very low
> load, and swithes the FET on hard.
>
> The Challenge :
> ---------------------
> To get a gate switching frequency between 20kHz and 30kHz using
> the 4MHz internal oscillator. This is not trivial and will require a good
> few assembly tricks. With non-optimal C code I've been able to get
> around 1.5kHz, but (as you can immagine) the circuit screams like a
> banshee when you draw a few amps. The FET stays cold even at
> loads up to 1.5A!
<snip>
If I understand you correctly, you basically want a 16-level pwm output
with a frequency somewhere between 20-30 khz from a 16c84(?) running off
of a 4Mhz crystal. If you do the arithmetic, that comes out to between
50 - 33 instruction cycles per pulse. (4Mhz / 4 / 20khz) That's tough!
You might wish to check out my single-cycle resolution 256 level pwm or
32 level pwm:
and try working with them as a start. But these guys are tweaked - it'd
be hell to get them working for your charger (though it would be
killer!).
However, it might be more feasible to implement an intertwined
isochronous routine (iir - okay I made it up). Do you remember Dwayne
Reid's pulse sampling problem a couple of months ago? I don't have time
to elaborate right now, but maybe someone else can (Dwayne?). But
basically, you can get a resolution of about 3 instruction cycles with
the algorithm. So in your case, you could have 16 levels * 3
instructions/level for 48 instructions per pulse. This also gives you 16
instructions per pulse for other processing (like sampling Vds and
determining the next pulse width).
> Very low tec but I mostly use a lamp in series with the battery
> and always have a stock of lamps in my workshop from 5w 12v
> to 55w 24v vehicle lamps.
>
> You can't beat the price and it doubles as a fuse
I use this method to charge the 6V battery on my motor cycle from a 12V
charger.
Light bulbs also make good short circuit testers for automotive use as
well.
> Tjaart van der Walt wrote:
>
> > Hi there
> >
> > I've been playing with all kinds of circuits to limit the current when
> > charging a flat lead acid battery.
> snip
>
> Very low tec but I mostly use a lamp in series with the battery
> and always have a stock of lamps in my workshop from 5w 12v
> to 55w 24v vehicle lamps.
>
> You can't beat the price and it doubles as a fuse
> If I understand you correctly, you basically want a 16-level pwm output
> with a frequency somewhere between 20-30 khz from a 16c84(?) running off
> of a 4Mhz crystal. If you do the arithmetic, that comes out to between
> 50 - 33 instruction cycles per pulse. (4Mhz / 4 / 20khz) That's tough!
> However, it might be more feasible to implement an intertwined
> isochronous routine (iir - okay I made it up). Do you remember Dwayne
I thought that an isochronous approach should work.
> Reid's pulse sampling problem a couple of months ago? I don't have time
> to elaborate right now, but maybe someone else can (Dwayne?). But
> basically, you can get a resolution of about 3 instruction cycles with
> the algorithm. So in your case, you could have 16 levels * 3
> instructions/level for 48 instructions per pulse. This also gives you 16
> instructions per pulse for other processing (like sampling Vds and
> determining the next pulse width).
Just over 20kHz! Dwayne! Give us you input!
I'll post a shematic of the circuit I built later.
I hope this will answer your challenge. This code will produce a pwm
like pulse that maybe sufficient for the purpose. For example, a pwm
value of 0x0A will produce a pulse train of 011000011111111.
BTW, the resolution is 2 cycles which is more than what you ask. The
disadvantages are that the pwm pin must be located at bit 0 or the last
bit of the port and may garble other pins on the same port if used as
outputs due to RLF's.
Regards,
Reggie
;******************************************************************
; 16 bit, 2 cycle pwm
; assumes pwm output pin is in bit 0
;
;
> Hi Tjaart,
>
> I hope this will answer your challenge. This code will produce a pwm
> like pulse that maybe sufficient for the purpose. For example, a pwm
> value of 0x0A will produce a pulse train of 011000011111111.
>
> BTW, the resolution is 2 cycles which is more than what you ask. The
> disadvantages are that the pwm pin must be located at bit 0 or the last
> bit of the port and may garble other pins on the same port if used as
> outputs due to RLF's.
I'v answered this privately, but for the sake of those interested, the PICto be used is a 12C508,
which would make shifting the port left or right
not work becuse you need the other pins too.
It takes 76 us for 1 pulsewidth output which at 4Mhz
equals to a pwm frequency of abt 13kHz.
I have *not* tested the code (which probably means that it doesnt
work :-)
;pw is current pulse width variable (0-F).
;f_outp is outputbit to fet.
;f_overcurrent is input from overcurrent comparator.
;f_undercurrent is input from undercurrent comparator.
;f_cp1 and f_cp2 is charge pump outputs.
init_mainloop
movlw 0
movwf pw
addlw 1
movwf temp
mainloop
decf temp,f
bsf f_outp ;Allways set output on at least 1 instruction.
btfsc f_zero
bcf f_outp ;Switch outp off if pw=0
btfsc f_overcurrent ;If overcurrent is on - decrement pw
decf pw,f
> Hello Tjaart
>
> How about this one.
>
> It takes 76 us for 1 pulsewidth output which at 4Mhz
> equals to a pwm frequency of abt 13kHz.
>
> I have *not* tested the code (which probably means that it doesnt
> work :-)
>
> ;pw is current pulse width variable (0-F).
> ;f_outp is outputbit to fet.
> ;f_overcurrent is input from overcurrent comparator.
> ;f_undercurrent is input from undercurrent comparator.
> ;f_cp1 and f_cp2 is charge pump outputs.
>
This looks very good. I will test it over the weekend or on
Monday. You have already beat me 10 times!
>
> > However, it might be more feasible to implement an intertwined
> > isochronous routine (iir - okay I made it up). Do you remember Dwayne
>
> I thought that an isochronous approach should work.
>
> > Reid's pulse sampling problem a couple of months ago? I don't have time
> > to elaborate right now, but maybe someone else can (Dwayne?). But
> > basically, you can get a resolution of about 3 instruction cycles with
> > the algorithm. So in your case, you could have 16 levels * 3
> > instructions/level for 48 instructions per pulse. This also gives you 16
> > instructions per pulse for other processing (like sampling Vds and
> > determining the next pulse width).
>
> Just over 20kHz! Dwayne! Give us you input!
>
The basic structure is like so:
clrf pw
clrf next_pw
clrf known_zero
start:
bsf pw_port,pw,bit
decfs pw,f ;1
bcf pw_port,pw_bit
movf pw_port,w
decfs pw,f ;2
bcf pw_port,pw_bit
andlw high_current_threshold_bit_mask
decfs pw,f ;3
bcf pw_port,pw_bit
rlf known_zero,w
decfs pw,f ;4
bcf pw_port,pw_bit
subwf next_pw,f ; reduce pw if over threshold
decfs pw,f ;5
bcf pw_port,pw_bit
movf pw_port,w
decfs pw,f ;6
bcf pw_port,pw_bit
andlw low_current_threshold_bit_mask
decfs pw,f ;7
bcf pw_port,pw_bit
rlf known_zero,w
decfs pw,f ;8
bcf pw_port,pw_bit
addwf next_pw,f ; increase pw if under threshold
decfs pw,f ;9
bcf pw_port,pw_bit
bcf next_pw,4 ;in case there was an under|over flow
This is a similar principle to the one I posted earlier. But this has no more
RLF/RRF problems. This also has the same principle as my 2 cycle serial out
routine I posted a month ago. I think this should work right.
;*******************************************************
;Modified PWM routine by Regulus Berdin.
;A pwm value of 0x0A will send a 011000011111111 pulse.
;Assumes pwm pin in bit 0, can be placed anywhere but
; requires little modification in the setup routine.
;
pwm
movf pwm,w ;get pwm
movwf tmp ;work with tmp to preserve pwm
rrf tmp,w ;
xorwf tmp ;convert to delta
rlf tmp2 ;get first bit, put in bit 0
movf PORT,w ;get last pwm pin level
xorwf tmp2 ; convert to delta
btfsc tmp2,0 ;8
xorwf PORT ;bit 0
btfsc tmp,0 ;
xorwf PORT ;bit 1
goto $+1 ;
btfsc tmp,1 ;
xorwf PORT ;bit 2
call delay6 ;8-2=6
btfsc tmp,1 ;
xorwf PORT ;bit 3
>
> Hi Tjaart,
>
> This is a similar principle to the one I posted earlier. But this has no more
> RLF/RRF problems. This also has the same principle as my 2 cycle serial out
> routine I posted a month ago. I think this should work right.
>
> ;*******************************************************
> ;Modified PWM routine by Regulus Berdin.
> ;A pwm value of 0x0A will send a 011000011111111 pulse.
> ;Assumes pwm pin in bit 0, can be placed anywhere but
> ; requires little modification in the setup routine.
> ;
>
> pwm
> movf pwm,w ;get pwm
> movwf tmp ;work with tmp to preserve pwm
> rrf tmp,w ;
> xorwf tmp ;convert to delta
> rlf tmp2 ;get first bit, put in bit 0
> movf PORT,w ;get last pwm pin level
> xorwf tmp2 ; convert to delta
I just looked over the diagram, you had two pins as output.
I think my routine fits perfectly for the application, just change the
movlw 1 to movlw B'11' and retlw 1 to retlw B'11' to work on 2 pins
inverted output. And Just set and clear the two pins, respectively on
the initialization.
I had looked up the diagram. I see that there is a charge pump to
toggle between every cycle. The routine I posted can be modified easily
to accomodate the toggles because there are about 9 free cycles left
which is more than enough.
Below are the changes for my routine to work on your application.
;on the setup/initialization add
bcf GPIO,0 ;initial state
bsf GPIO,1 ;
;replace 'movlw 1' with
movlw B'100' ;set pwm toggle mask
;replace 'call delay6' with
movlw B'11' ;charge pump mask
xorwf GPIO ;toggle charge pump
movlw B'100' ;put back pwm toggle mask
goto $+1 ;delay 2 cycles to complete 6 cycles
;replace 'goto $+1 ;16-4=2' with
nop ;this is my mistake :).
;A delay miscalculation due to
;added 'movlw 1' on my previous correction
On Thu, 17 Sep 1998 20:58:24 +0300 Peter Cousens
<RemoveMEcousensTakeThisOuTspamher.forthnet.gr> writes:
>Tjaart van der Walt wrote:
>
>> Hi there
>>
>> I've been playing with all kinds of circuits to limit the current
>when
>> charging a flat lead acid battery.
>snip
>
>Very low tec but I mostly use a lamp in series with the battery
>and always have a stock of lamps in my workshop from 5w 12v
>to 55w 24v vehicle lamps.
>
>You can't beat the price and it doubles as a fuse
>
>
In fact, I've suggested this to a friend as a way of charging the
batteries in the electric car he's builting. He has 11 12V batteries in
series. The electrical supply here is 120VAC. Residential it's a 240VAC
line with the center tap grounded (neutral). Business, it's a 3 phase Y
with 120 VAC each line to ground (neutral). I've suggested connecting
two or three diodes thru a big light bulb to the positive end of the
batteries. The negative end goes to neutral. He can put a voltage
sensor on there to detect when the battery has reached full charge
(either by setting an end of charge voltage or watching for negative
dv/dt), then drop to a lower wattage light bulb for a float or trickle
charge. Pretty light weight charger.
Harold
_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]
> I've suggested connecting two or three diodes thru a big light bulb to
> the positive end of the batteries. The negative end goes to neutral.
Boy, the utility company will really *love* you! Whole Amps of half-
wave pulses through *each* of their three phases. It probably wouldn't
matter on the domestic system though, but would still be against the
rules.
> Pretty light weight charger.
And hot, inefficient... "Environmentally friendly"?
--
Cheers,
Paul B.
Of course, if we were to put a transformer in front of the diodes, we
could make it weigh a whole lot more and result in the same current
waveform. I agree that it'll probably just clip off the sine wave peaks
on the power line. I've seen some mention of CE rules on harmonic
content, but these seem to be for devices that draw less than 16 amps.
Are there other rules? Are there any US rules on line harmonic content?
>Harold M Hallikainen wrote:
>
>> I've suggested connecting two or three diodes thru a big light bulb
>to
>> the positive end of the batteries. The negative end goes to
>neutral.
>
> Boy, the utility company will really *love* you! Whole Amps of
>half-
>wave pulses through *each* of their three phases. It probably
>wouldn't
>matter on the domestic system though, but would still be against the
>rules.
>
>> Pretty light weight charger.
>
> And hot, inefficient... "Environmentally friendly"?
>--
> Cheers,
> Paul B.
>
_____________________________________________________________________
You don't need to buy Internet access to use free Internet e-mail.
Get completely free e-mail from Juno at http://www.juno.com
Or call Juno at (800) 654-JUNO [654-5866]
<much snipping>
>
>Just over 20kHz! Dwayne! Give us you input!
Sorry for the delay in responding, Tjaart. I've had my head glued in front
of my monitor trying to get some board layouts finished for a project that
ships next week. Thank God for outfits like apcircuits (just 3 hours to the
south of me!).
In the meantime, Scott wrote just about what I would have written (and, in
fact, is quite similar to an 8 step 25KHz PWM motor speed control I
presently use). One thing to watch out for is just WHERE (in time) you
sample the overcurrent. My motor speed control monitors for shorted load
and cuts back to minimum pulse width if a short is detected. I couldn't
sample immediately after turning on the FET drive because of delays in my
gate driver. If I waited too long to sample, I couldn't get my minimum
pulse width low enough to prevent destruction if the short persisted too
long. You may have a similar problem unless you add some form of peak hold
to the overcurrent sense.
I looked at your schematic and was wondering what you are using to control
the battery voltage. Is Vsupply regulated or do you have something else to
set the battery float voltage. Do you worry about equalize mode? My lead
acid chargers stay in equalize mode (7.5 Vdc on a 6V gell cell) until they
drop out of current limit, whereupon they drop down to float mode (6.75
Vdc). They switch to equalize mode both on powerup and anytime the charger
goes back into current limit.
I also see that the circuit appears to be set up as battery backup with
automatic change over - the battery powers Vsupply thru the intrinsic back
diode in the FET when Vsupply drops more than 1 diode drop below the
battery. I assume this is intentional.
I'm looking forward to hearing about the final result. Good luck!
Why is the d.c. component on the mains system limited?
> Boy, the utility company will really *love* you! Whole Amps of half-
> wave pulses through *each* of their three phases. It probably wouldn't
> matter on the domestic system though, but would still be against the
> rules.
>
> > Pretty light weight charger.
>
> And hot, inefficient... "Environmentally friendly"?
> --
> Cheers,
> Paul B.
> On Thu, 17 Sep 1998 20:58:24 +0300 Peter Cousens
> <cousensSTOPspamspam_OUTher.forthnet.gr> writes:
> >Tjaart van der Walt wrote:
> >
> >> Hi there
> >>
> >> I've been playing with all kinds of circuits to limit the current
> >when
> >> charging a flat lead acid battery.
> >snip
> >
> >Very low tec but I mostly use a lamp in series with the battery
> >and always have a stock of lamps in my workshop from 5w 12v
> >to 55w 24v vehicle lamps.
> >
> >You can't beat the price and it doubles as a fuse
> >
> >
>
> In fact, I've suggested this to a friend as a way of charging the
> batteries in the electric car he's builting. He has 11 12V batteries in
> series. The electrical supply here is 120VAC. Residential it's a 240VAC
> line with the center tap grounded (neutral). Business, it's a 3 phase Y
> with 120 VAC each line to ground (neutral). I've suggested connecting
> two or three diodes thru a big light bulb to the positive end of the
> batteries. The negative end goes to neutral. He can put a voltage
> sensor on there to detect when the battery has reached full charge
> (either by setting an end of charge voltage or watching for negative
> dv/dt), then drop to a lower wattage light bulb for a float or trickle
> charge. Pretty light weight charger.
This doens't satisfy the most important requirement (and the reason
for the whole project) of no heat. Put this globe in a box, and you'll
have an instant fire hazard. Put a battery charger chip board, and
the cost will make your boss so angry you'd be fired! ;)
Seriously, this circuit can charge up to 14A (dependant on your
MOSFET) If you use a IRLU024 instead of the IR530, you'd
have very little heat because it is guaranteed to be fully switched
at Vgs = 5V.
The only thing bothering me about the circuit at the moment is
whether I'd need a NPN tranny on the gate to switch it off hard.
I haven't been able to test it at high enough currents for this to be
a problem.
> Tjaart van der Walt wrote:
>
> <much snipping>
> >
> >Just over 20kHz! Dwayne! Give us you input!
>
> Sorry for the delay in responding, Tjaart. I've had my head glued in front
> of my monitor trying to get some board layouts finished for a project that
> ships next week. Thank God for outfits like apcircuits (just 3 hours to the
> south of me!).
>
> In the meantime, Scott wrote just about what I would have written (and, in
> fact, is quite similar to an 8 step 25KHz PWM motor speed control I
> presently use). One thing to watch out for is just WHERE (in time) you
> sample the overcurrent.
Ha! you saw the pitfall! Because I am just comparing the average drop, Ican check for overcurrent
(or undercurrent) anywhere in the loop. I had to
average the drop with a resistor and cap because I switch the MOSFET
hard on.
> My motor speed control monitors for shorted load
> and cuts back to minimum pulse width if a short is detected. I couldn't
> sample immediately after turning on the FET drive because of delays in my
> gate driver. If I waited too long to sample, I couldn't get my minimum
> pulse width low enough to prevent destruction if the short persisted too
> long. You may have a similar problem unless you add some form of peak hold
> to the overcurrent sense.
I am thinking about forcing the PIC into some sort of a waiting state. If the pulsewidth runs down
to zero, it must wait a few seconds before trying again. I will
have to play with this idea first because I think an inrush current could confuse
the poor 12C508 of of it's tiny mind...
> I looked at your schematic and was wondering what you are using to control
> the battery voltage. Is Vsupply regulated or do you have something else to
> set the battery float voltage.
Yep, the supply is pretty well regulated at 6.7V (or something, I'll have to check)with a switcher.
> Do you worry about equalize mode? My lead
> acid chargers stay in equalize mode (7.5 Vdc on a 6V gell cell) until they
> drop out of current limit, whereupon they drop down to float mode (6.75
> Vdc). They switch to equalize mode both on powerup and anytime the charger
> goes back into current limit.
I'm not sure what equalize mode is. Please tell me more.
> I also see that the circuit appears to be set up as battery backup with
> automatic change over - the battery powers Vsupply thru the intrinsic back
> diode in the FET when Vsupply drops more than 1 diode drop below the
> battery. I assume this is intentional.
Yes. This is also the reason for the undercurrent sensing. As soon as the currentdirection changes,
the PIC sees a undercurrent and keeps the FET switched on
hard.
I hit upon the idea of using the FET's channel as a 'shunt' to measure the
current flow when I was paging through a datasheet. I won't claim being the
first to try it, because I am sure someone else has thought about it before me.
This, and the fact that you can charge the battery to supply AND use the
battery without a diode drop makes it quite handy (I think so, anyway!)
Tjaart van der Walt wrote:
snip
>
> Ha! you saw the pitfall! Because I am just comparing the average drop, Ican ch
eck for overcurrent
> (or undercurrent) anywhere in the loop. I had to
> average the drop with a resistor and cap because I switch the MOSFET
> hard on.
I can't see how this is going to work ?
Your I/voltage drop will be swamped buy the pwm off voltage and will
be 99% dependant on your pwm mark/space
ie: when the fet is off it looks like your drawing lots of amps
I know you don't want additional heat but a resistor will probably be
the
best (with the opamp you only need very low Ohms)
> Tjaart van der Walt wrote:
> snip
> >
> > Ha! you saw the pitfall! Because I am just comparing the average drop, Ican check for overcurrent
> > (or undercurrent) anywhere in the loop. I had to
> > average the drop with a resistor and cap because I switch the MOSFET
> > hard on.
>
> I can't see how this is going to work ?
> Your I/voltage drop will be swamped buy the pwm off voltage and will
> be 99% dependant on your pwm mark/space
> ie: when the fet is off it looks like your drawing lots of amps
>
> I know you don't want additional heat but a resistor will probably be
> the
> best (with the opamp you only need very low Ohms)
The LM324 works down to 0V. I need the divider to bring the
voltages within the input range of the opamp. When the MOSFET
is on, the output of the opamp goes high. This difference is averaged
over the complete cycle.
> I can't see how this is going to work ?
> Your I/voltage drop will be swamped buy the pwm off voltage and will
> be 99% dependant on your pwm mark/space
> ie: when the fet is off it looks like your drawing lots of amps
I shouldn't answer email first thing in the morning
(I'm still asleep)
I've just seen the diode D5
I only printed out the left half of the page
So ignore my last message
PS: Tjaart thats not a very clear diagram, the colors really make
it messy
--
Peter Cousens
email: TakeThisOuTcousensKILLspamspamher.forthnet.gr phone: + 3081 380534
snailmail: Folia, Agia Fotini, Karteros, Heraklion Crete, Greece.
Is it true? that they have, on the new version of windows
managed to increase the MTBF from 95 to 98 minutes
(Thats why they called it 95)
> Ruben Jvnsson wrote:
>
> > Hello Tjaart
> >
> > How about this one.
> >
> > It takes 76 us for 1 pulsewidth output which at 4Mhz
> > equals to a pwm frequency of abt 13kHz.
> >
> > I have *not* tested the code (which probably means that it doesnt
> > work :-)
> >
> > ;pw is current pulse width variable (0-F).
> > ;f_outp is outputbit to fet.
> > ;f_overcurrent is input from overcurrent comparator.
> > ;f_undercurrent is input from undercurrent comparator.
> > ;f_cp1 and f_cp2 is charge pump outputs.
> >
>
> This looks very good. I will test it over the weekend or on
> Monday. You have already beat me 10 times!
Hello Tjaart.
Here is anotherone for your battery charger.
It has a pwm frequency of 31 kHz @ 4MHz.
It uses 17 different functions, all taking
exactly 32 instruction cycles (32 us).
There is one function for every possible
pwm output, ranging from pwm output off all
32 cycles to pwm output on all 32 cycles in
17 steps.
Each function sets and clears the pwm output
according to the table below.
pwm_0 can loop back to itself if undercurrent
and overcurrent inputs are 0, or to pwm_1 if
undercurrent input is 1.
pwm_1 to pwm_15 can loop back to itself if
undercurrent and overcurrent inputs are 0,
to pwm_-1 if overcurrent input is 1 or to
pwm_+1 if undercurrent is 1.
pwm_16 can loop back to istelf if undercurrent
and overcurrent inputs are 0 or to pwm_15 if
overcurrent input is 1.
pwm_12, pwm_14 and pwm_15 doesn't have its
positive edge for the pwm output same as the
other functions because at the end of the loop
there are some instruction groups that can't
have a bcf f_outp inserted into them. The
average output is correct and I don't think
this is any problem.
As you can see, there are a lot of nop's in
every function which probably means that they
can be changed so the pwm frequency is
increased to over 50 kHz. (The instructions
that does anything are less than 16!).
Also: 2 nop's can be replaced with 1 goto $+1
and 4 nop's can be replaced with a call to
a return instruction to reduce the size of
the code. It is however simpler to understand
with nop's and code size isn't any problem
if the 12C508 shouldn't do anything else.
Function Instruction cycle/pwm output
---------------------------------------
00000000001111111111222222222233
01224567890123456789012345678901
Example of one of the 17 functions. The others are
the same except for that the bsf f_outp and bcf_foutp
is at different places. (pwm_14 and pwm_15 must have
2 bcf f_outp - one as the first instruction.)
The functoins use no ram (not even W) or flags.
; Code Cycle Coment
; ---------------------- -- ----------------------------------------
pwm_1
bsf f_outp ;0 Set pwm output high
nop ;1
bcf f_outp ;2
bsf f_cp1 ;3 Set charge pump output 1 high
bcf f_cp2 ;4 Set charge pump output 2 low
nop ;5
nop ;6
nop ;7
nop ;8
nop ;9
nop ;10
nop ;11
nop ;12
nop ;13
nop ;14
nop ;15
nop ;16
nop ;17
nop ;18
bcf f_cp1 ;19 Set charge pump output 1 low
bcf f_cp2 ;20 Set charge pump output 2 high
nop ;21
nop ;22
nop ;23
btfsc f_undercurrent ;24
goto 1_change_to_2 ;25,26 Change to pwm_2 if not enough
current
nop ;26
btfsc f_overcurrent ;27
goto 1_change_to_0 ;28,29 Change to pwm_0 if too much
current
nop ;29
goto pwm_1 ;30,31 Loop back to pwm_1
1_change_to_2
nop ;27 Put in nop delays so the function still
nop ;28 takes 32 us.
nop ;29
goto pwm_2 ;30,31
1_change_to_0
goto pwm_0 ;30,31
The instructions bs/cf f_cp1, bs/cf f_cp2 could be replaced
with a xorwf gpio,f if w holds the bitmask for (cp1 | cp2)
but it makes the code more sensitive to EMC disturbance
because the outputs are never set to a known absolute value.
> Peter Cousens wrote:
>
> > Tjaart van der Walt wrote:
> > snip
> > >
> > > Ha! you saw the pitfall! Because I am just comparing the average drop, Ica
n check for overcurrent
> > > (or undercurrent) anywhere in the loop. I had to
> > > average the drop with a resistor and cap because I switch the MOSFET
> > > hard on.
> >
> > I can't see how this is going to work ?
> > Your I/voltage drop will be swamped buy the pwm off voltage and will
> > be 99% dependant on your pwm mark/space
> > ie: when the fet is off it looks like your drawing lots of amps
> >
As I was riding home Friday and thinking about this, I fell into that same
trap.
>
> The LM324 works down to 0V. I need the divider to bring the
> voltages within the input range of the opamp. When the MOSFET
> is on, the output of the opamp goes high. This difference is averaged
> over the complete cycle.
>
Or to state it differently, when the MOSFET is off the LM324's output is
low and D5 has no effect on the low-pass Ra/Ca/Cb filter. When the MOSFET
is on and Vsupply is being driven by the external source, the output of
the opamp will still be driven low, but not all the way to ground. If
there is a whole lot of current flowing through the FET (and hence a
relatively large voltage) the opamp's output will be driven lower still.
Thus it appears that the sensing signal Vdrop varies in the opposite
direction to the current flowing into the battery (i.e. as I goes up,
Vdrop goes down).
This is clever, but I would imagine you would still need to be careful not
to mistake a turned off MOSFET for a large current flow.
In another message, you express some concern about turning the MOSFET off
hard. In your current schematic, the turn off is controlled by a 10k
resistor. I'm not sure how big Cgs or Vgsth of the 530 are, but I think
I'd be concerned too. (I mean this is supposed to be a perfect charger,
right?) One circuit I have found that works well for capacitive drive is
a simple push-pull:
^
|
|/
+--| NPN
| |\
| v
| |
in --+ +---- out
| |
| v
| |/
+--| PNP
|\
|
|
---
///
This circuit can be thought of as a current amplifier. It has two
benefits: 1) it reduces the amount of loading on the signal driving 'in'
and 2) it provides a relatively low impedance for driving 'out'.
Battery stuff:
It appears that you're treating the battery like a baby: feed it until it
quits crying. However, batteries like babies can spout from many orifices
if overfed. Lead acids are pretty resilient, however if this charger is
intended for 'trickle-charging' too you will have to monitor the terminal
voltage. If you don't, the battery's life will be reduced. Also, you
currently have no way of disconnecting the load from the battery. This
means you will be susceptible to deep discharge (unless the regulator
protects you by shutting off for an undervoltage case - which I doubt).
Finally, if you monitor the terminal voltage don't forget that it is
temperature dependent.
Scott
PS. I should be working on gpsim instead... Version 0.0.5 was released
today (on the gnupic mailing list).
>In another message, you express some concern about turning the MOSFET off
>hard. In your current schematic, the turn off is controlled by a 10k
>resistor. I'm not sure how big Cgs or Vgsth of the 530 are, but I think
>I'd be concerned too. (I mean this is supposed to be a perfect charger,
>right?) One circuit I have found that works well for capacitive drive is
>a simple push-pull:
>
>
> ^
> |
> |/
> +--| NPN
> | |\
> | v
> | |
>in --+ +---- out
> | |
> | v
> | |/
> +--| PNP
> |\
> |
> |
> ---
> ///
Almost exactly right! I would connect the collector of the PNP transistor
to the FET's Source terminal - there is no need to swing the gate below S
and doing so only wastes some of that precious boost supply. Tjaart - you
should be able to use this in place of your PNP transistor and 10K pulldown
resistor. The 4K7 resistor in the collector of the NPN transistor sets how
much current is drawn from the battery thru the forward biased B-C junction
while the NPN is conducting - it might be prudent to increase that 4K7
resistor somewhat. Also note that the PWM output from the PIC now becomes
inverted (exactly like mine is!) and the 100K pulldown resistor you have on
the base of the NPN transistor to GND should now go to VDD.
It looks you now have several different pieces of code to try. I'm looking
forward to hearing how it all owrks out.
>> I looked at your schematic and was wondering what you are using to control
>> the battery voltage. Is Vsupply regulated or do you have something else to
>> set the battery float voltage.
>
>Yep, the supply is pretty well regulated at 6.7V (or something, I'll have
to check)with a switcher.
>
>> Do you worry about equalize mode? My lead
>> acid chargers stay in equalize mode (7.5 Vdc on a 6V gell cell) until they
>> drop out of current limit, whereupon they drop down to float mode (6.75
>> Vdc). They switch to equalize mode both on powerup and anytime the charger
>> goes back into current limit.
>
>I'm not sure what equalize mode is. Please tell me more.
Lead acid batteries have 2 different charging parameters. The voltage can
stay permanently at the float voltage: if the battery is heavily discharged,
it charges at that voltage and reaches probably 75% of full charge
relatively quickly. Once the charge current starts to drop off, the battery
takes many hours or days (at float voltage) to reach 100% charge.
Equalize mode causes the battery to hold the charge voltage (and current)
high until the battery becomes near to 100% charged. In essence, if you put
a current limited voltage supply set at the equalize voltage across a
discharged battery, the slope of the charge curve (% full charge) remains
relatively constant until the battery is full charged. BUT - if you KEEP
the voltage at the equalize level for an extended time, the battery
overcharges, begins to vent, and becomes permamently damaged.
You say that you are using a regualted 6.7 Vdc switch mode supply. I think
that should be just fine. Just remember that the last 25% or so of the
battery's capacity will take substantially longer to be charged than the
first 75% or so.
Couple of other thoughts: how does your 6.7V switcher react when being
backfed by the battery? Will that cause startup problems for it? What kind
of loading does the supply have internally - how much current is it going to
draw from the battery? Just something to check out.
Scott mentioned another concern: do have or need any mechanism to prevent
the battery from becoming too deeply discharged? If this is a concern, I
have a couple of suggestions. First, put another N-channel FET in series
with the (-) lead of the battery. This FET is driven by your low voltage
dropout detector (another section of op-amp using VDD as the refernce). Now
that you have this normally on FET in the negative lead of the battery, use
it as your current sense. It would reduce the problem of getting rid of the
PWM swings your existing filter has to deal with. Of course, if deep
discharge is NOT a concern, don't do this . . . ;)
> > The LM324 works down to 0V. I need the divider to bring the
> > voltages within the input range of the opamp. When the MOSFET
> > is on, the output of the opamp goes high. This difference is averaged
> > over the complete cycle.
> >
>
> Or to state it differently, when the MOSFET is off the LM324's output is
> low and D5 has no effect on the low-pass Ra/Ca/Cb filter. When the MOSFET
> is on and Vsupply is being driven by the external source, the output of
> the opamp will still be driven low, but not all the way to ground. If
> there is a whole lot of current flowing through the FET (and hence a
> relatively large voltage) the opamp's output will be driven lower still.
> Thus it appears that the sensing signal Vdrop varies in the opposite
> direction to the current flowing into the battery (i.e. as I goes up,
> Vdrop goes down).
>
> This is clever, but I would imagine you would still need to be careful not
> to mistake a turned off MOSFET for a large current flow.
This is part of the challenge. To make PWM work on a PIC is trivial. Tocompare two inputs are also trivial.
To toggle the two charge pump pins
is probably the 'Hello world' equivalent on a PIC. To make it work
outside the audio band from a 4MHz clock is not so trivial.
I initially got a limiter going with just a quad opamp and the MOSFET,
but it had some shortcomings that the PIC can overcome.
> In another message, you express some concern about turning the MOSFET off
> hard. In your current schematic, the turn off is controlled by a 10k
You'e quite right - 10k is too big. I had a peek at the breadboard and sawthat I actually used a 2k2. I
will test it at higher currents, and if I get too
much heat, I'll use an open collector transistor to zap the gate down.
> resistor. I'm not sure how big Cgs or Vgsth of the 530 are, but I think
> I'd be concerned too. (I mean this is supposed to be a perfect charger,
> right?) One circuit I have found that works well for capacitive drive is
> a simple push-pull:
It would have to be driven from Q3's collector, because the supply for theswitching transistor is 5V (minus
bridge drops) above Vsupply. This means
I can't switch the high side transistor off with my 5V output from the PIC.
> It appears that you're treating the battery like a baby: feed it until it
> quits crying. However, batteries like babies can spout from many orifices
> if overfed. Lead acids are pretty resilient, however if this charger is
> intended for 'trickle-charging' too you will have to monitor the terminal
> voltage. If you don't, the battery's life will be reduced. Also, you
> currently have no way of disconnecting the load from the battery. This
> means you will be susceptible to deep discharge (unless the regulator
> protects you by shutting off for an undervoltage case - which I doubt).
You are right again. We use the Hawker Cyclon lead acid gels( http://www.hepi.com/ ), so we don't have
problems with deep discharges.
It can also take a massive charge current without pressure build-up.
Having said all of that, I don't think I will charge it at more than 1A-1.5A.
I thought that most PIClisters have some sort of project where they could
do with current limiting and bidirectional current flow, so I decided to make
it a group effort.
> Equalize mode causes the battery to hold the charge voltage (and current)
> high until the battery becomes near to 100% charged. In essence, if you put
> a current limited voltage supply set at the equalize voltage across a
> discharged battery, the slope of the charge curve (% full charge) remains
> relatively constant until the battery is full charged. BUT - if you KEEP
> the voltage at the equalize level for an extended time, the battery
> overcharges, begins to vent, and becomes permamently damaged.
How pronounced is this in a gel battery (like the Hawker (previously Gates))batteries?
> You say that you are using a regualted 6.7 Vdc switch mode supply. I think
> that should be just fine. Just remember that the last 25% or so of the
> battery's capacity will take substantially longer to be charged than the
> first 75% or so.
>
> Couple of other thoughts: how does your 6.7V switcher react when being
> backfed by the battery? Will that cause startup problems for it? What kind
> of loading does the supply have internally - how much current is it going to
> draw from the battery? Just something to check out.
Hmmm. Now that I have done away with the series diode, I might have openedanother can-o-worms. I'll
check the specs.