Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Friends, help to find out the bug of this charger

Not open for further replies.


Full Member level 4
Jul 16, 2007
Reaction score
Trophy points
Activity points
I've added the schematic and bascom codes for the whole thing. Now I am a bit confused about the reset pin. also I am not sure about the fuse bits for this uC.

External crystal at 10mhz. and the whole thing is a 12v charger that will do 13.8v and 14.6v. the code is self explanatory. so help me to find the bug. I am getting nothing here... please...


charger at pb137

What is the scematic drawn in, Can't open it

upload jepg or pdf format

pb137 battery charger circuit

it was in target3001 program. anyway, i've given the pdf too...

guys, I need the reply... in a serious trouble...

What a mess!!!

It looks like a very badly designed power supply but it is so badly drawn it's difficult to tell.

Anyway, I would guess, not knowing any of the voltages, that nothing is coming out because there's no way of controlling Q3 bias current.


I've had a quick look at the drawing and the code,
I think you need to go back to the drawing board, Like Brian siad the schematic is a mess it's hard to tell whaat is what, It's not the best way to do it the way your trying to control the LM317 and Q3.

Sorry to say your design would not work very good and I would not trust it with my batteries. I woudl use a PID or PWM routine to control the vlotage and the current, There are lots of thing that you have to think about with battery chargers, like current limit,voltage control tempitaure of the battery this all depends on what type of battery your trying to charge.
Have a look here This was also published in EPE you still can get the back issues. I found this very interesting reading and give lots of info.

Here some things that I woudl try first, Have you tried by just putting 5V on your 3 inputs this would manually control the charger the same way the AVR does, this then tells you if it's your hardware or your code. But do some more searching on battery charging

That's my 2 cents worth

i know it is a complete mess. because i am using the CAD just for me... once I can finish the buildup, that's the end... anyway, let me explain a bit...

The goal is to charge a 12V 7A Lead Acid Batt of my bike in two stage... not 3 stage. One is with constant voltage (step 2 of 3 step..) at 14.6V. Once the current consumptions drops below 500mA, it will switch to 13.8V and keep floating.

The bridge will get around 16-20VAC 5-6A current. that will goto 12V and 5V rail also. Next is: lm338. It is a 5A voltage regulator. I'm setting two pot R3, R2 for this job. one will set the 14.6V and other will 13.8V. But inorder to get them work, the ckt must be full, means then must be connected to one at ADJ pin of 338 and other at GND. so I am planning to use the Mega32 to drive the transistor as a switch to turn on either one of the pots of the desired. Also i'm using the TIP2955 as a high current switch between the load and the source. So when the mega32 will turn on, it will wait for 3 sec (thus no voltage at load for 3sec after first power up) and then it'll bias the transistor for passing the current. [i'm not doing the current limitation here because 338 will already not allow more than 5A].

R4 is a .1ohm 5W current sensing shunt. it'll be connected to one of the adc of mega32 and thus i can get the current [High side is the adc voltage and low side is 0 since shunt's location]. so then i can decide for current pass and then i can decide on 14.6v or float. and the PA1 is nothing but to show me the batt terminal voltage. the resistor voltage devider used here is to scale down the voltage from 20V to 5V.

The JP5 is a jumper (basically a spst switch) for display mode. one detals mode, another just a battery charge progress symbol.

JP6 is for calibration. on turning on of any of the pin, it will go to calibration mode for 14.6 or 13.8v. basically cal mode is nothing but i hv to do it manually when the adc will get input and tell me how much voltage is at batt terminal.

that's all i am planning. I figured out that there are mistakes in avr i/o in my schematic. will solve them. but need suggestion.

ohh yes, i tried that article, it asks for $$ for access. anyway, i already have some literature on batt charging. Basically in 3 stage charging, const curr, cons volt and float. but i'm making it into two. for nothing, because it is only need once in a certain time after a long idle of my bike... i dont use it regularly and thus i get stucked with my self starter....

As said Q3 can't never turn on. In addition, to correct the Q3 control circuit, at least one more transistor is necessary to drive the switch from the processor logic level.

Regarding ATmega reset pin, it has an internal pull-up and may be left unconnected. It's however needed for the ISP interface, too. I think that you can find suitable reference circuits, from Atmel and others.

Also (sorry to compound the problem even more) - a fully discharged or short circuited battery could destroy the micro. I assume pin 40 is an analog input to sense the charging current but it has no protection whatsoever. At the very least, put a resistor in line with it and if your regulator is only rated at 5A, it might be an idea to put an amplifier in line too. At 5A you would get a maximum of 0.5V sense voltage and considerably less for a partially charged cell. Your ADC will only ever read a tiny number and its resolution will be very low.

What you are attempting do is fine, the implementation and use of technology is what's in question. You could make it simpler, cheaper and more versatile by using PWM for example.

Alternatively - look at an IC called a PB137 it is a lead-acid battery charger in a single 3 pin chip. It is rated at 1.5A but you can parallel them for more.


To FVM:->
Can you describe a bit more on the Q3 matter?? infact with a sample schematic type... i cant actuarry get the point... (may be i'm in too hurry...)

And to betwixt:->

Thanks again... but first of all, in my country 9bangladesh) i dont get all parts. even a simple sensor ds18b20 and ds1307 comes very rare... so i am not sure wheahter i'll get that ic. but i'm reading the datasheet to come up new ideas... and ohhh.... again, about sensing, can i then shift the 0.1ohm resistor at the positive terminal and then take differential inputs using 2 adc??? also about amp, i tried to collect single chip instrumentation amplifiers, but again, not in the market... (personally, I hate this market). so can you give me a block diagram type suggestion on sensing with protection?? specially the amplification part.... because ref is 5v. so max input is 5v. and dafinitely i need better resolution. In sim i can work with it, but in practical i may not so i need amp. suggest on it... please...

And finally, thanks to you guys for attending here to help me out.... really thanks a lot.... (because i'm now really learning a LOT)

Added after 2 minutes:

To FVM again:->
I can ommit the T3 infact. but then i need to hold up the power to the battery for atleast 3 seconds before it goes to the battery after the power it gets... how can i do that??? can you suggest??

Added after 3 minutes:

note again to betwixt : ->

I have no idea on pwm and all i have found on the net, they are not for 5A rate... but in max 1A. and i found no way to make them upto 5A... you can still suggest me on that too....

guys, all i need is a 5A charger, automatic, intelligent. and opps, upgradable to any ampere (practical indeed, like 5 to 10 later on).

You can use high side current sensing (sense resistor in the supply side rather than ground) but it makes things more complicated because it has to be differential and the voltages may be rather high for comfort. It is better to use ground side sensing as you do at the moment. The amplifier can be just about any type that can give 5V swing at its output pin, the bandwidth, input leakage and gain are irrelevant in this application. Even the humble 741 op-amp would work.

PWM is a technique for converting the width of pulses into an analog voltage. You could use the voltage to give continuous control of your charging current. There is no limit to the current, commercially PWM is used at thousands of Amps, it all depends on the output circuit you choose. The idea is that your micro produces continuous pulses and a simple filter takes the average voltage from them. Narrow pulses have a longer 'off' and short 'on' so their average is low, wide pulses have short 'off' periods and long 'on' periods so their average is higher. It means you can use software to generate the pulses and produce any voltage from zero (no pulses) to VDD (always on) by simply changing the ratio of 'on' to 'off' in your code. You can use the resulting analog voltage to set your charge current.

I get my PB137 devices from Farnell in the UK but they have a distributor in Bangladesh:

Global Technologies

City Heart Building
13th Floor, Suite 7A
67 Nayapaltan
Dhaka 1000
Tel: +88-02-8313075
Mobile: +88-0171592761

Hope this helps. Brian.


    Points: 2
    Helpful Answer Positive Rating
hey betwixt,
thank u thanku thanku so so so sovery much for the complete address there...

anyway, the pb137 is for only 13.7v or such right???but what if for say bulk charge and then float charge??? then i have to stick with first 14.6v untill curr drops neat to around 500mA and then 13.8v as float. So may I stick to the older plan???

if, then here is my next plan, using 338 as a voltage regulator (as earlier, with 2 pots briven by mcu. one for 14.6v, and another for 13.8v). and for 2-3sec delay, i can use a relay straight instead of the Q3 there right?? and ohhh... finally about the curr sensing, I am planning to use the simple inverting amp with proper gain and then use a buffer for making the amplified output from negative to positive right??? then i simply can employ an mc1458 (since i need only 2 opamp). and finally to take inputs, like display control, calibration, i just can use switch/jumpers.... but in that case, modification in circuit needs with pullup resostors at the inputs right????

Thanks again for taking the pain for me....


The PB137 will adjust to the charge rate for lead acid batteries automatically.

I have drawn a hybrid of the LM338 regulator and your schematic, sorry it isn't very clear, as you can see it is hand drawn and photographed on my mobile phone! I did not have time to draw it properly. With the values I picked, it should give close to 15V with the lines from the ATMEGA at zero. Sending a logic high on either line will reduce the voltage according to the variable resistor setting. It is reverse voltage protected and it will automatically current limit at about 6A.

You do not need to invert the current sense voltage twice, use a non-inverting amplifier. You might need to use a negative supply rail so it can measure right down to zero, most op-amps have trouble when the input is close to ground and a single supply rail is used.


edit after a good nights sleep - sorry it was late when I did the drawing:
The 2400 Ohms resistor should be where the wire directly below the 220 Ohm resistor is. The existing 2400 position should be shorted out.

hey Brian,
Who said it is not clear?? I can see it damn clear even though i am wearing a -4.5D glass.

Anyway, Dafinitely so so so many thanks to you since you are working hard for me.... ummm let me first see and telling you more...

Added after 25 minutes:

Hellow Brian,
First of all, can you tell me the reason of the 0.1uF cap there??

Next, is it now okey?? I have changed the resistor and shorted the rest as per your advice (2400).

In 338 datasheet, i have seen a 10uF cap used between point A and B. Is it necessary here?? Also what is the reason for Q3???

And finally, For that 3 secong delay, can I just use a relay after the output but just before the + terminal of the battery??? instead of the previous TIP2955 (Q3in first drawing)??


-4.5D glass - I wish my eyes were as good as that! I can only focus to 10cm away without aid and I'm starting to walk into things as I get older!

The capacitor is 1uF not 0.1uF, it wasn't clear on my scribbled schematic. The reason for it is to keep the impedance across the output of the regulator low. Inside the 338 and most other regulators there is a high gain amplifier that compares the output voltage to an internal reference. The output of the amplifier controls the amount of current that can flow through the device, hence compensating for changes due to varying loads. Without it, there is a danger of the amplifier going unstable or oscillating.

Q3 does exactly the same as the other two transistors, it pulls the adjustment pin to a lower voltage to drop the voltage at the output pin. Instead of being controlled by the microprocessor, it gets turned on when its base/emitter voltage reaches about 0.6V. That voltage comes from the drop across the 0.1 Ohm sensing resistor so at about 6 Amps load, the transistor starts to conduct and lowers the output voltage to a safer level. Its a kind of extra current limiting circuit to protect against overload.

Instead of using a relay, consider using yet another transistor, connected like the two with variable resistors in their collectors but wired with its collector pin straight to the 338 'Adj' pin. it wont shut the supply off completely but it will drop the voltage to about 1.5V which should make it safe. the two diodes will protect the regulator circuit from being driven 'backwards' by the battery.

You can of course use a relay if that's what you want to do. Power it from the voltage from the bridge rectifier and switch it with another transistor to ground. Put a 4700 Ohm resistor n line with its base and drive it from the microprocessor. You will need to add a diode (1N4001 etc.) across the relay coil with the cathode end to the supply, anode end to the transistor. This will absorb the back voltage kick as the coil switches off.

Blind Brian :)

betwixt said:
You can of course use a relay if that's what you want to do. Power it from the voltage from the bridge rectifier and switch it with another transistor to ground. Put a 4700 Ohm resistor n line with its base and drive it from the microprocessor. You will need to add a diode (1N4001 etc.) across the relay coil with the cathode end to the supply, anode end to the transistor. This will absorb the back voltage kick as the coil switches off.
There i was intend to use the relay....

Well, so again for sure...

The ckt will ctrl the output current to max 6A to min some mA right??and the Q3 is for that...

Well, so after the correction as you said, (relocating the 2400ohms), it is okey?? I mean did i redraw it properly now?? And about the 10uF cap between A-B (As told in datasheet)???it is required or i just can ommit it?
If I fail to get a 2400ohm, can I go with 2200?? And so for controlling 2 of the voltages as I said, i will bias the Q1,2 by ATMEL right??


Added after 2 minutes:

oppps, about relay, you were telling that so finally i can use total 3 pots for 3 diff voltage... one 14.6, 13.8 and 1.5 right??? or alternate is to use a relay as i told...

Added after 11 minutes:

hey, about the part of q3,

as per datasheet of 338, it says that

Vout = 1.25(1+R2/R1) and thus with the use of 2400, what happens??? can you please check this schematic I attached again for the location of 2400ohm?? and when .6v makes the Q3 conducts, then actually what happens?? I mean how it actually controls the current not flowing over 6A??? or it is shutting down when it sense I=6A??? If shuts down, then for a empty batt, i think it will never start... because hungry batt will try to eat even 10A. but if it limits the curr out, then fantastic. Whatever your hunger is, you have to eat that I feed...

Added after 20 seconds:

hey, about the part of q3,

as per datasheet of 338, it says that

Vout = 1.25(1+R2/R1) and thus with the use of 2400, what happens??? can you please check this schematic I attached again for the location of 2400ohm?? and when .6v makes the Q3 conducts, then actually what happens?? I mean how it actually controls the current not flowing over 6A??? or it is shutting down when it sense I=6A??? If shuts down, then for a empty batt, i think it will never start... because hungry batt will try to eat even 10A. but if it limits the curr out, then fantastic. Whatever your hunger is, you have to eat that I feed...

Added after 34 minutes:

opps.... agiain.... (Lots of questions.... huh...)
Can I also limit the current by using a Limiting resistor (around 5ohms, 5W) for limiting it to 5A??? just to know... (as i said, learning.... that never ends)

That's a lot of questions !

Firstly, your new schematic is correct.

The extra capacitor from points A to B is probably not necessary but it will do no harm if you add one of say 10uF. If you make the value too big it will make the regulator slower to react as the load changes although in the case of a battery charger this probably isn't critical anyway.

The relay can be used if you need to completely isolate the charger from the battery.
The point about adding another transistor across Q1 and Q2 is that if you make it fully conduct, the 338 adjust pin will go to ground and it will only produce 1.5V output. If that is satisfactory, it makes a simpler and cheaper way of 'almost' turning it off than using the relay method.

Q3 actually limits the current to 6A. It does nothing until 6A load is reached then as Q3 starts to conduct it reduces the output voltage to maintain 6A into the battery. It changes the circuit from constant voltage to constant current to prevent the battery and charger overloading.

The formula, as you stated for setting the 338 output voltage is,
Vout = 1.25(1+R2/R1)

R2 is the 2400 resistor and R1 is the 220 resistor so the maximum voltage will be 1.25 *(1+(2400/220)) or 14.88V, this is a suitable maximum for charging a 12V battery, remember that as you drive Q1 and/or Q2 you reduce the voltage to a level set by the variable resistor (think of the variable being in parallel with the 2400 Ohm resistor).

If you change it to 2200 Ohms, the maximum voltage will be 1.25*(1+(2200/220)) which only gives 13.75V which may be too low. You could compensate for using 2200 Ohms by changing the 220 Ohm resistor to 180 Ohms which would give a maximum of 16.53V It is really up to you to decide the highest voltage you are likely to need. The variable resistors will let you drop it to whatever you want but the two fixed resistors will set the maximum.

You can use the outputs of the microprocessor to directly switch Q1 and Q2 on or off. Their emitters are tied to ground so if you inject current from the micro into the base the transistors will effectively become short circuits and let you set the voltage with the VRs.

Incidentally, that was one of the problems with your original design. There was no way of providing the base-emitter voltage to turn the output transistor on.


Dear Brian,
Thanks a LOT.... just thanks a LOT....

Well, I'm kinda sick today...(nothing, just a little break in my regular food chain and it happens all the time... need 48hrs in total...)

I'll let you know detail in it after that... meanwhile, i'm planning to use using another Q for making 1.5V for the 3sec holdoff... because isolation is not necessary, just a little hold off... already since I have used diodes there for reverse polarity protection, so i dont care about that.

And well, that sounds cool of hearing constant current.... But sir, I again have a little question (question question question...)... Say, I'm using Q1 for 14.6v. it's working... and then the Q3 also strated working, then 2.4k will get the path from below of 220 through the base of Q3 to ground... right???

either way, when already q1 is working, then again q3 also starts working, then the pot for Q1 and the 2400 will become parallel right?? then???

Added after 49 minutes:

sorry, as i forgot to UL the pic

Dear Brian,
There is a little ammendment... I just got the battery today that is 6.5AH and I'm planning to use it with the batteries of 7AH max. Thus i have to limit the current more... say within 3A. So need to make bit change... what you think?? adding a series resistor (5W) as current limiting resistor??


The 0,1Ω resistor limits the output current. Limitting happens when the voltage on this resistor reaches about 0.6V (when it equals the Vbe of Q3). To limit the current to 3A replace the 0.1Ω resistor by a 0.2Ω one. The equation is: Ilim = Vbe/Rlim or Rlim = 0.6/Ilim. This also means that at full output you´ll have the same voltage sent to the ATmega(0.6V), irrespective of the current you choose.

Not open for further replies.

Part and Inventory Search

Welcome to