DIY Electric Car Forums banner

$200 Build your own intelligent charger.

212K views 565 replies 60 participants last post by  PStechPaul  
#1 · (Edited)
This project started here. I had built a high voltage electric vehicle but found the options for charging somewhat limited and very expensive. I wondered how complicated it could possibly be? A couple of minor explosions and the odd electric shock later, here it is - a fully programmable digital charger capable of operating up to 350v and 35A.

I built mine largely from parts salvaged from junk computer UPS's but even if you bought all the parts new, I doubt it would come to much more than $200.

First of all the circuit diagram:
Image


I would strongly recommend you test and tun this using an isolating transformer. While testing, I used and isolating transformer as well a Variac which allowed me to reduce the input voltage to a relatively safe 50v or so.

This is a list of the parts you will probably need to buy. I've not included most of the resistors and capacitors - but they are shown on the circuit above:
High Side Driver - A3120
Encapsulated 12v Power Supply
15v DC/DC Converter (this could do with being higher power than 3W)
5v Zenner Diodes used to protect microcontroller
40A Bridge Rectifier Avoid the Chinese ones from eBay - they say 35A but let the smoke out at about 15A.
Ultra Fast Diodes I'm using 5 salvaged 10A Shottky diodes, but they are no longer available. Something like the ones listed will be fine though. Parallel up enough for 2 x the max charge current.
Microcontroller This is the most expensive part at about $60

Parts you are best off salvaging from something else:
Large Electrolytic Capacitor. Must be rated at >= 2 x your mains input voltage or it will explode (exciting and smelly). I have a 2200uF 500v capacitor - but something a lot smaller will be fine - it's just what I had.

IGBT I've used a big 200A 600v IGBT from a 3 phase UPS - but it only needs to be rated at about double your charge current. There are some nice ones on eBay for about $25 - but you can just parallel up a load of low current ones on a heatsink. Watch out though - often the metal tab on the device is connected to one of the pins. This may cause a problem for other stuff connected to the heatsink - particularly your fingers!

Output smoothing Capacitor I used something similar to this but it's not that critical. It's to get rid of the switching spikes from the output so any low value high voltage (non electrolytic) capacitor will probably do.

It's not shown in the circuit, but I also put a power diode in series with the connection to the batteries. This is just in case the batteries are connected the wrong way round. In this case you will get a loud pop and the smoke will escape.

Relay The microcontroller board includes a relay which it says is rated at 15A. However - it kills itself at a lot less than that. I'm using it to switch a larger 60A relay in the output line (RL1 on the diagram).

Shunt The current is measured using a simple 0.22 Ohm shunt. I would recommend one of these over a wire-wound type as they have very low inductance and can be bolted directly to a heat sink. This particular one is rated at 50W or 14A but bigger are available.

I built mine on stripboard just to try it out - but may get some PCB's made.

Next, I'll cover the software and microcontroller.
 

Attachments

#2 · (Edited)
Microcontroller and Software
The project is based on an AT Mega 128 development board which includes a relay, a beeper, a 2 line 16 character LCD (sadly not backlit) and five buttons. It also has several digital and analogue ports brought out on to connectors on the rear.

The microcontrollers themselves are inexpensive, but you need to spend about the same again on a programmer. It is a 'dongle' which connects to the USB port on your PC and to one of the sockets on the back of the controller (the JTAG port in my case).

You also need a language to program it in / with. To make it as widely understandable as possible, I adopted a version of Basic - MikroBasic
I started with the demo version - and found I quite liked it. Because of the size of the program, I bought the 'pro' version which was about $150 - but I will get more use out of it than just this I hope.

That means that unless you can persuade someone else to do it for you, you are looking at another $200 to burn the software on to the microcontroller board.

Once the software has stabilised, I might offer some kind of "send me your board and I'll blow the software on to it for a nominal consideration" type thing - which will lower the cost a bit.

I have attached the code for the charger. This version works but has a few 'issues'. Most are cosmetic (screens not being very clear or UI being poor) but the main one is that the charge cycle times out after about 20 mins - so you only get 20 min charging at a time.

I have also uploaded the .HEX file which you can burn directly on to the controller using a piece of free software

How the application works
There are three main functions:
1. Calibrate
From the home screen, push the left button. It will ask you to measure the battery voltage with a meter and adjust the reading on the screen (using the top and bottom buttons) to match. This just calibrates it's internal volt meter.
To exit to the home screen push the middle button (this works from most of the other screens too - sort of like the back button)

2. Edit
From the home screen, push the Bottom button. Edits the charge profile.
The charge profile consists of five 'Pots' (Why 'Pots' - cos it's short and each pot contains info?). Each represents one charging stage.
within each pot, you can set:
Enable - Enables this pot. If your profile only needs 2 pots, disable the other 3.

Voltage - Sets the max voltage

Current - Sets the max current
The output will try to achieve the specified voltage, unless the current is too high - then it will limit the current. Remember, this is the voltage of the whole string, not a battery or cell.

Trans Voltage - this is a voltage which when reached, this pot will terminate and the next enabled pot start. Set higher than the charge voltage to ignore this parameter (as it will never be reached)

Trans Current - If the charge current drops below this value the pot will terminate and the next enabled pot begin. Set to zero for it to be ignored.

Timeout - the time in seconds (up to 2550s) after which the pot will terminate

You use the top and bottom keys to increase and decrease values, the left and right keys to cycle through the parameters and the middle button to save and exit back to the home screen.

3. Run
From the home screen, push the right button. Runs the charge profile. The duty cucle starts at 1 and climbs slowly until the desired voltage or current is reached - then increases and deacreases to keep it within the desired limits. It will hover around +/- a couple of volts because of the limited PWM resolution but this should be OK for the batteries, it's better than 1% regulation.

4. Test
From the home screen, push the Top button. This was added to test the circuit without necessarily charging a battery. I just conected the output to a light bulb as a load. You can use the top and bottom buttons to adjust the duty cycle from 1 to 255. The display shows the measured current and voltage.




I forgot to mention that I had abandoned using a hall effect current probe in favour of a shunt.
The hall effect probe, for a number of reasons worked better than the shunt but unfortunately I stepped on the only one I had and broke it. In it's place I have used a 0.25 ohm 100W resistor which will drop 5v at 20A - and give me good resolution across this range. I will probably go back to the hall effect sensor at a later date when another suitable one falls in to my hands. This is the type I used previously.
 

Attachments

#3 ·
Interesting effort, Simon... but your circuit... well... let's just say it's missing a bunch of stuff.

1. WHERE'S THE FUSE, SIMON??? I don't see any surge protection, either. If the IGBT fails it will fail short circuit, and if your battery pack has just enough impedance to not vaporize the IGBT's bondwires, welll...

2. inrush current limiting, aka "precharge" - this is probably why you blew up one of the electrolytics. You need to put, say, a 100 ohm/5W resistor in series with the cap that gets shorted out by a relay after a second. This will make the bridge rectifier a lot happier, too.

3. proper isolation of the control circuit from the mains - while I think it is arguably pointless to isolate the mains from the battery pack, referencing the microcontroller interface to the mains is a real no-no. Lots of stuff needs to be changed to fix this issue, but start with your current sensing and gate driver.

4. current sensing - I really recommend you go back to a Hall effect sensor both because it is naturally isolated AND likely more accurate in this situation. The reason has to do with the reactance of the stray inductance in the sense resistor approaching or even exceeding the actual resistance value, which exaggerates the output voltage as the frequency goes up.

5. buck inductor - the core material and number of turns of the inductor should be specified with a bit more care. I like to use this site:

http://schmidt-walter.eit.h-da.de/smps_e/abw_smps_e.html

to get a reasonably accurate initial estimate of the component values needed.

Now, please edit that circuit before someone here with even less knowledge/experience builds it with even less suitable components and destroys their battery pack, burns down their car/garage/house/whatever.
 
#77 ·
3. ... I think it is arguably pointless to isolate the mains from the battery pack ...
Hi Tesseract!

if I built a battery charger, I would want to connect mains earth to the car chassi for obvious security reasons. And with a charger that has common mains earth and battery minus, the battery pack is no longer isolated from the car chassi! Even if a residual-current device would save you in most cases, you can not count on that it is fast enough.

Or why do you mean that isolation from the mains would be pointless?
 
#5 · (Edited)
with even less knowledge/experience
That's a little bit hostile - don't you think?

OK - I missed out the fuses, and the bleed resistors. I'll update it in a minute.

Isolation from the mains. The IGBT driver is opto isolated from the microconroller. The current and voltage sensing is more difficult. One option I considered was to use an A to D board with an optical data link to the main board. Do you have a constructive alternative suggestion?

http://schmidt-walter.eit.h-da.de/sm...bw_smps_e.html - the site you suggested is very good. Wish I'd seen it previously.
To use this, the only bit you cannot work out for yourself is frequency - and it's about 41kHz. For my application it suggests 500uH inductance with 2.5mm wire. The inductance I'm using is a bit bigger than that - but it seems to work OK.

Is this really any more dangerous than using a bridge rectifier and a kettle element or capacitor as a current limiter as a battery charger? However, Tesseract's response to the thread on that one was:
Good luck, and don't forget your safety glasses with this one
I'm obviously missing something.

I agree in general with your points - but the point of this was to make something low cost which is better than a kettle element! It's not supposed to be competing with multi thousand dollar chargers - so treated with the same caution you would extend to a kettle element current limiter, it should not be a problem.

Si
 
#11 ·
That's a little bit hostile - don't you think?
Not in the slightest. There's a reason the UL/CE/VDE etc. are in existence, you know. Has something to do with electrical problems being the number one cause of house fires I believe.


Isolation from the mains. The IGBT driver is opto isolated from the microconroller.
Indeed it is, but the rest of your circuit is not courtesy of your voltage and current sensing methods. Also, your gate drive resistor is awfully high and there is no return path for the gate current (ie - you need to connect the (-) output of the 15V DC-DC to the emitter terminal of the IGBT, and you ought to put a 15V TransZorb and at least a 10k resistor from gate to emitter).


The current and voltage sensing is more difficult. One option I considered was to use an A to D board with an optical data link to the main board. Do you have a constructive alternative suggestion?
There are many ways to transmit voltage level information across an isolation boundary. Probably the most popular is the venerable TL431 and an optocoupler. One clever method uses a self-oscillating flyback converter to produce an output proportional to its input. BTW - using a resistive divider is the same mistake K*lly makes in it's controllers, and why you get a little tingle from them if you happen to be touching the vehicle frame and a battery terminal at the same time.


http://schmidt-walter.eit.h-da.de/sm...bw_smps_e.html - the site you suggested is very good. Wish I'd seen it previously. To use this, the only bit you cannot work out for yourself is frequency - and it's about 41kHz. For my application it suggests 500uH inductance with 2.5mm wire. The inductance I'm using is a bit bigger than that - but it seems to work OK.
You have to make an educated guess about the frequency of operation. For a motor controller there is little advantage in going any higher than is necessary to render the motor silent (at least from the switching frequency); for an SMPS, though, there is considerable merit in going higher because you can use less inductance (= smaller core).

For a buck converter, specifically, using more inductance than called for is fine - it just shifts the boundary between continuous and discontinuous modes downward. Transient response is affected, but that's not normally an issue for a battery charger.


Is this really any more dangerous than using a bridge rectifier and a kettle element or capacitor as a current limiter as a battery charger?
Yes, it is more dangerous for two main reasons: 1) you have a big fat electrolytic capacitor in the circuit (and your precharge resistor needs to be shunted out by a relay, btw - you can't leave that 100 ohm resistor in there all the time and expect this thing to function worth a damn); 2) the other circuit had some form of current limiting impedance in the circuit whereas yours does not.

I'm not saying the "dumb charger" is better, just that yours has much more potential to do bad things.
 
#7 ·
Good news! It all seems to work rather well.

I built a charge profile from the info here and have achieved a 20% increase in range compared to charging the batteries withg a variac.

I'm charging at a constant current (8.5A) until the batteries get to 2.45v per cell (Bulk Charge). Then switch to constant voltage (limited to 2A) at 2.45v for a period of 4 hours (Absorption Charge). Then switch to a 2.27v per cell float charge which times out after 4 hours.

I've also fixed several of the bugs in the software and improved the voltage measurement calibration to within 1%

Si
 
#9 ·
Mine are 50Ah (15 of them). The bulk charge depends on the degree of discharge but assuming they are completely flat, it should take about 6 hours plus 4 hours Absorption.

This was with the Optimas from the junk yard. Before I fit the Odysseys, I want to build something to limit each battery to 14.7v allowing them to auto equalise.

Si
 
#10 ·
Yeah i've been brainstorming on that also as the odysseys don't like going above 14.7v per batt and i'm worried that a "dumb" pack charger would cause damage even if the total voltage were limited. Its a tough ball of wax because even if you detect one bat at 14.7v others probably are not.
 
#12 · (Edited)
Great knowledge sharing!!!

Since you must have studied requirements for charging voltage - what do you think about 12V Scumacher charger:

When set to 8A it will:
- charge at 8A till voltage reaches ~14v, then will start to slowly decrease coltage, but will charge up to 16V, finishing at 1-2A
- once 16v reached, it will step back to 15.5v and hold that for 1-2 hours.
- after that switch to float mode at ~13.2

Similar scenario when set to 12A.

Batteries clearly get good charge, and hold 12.8 even after a 1-mile ride.
Chargers have another mode of charge, for GEL type of batteries, and will supposively set lower cutoff voltage, but i haven't played with it yet.

Is it too muhc of charge?
 
#16 ·
I think i have spotted something usefull for my Keystone Interstate (from costco - http://www.batteries-faq.com/activekb/questions.php?questionid=1

BUlk charge - 14.4 but absorbtion - 15.5 ! Schumacher goes a bit past 15.5 but then runs absorbtion charge at 15.5.

Tested GEL mode - charger will go up to 14.5 volts, and stay there for some hours, didn't catch exactly how much. THen go to float.
Interesting, but that almost exactly what Odyssey recomends. Are odyssey - gel batteries?
 
#19 · (Edited)
Nope, the popular odyssey batteries are agm. Many say they are the best agm batteries you can buy.
Since AGM is just another type of VLRA battery- they must have the same charging pattern. Previous model of 12/8/2A charger has Gel and AGM types on the same button.
So Shumacher chargers indeed hold the correct charging for different types of batts! I guess I am ok with using Starndard setting for my floodies.
 
#18 ·
OK - I've used TL431's in this kind of configuration before:
http://www.powersystemsdesign.com/design_tips_june07.pdf
All be it a long time ago. They are a fine way of providing isolation on an analog signal.

However, this has been where the microcontroller shares it's -ve terminal with other stuff like the casing or heat sink.

In this case the buttons and display on the controller are plastic - and are behind another layer of plastic to insulate the user from the controller. Why does it matter if the microcontroller is isolated or not? There is no electrical connection between the controller and the outside world (other than to the mains and batteries).

In any case, if I were going to go down that route, I would probably just isolate the buttons and display through simple opto's. Likewise if it had a data / rs232 connection.

(ie - you need to connect the (-) output of the 15V DC-DC to the emitter terminal of the IGBT, and you ought to put a 15V TransZorb and at least a 10k resistor from gate to emitter)
I had missed a connection between the IGBT Emitter and the A3210 driver which I have corrected.

The 590R is a bit high, but the 15v DCDC converter could not deliver the current that a smaller value would pull which resulted in a lot of ringing. 590R was just a compromise which seemed to work. With a higher power DCDC, the value can be lower. If the DCDC can spit out 2A continuous, a 100R resistor works well.

The A3120 doesn't need a 10k bleed resistor to switch the gate off - it has a pair of transistors on it's output - one to pull up and the other pull down. As it stands, the switching waveform is fairly symetrical.

A transorb is a good idea though for a bit of extra protection of the IGBT.

I'll maybe re-draw the circuit with a few of these thoughts included.

Si
 
#21 · (Edited)
Hi Si,



Good effort on the buck charger. I can offer a couple of points:
  1. EMI Filter. A common mode choke and possibly a low pass filter should be installed before the rectifier bridge.
  2. Consider adding PFC circuit. The materials cost isn't that high and it gives you the advantage of boosting the bus voltage when on a single phase (110V) supply. EDIT: Sorry, didn't notice that you're in the UK (240V mains). The Americans might benefit from a PFC though.
  3. If the current sensing shunt circuit is in fact giving false readings due to the shunt's inductance, put a capacitor just after the inductor to get rid of any AC (switching freq) current.
  4. Consider using RS-232 between your display/buttons and the controller micro. There's lots of example code out there for a small micro to run the display and buttons. Use a MAX232 on the display to level shift and invert the TTL to RS-232 signals. At the controller end, to isolate, level shift and invert requires only two optos and four resistors.
Sam.
 
#94 ·
Consider adding PFC circuit. The materials cost isn't that high and it gives you the advantage of boosting the bus voltage when on a single phase (110V) supply. EDIT: Sorry, didn't notice that you're in the UK (240V mains). The Americans might benefit from a PFC though.

Hi *****,

With a PFC you mean a circuit that increases the voltage to a desired level? I think I want a 400 voltage system, and with 230 Vac I would need a little more volts. I can't find any leightweight high power transformers on internet that will do this for me. Is there another way?

Tesseract,

I will not do anything with this stuff before I'm convinced I can, or get the help it requires. But because I want -eventually- a pretty complex setup with solar power and the highest efficiency I can reach, I'm interested in this stuff. I will tell you before I do anything, I promisse.
 
#22 ·
Thanks Sam - good advice all round.

On mine, I have a choke on the mains input (as well as fuses) - I just omitted them from the diagram to simplify it. Being in an unscreened plastic box, there is a certain amount of RFI produced - but once the hood is closed, I cannot detect any. If it were in production, it would need a bit more screening.

The shunt and potential divider are reading within 1% (compared to my RMS Calibrated Fluke 79) which is porbably good enough. I am using capacitors to smooth the readings - but it was more because the ADC's were reading the waveform itself rather than the average which lead to rather random values!

I think when I build the next one, I'll just use 100W metal film resistors for the shunt.

I mentioned earlier using optos to isolate the display and buttons. Again, I would be tempted to use a separate ADC board connected via optos using I2C. The board has RS232 on board, but I currently do not use it - so although the controller is not isolated, it is insulated.

Si
 
#23 · (Edited)
Si, good point on smoothing the input to the ADC on the microcontroller.

For others attempting a similar project, the inconsistent readings on the ADC will have you tearing your hair out for ages trying to fault-find. This happened to me back in Uni on an SMPS charger design.

There are two common problems with sampling an ADC - unwanted out-of-band noise (the IGBT switching frequency in this case) and aliasing caused by noise above the Nyquist frequency. The Nyquist frequency is defined as exactly half of the maximum sampling frequency of the ADC. Since the analogue signal we're interested in is at a frequency band below below both constraints, we need to design a filter that passes analogue signals below the lowest of the two constraining frequencies and blocks above it. The answer is to use a simple low-pass resistor-capacitor filter just before the ADC pin to filter HF noise and aliasing. The filter frequency should be at least 1 decade below the switching frequency in order to account for roll-off of 6dB/decade of a simple single pole filter. Eg: If the switching frequency is 40kHz, the filter should be set at 4kHz or lower. If the Nyquist frequency is 2kHz then 2kHz will be frequency you want to set your filter to.

The resistor is inline with the signal and the capacitor is in shunt between the ADC pin and ground. The resistor value will be the ideal impedance for ADC sampling (refer to the microcontroller datasheet) and the capacitor value is determined by 1/(2piRF), R being the resistor value and F the frequency in Hz.

If you're filtering from a high impedance source like a voltage divider, consider this when working out the resistor value. If the voltage divider impedance is too high for the ADC you may need to buffer it with an opamp set up for zero gain to drive the ADC.

Si, would you consider writing up a wiki page on your charger? I think it would be of great benefit to others wanting to go the pure DIY route. I'd like to do the same for my charger when it's finished. Mine is simply a PFC boost design since my pack voltage is above the peak AC RMS voltage - a lot less current to deal with! :)

Sam.
 
#24 ·
There is also quite a lot of filtering (moving time average) in the software which seemed to achieve a good approximation to RMS.

I used this design (something like it anyway) for converting 12v to 24v:
Image

Which worked pretty well. When the IGBT's switch on, there is no current flowing - so no loss. When they switch off however, there will be quite a high current flowing - so you need to switch them off quickly! I used an A3120 (same as in the charger) but took A to +5v to switch on and -15v to switch off - which seemed to do the trick.

I had kind of intended this to be a sort of Wiki - however - considering the amount of negative attention it seems to have generated with my dangerous lack of competence - i'm not sure I can be bothered with the flaming.

I have been using my charger for a week now twice a day (home and work) and it seems rather good. The batteries have equalised remarkably well and I'm getting about 10% more range than last Monday. With the components used, it will charge at 20A without getting any more than warm - that's 4.5Kw. I've improved the software with temperature monitoring on the heatsink and an auto-start on power up so I can just plug it in without opening the hood.

Before I fit my Odyssey batteries, I think I'll build another version of the charger using all new components. I wrote a program for the mill last night which will cut a nice wavy heatsink :p from a slab of Ali with a deep pocket on the reverse to house the components etc. Because the charger lives under the hood - it really needs to be waterproof.

Si
 

Attachments

#27 ·
It ought to work on anything you can design a charge profile for. The only thing not implemented in the software is 'delta V' where you control the charge based on the rate of change of voltage (or current) - but as far as I know that's only relevant to NiCd's

I have no plans to make kits - though I have had a call from a Switch Mode PSU maker interested in doing something with the software / microcontroller, connected to more grown-up hardware. Looking at one of their PSU's however, it's not much different to mine - just a bit more signal conditioning and a small, HF transformer in the middle for isolation.

If you want to build your own hardware - I'll happily program one of the AT Mega 128 controllers for you with the latest version of the software. The point of this thread was that with a bit of effort, pretty much anyone can build something usable if not ideal - by moving a lot of the normal complexity into software.

Si
 
#28 ·
Is the atmega micro a through hole device and could you provide a circuit diagram for the control board portion? If its just a 5v supply , osc , lcd and a few buttons its probably easier to just make. I think i would prefer to use the hall current sensor so would the code work or need a mod? Sorry for all the questions:D.
 
#29 ·
The microcontroller would be pretty easy to build - however, when I looked at doing just that, you save about ÂŁ2 on the cost of just buying one ready built and tested on a nice PCB!

Although the hall effect device seems a great idea, I found the output less stable than a simple shunt. Since the voltage measurement is not isolated, the current measurement being isolated is pointless. It would require a program change - but if you tell me the voltage it spits out per amp and with what offset (mine read 2.55v at 0A then increasing or decreasing for current flow in either direction), I'll adjust the code to suit.

I figured that shunts and voltage dividers are good enough for multi-meters, so they are good enough for this!

Before you start building, let me finish my Mk2 design which will be made entirely out of components from RS so at least you will have the option of buying new.

Si