There are currently 0 users and 4 guests online.
LiPo Protection Circuit with kill switch
LiPo Protection Circuit with kill switch
Submitted by TrickyNekro on February 1, 2009 - 9:25am.
Deep discharge.... Oh crap!
Ok tell me know that you are the always neat guy that forgets nothing....
You may be.... but... Natures says that you are not error free... :p
So what happens if your BEC ESC turns off your motor but you continue to use the battery with the electronics.... And I'm not talking about the landing time... I'm talking when you board your airplane to your car get your cup of coffee and you are ready to go... What happens then... you kill your RC battery??? NOP....
And what about you lazy robotier.... I'm one of you out there guys.... Do you always disconnect the battery when done... You are sure that any capacitor that leaks power isn't still connected... Or... You always measure your battery... I get no... You don't run behind your robot with a multimeter... Your robot may run behind you... but if it can not shout recharge me I'm turning off... you will wait until you have the next pay day to buy a LiPo...
Moreover this tutorial is for making LiPos easy to use... without any concern killing them...
So... how the hell we protect our LiPo from deep discharging... There must be a circuit that measures the voltage of our LiPo and when it has passed a certain threshold disactivate any but any drain...
Any drain??? It's internal drain also??? How??? Thus this projecy is called a kill switch...
There are some pros and some cons to this but... I see it the positive way...
So here are the pros:
You protect your battery from low voltages... period!!!
You protect your battery from over current.... good one!!!
You can connect the circuit and let it be on the battery until next recharge!!!
It drains NO current when disactive but less that 20mA when active... A RC motor can drain serious Amps!!!
The Dip version is about 100gr but I imagine that the smt version will be around 20gr or less... So it's light!!!
Once the microcontroller hit's the kill switch only the user can activate it again... It's a kill switch......
As current flows though a MOSFET, it flows through an electronic device with resistance.... So some power is wasted... I haven't tested so far how much... But I calc that it's about 20 - 30 flying seconds... I'll try to improve this in later versions....
These are the two cons I see so far... more will be revialed only with testing!!!
Ok??? where we were....??? How to build this kill switch??? It's not difficult and I tried to use easy to find components... Two MOSFETs, two bipolars, some resistores and caps, a atmega8 and a LM358 and a buzzer!!!
Here are the schematics for the whole thing and we will explain part by part:
First let's mention the values of the resistors:
R1 = 1K R2 = 10K
R3 = 1K R4 = 10K
R5 = 10K R6 = 10K
R13 = 1K
The rest resistor values will be discussed later on this tutorial.
All the capacitors shown are noise limiting capasitor at 100nF. Placing a 1000uF electrolitic near C2 is recommended.
Ok, now let's explain how every circuit works:
The Kill Switch circuit:
The circuit may seem to be a little complicated cause I didn't draw it keeping in mind that total beginners may see it and rebuild it.... My mistake here I gotta admit...
Ok, As you can see we have a tact switch (S1)... This is connected to the battery and the Base of a NPN transistor (T1) via a current limiting resistor. These resistors exist to "limit current" as you can imagine.... preventing the transistor from frying.... With other words.... If you don't place this resistor, get a pan.... an egg.... and start cooking....
So, T1 NPN transistor is activated, this means that current can flow through it as we use this transistor only as a switch. Being a NPN transistor means that it's activated with a Logic high or positive voltage at the Base and
it allow Emitter and Collector to be interconnected... So with the Collector connected to the ground the Emitter also becomes ground. At this point let's go at the PNP (Q3) transistor... It's basically the opposite of the NPN transistor in operation. It's Emitter is connected at the battery and the Collector goes to our N-Channel MOSFET. Note that the Base and the Emitter are connected with a 1K resistor... We do this to prevent the transistor to activate itself using electromagnetic noise... So how this go? We hit the switch (S1) and the base of T1 has possitive voltage so it allows the Emitter of T1 to be ground, and when this happens Q3 is activated cause to be activated it needs zero voltage at the Base. When this happens the Collector of Q3 has a positive voltage from the battery and this voltage goes to the Gate on the N-Channel MOSFET (Q1) and guess what??? I activates it!!! So the Drain Circuit has power!!! And that's cool!!!!
But you also note the existance of Q2... This is a P-Channel MOSFET... Why do we have it there???
Well, in the beginning we said that we want NO current draw when the circuit is not activated... This is why Q2 is there... To power up the rest of the circuit only when the Drain Circuit has power...
This means, that before we hit the switch nothing has power.... and I mean nothing... As we hit the switch everything power up!!! If we leave the switch and the microcontroller detects NO problems as shortages and low battery, it takes on and the circuit remanes activated... if not... it immediatelly turns off....
Here are some videos explaining how this is done, I hope you enjoy:
First the real world:
Then the theory:
The Voltage Divider:
This is a very straight forward circuit... It only consist of two resistors, one connected to ground and one to the battery. Then, these two are connected together and the join is connected to an ADC pin of the microcontroller. What we achieve with the voltage divider is to multiply the voltage input with a fragment reducing it so that our microcontroller can read it without being burned.
As you can see, in our circuit the voltage divider is represented by resistors R7 (640K) and R8 (400K).
The math behind these values is this:
Vout =Vin * R8/(R8+R7) where Vout = 12V6 MAX!!! So that Vin ? 5V
So we ensure that no more than 5V goes to our microcontroller, keeping everything smoke free!!!! :p
A zener here maybe useful, in times you accidentally connect a voltage bigger than 13V, but this time we can just go off with it...
NOTE THAT!!!! This battery protector is designed for a 3Cell battery, it won't work with a smaller battery, but it will get burned with a bigger battery, just because I'm assuming you won't test it... It's rare to see a model with a bigger battery anyways, and for robotics, the best comes with a 2Cell battery which with circuit covers with the respective stange in code, or else it won't function. (You shouldn't worry much about this code change, it's just two values!!!)
The Microcontroller circuit
Nothing special this time too! Basically you can use anything you like as far as it has ADC inputs!!!
Here we use ATMEGA8 cause, It's well known and many many guys use it (arduino guys, the 50$ robot etc etc etc.......), Cause it's well know it's rather easy to find in small quantities, It's compact and has the hardware we want, has an internal RC to save some space (although crystal is recommended) and other things!!! The microcontroller is our logic unit, it makes all the calculations using as input the ADC channels, it creates a frequency with the timer to tell us that the battery is going low, it has the ability to control it's power source, it sents data via usart to tell us the remaining capacity and the voltage of the battery and other things!!! Basically with the right coding it does it all.... But as said.... coding is required....
And the code of the microcontroller will be the last thing to discuss... so let's continue to the rest of the circuit...
The buzzer circuit
Well, what more I gotta say, a nice big buzzer or speaker that has a transistor to amplify it's output so you can hope you hear that the battery is low.... I know this probably is the worst way to inform the user but.... it's only board number ONE!!!! I added that uart just for wireless data transfer.... but this will be possible with a RF tnasmitter add on... I haven't thought of it yet, but my heart just goes to LINX modules, we will see...
And last but not least..... The current sensor!!!
Ok this thing was very very nasty to make... Right know I have problems with the LM358 and it's output capabilities, so I will only explain how this works and add another schematics with the replacemant...
Why I am having this problems??? It's cause I want a rail to rail output... What this is???
A rail is considered one of the two voltage levels of the supply. In our circuit here it's the 0V rail and the 5V rail.... But to have a full spectrum at the ADC channel we want the output to be from 0V to 5V... something that didn't happen with LM358 cause it's output isn't rail to rail.... with other words, it won't go from 0V to 5V, but using the non-inverting style of op-amp (here in this circuit), the output will go from 0V to 3V8.... which means we lose resolution.... BAD!!!! So, until the samples from MAXIM arrive.... NO GO!!!!
But I feel like I can explain how this sensor works...
Well, first of all we have a circuit eehhh? What is a circuit??? No matter what this circuit does.... it's no more than a meer resistor... As you know the bigger the resistor, the less current!!! That's right!!!
As a consequence of having resistance in a circuit, is voltage drop between the pins of this resistor...
But what if we have more than one resistor connected in series, the same current will go through every single resistor depending on the order of place... Now the voltage doesn't go from +Vbatt to -V at the final resistor, but depending on the value of the resistor and the current through the resistors, each resistor will drop the voltage respectively... With ohms law, we can find the voltage drop between each resistor pins!!! Considering that current is what we don't know, knowing the voltage and with a given resistor we can calculate current through it!!!
So what so we do in reality??? MOSFETs aren't perferct, so that means that they act as a very small resistor when active... So what we do is to measure the voltage differencial of the Drain and Source, given that it's internal resistor is stady, we can to the calculations and find out the current through the MOSFET!!!
In this circuit the MOSFET we use for this job is the N Channel IRF540 with an internal resistor of 44mOhm with high gate!!!
As you see, the internal resistor is very very small, so we expect an very small voltage difference.... So what we do is to multiply this voltage difference in a level than this acceptable from the microcontroller to read!!!
How we do this??? With an Op-Amp circuit!!! As said above, the LM358 has a very poor output for out work here so, we can only wait for samples to come and be tested!!!
From here you may also have noticed the existance of two amplifier circuits. This is because the one is use for accurate measurements from 0 to 1Amps and the other is used for 0 to 20Amps...
I can also not tell you the values of the resistors used in the amplifier circuit so far, as I wait for the replacement... But in tests so far and theory R11 = 49*R12 and R9 = 4*R10
So that R11 = 925K and R12 = ~18K5... R9 = 4K and R10 = 1K but these two aren't tested!!!
Petience guys!!! Update in one or two weeks.... Better tell MAXIM to hurry with those samples.......
Here is a small vid I shot to show you what I wrote above.... I only hope it doesn't make it more confusing :p
Turning the stone into a thinking machine....... CODING!!!!!! :P
So the time has come to the coding part... Since, we want a smart battery protector that won't just turn off middle air we must take some parameters into consideration before coding...
Most battery protectors out on the market are dump.... they are based on simple electronics like comparators and such, cutting the power when most needed... and that's very bad... cause on a air model, the batteries aren't the only precious thing on it...
So we want to make a battery controller that warns the user early, protects the model and the batteries, and later on give the user a constant feedback on the contition of the battery wirelessly, without intefering with the remote... Are these too much??? The answer is no... Can a beginner do this??? Well... this why we are here....
So the pseudo-code goes something like this...
1. Give power and check the battery. Warn the user when power is autonomously available to the rest of the craft and if battery is above an acceptable voltage then continue, else kill the switch...
2. Check the battery contition constantly, voltage, draw and mAh used, to see what is happeing to the battery
3. Sent the data back the user. At the end "airmodel" version this will be down wirelessly, this module here, targets a robot, so data a sent serially to a hyperterminal or microcontroller.
4. When the battery is low. Warn the user.
5. If it goes even lower then kill, the switch.
6.Before killing save the data somewhere for later export. These data will include mAh used, killing voltage, peak voltage, average current draw and peak current draw. All very importand on maintaining the battery safe.
So step 1 what we do is:
Set the microcontroller, activate the peripherals, wait the right time for the user to end activation, once activated, warm him/her of that. Check the battery voltage to see if it has enough charge to operate without killing herself!!! Access the main routine for step 2....
Step 2 and Step 3:
Check voltage, and current draw from to ADC sorces (low Amp sensor, high Amp sensor)... Do the math so that these data are understantable by a human being. Sent them via UART to the user... Simple!!!!
Also get peak values for everything...
Step 4.... warning the user:
Since we use a buzzer and as you will see later on Timer1 is running... we enable the output on OC1A to make a siren and so on...................................
Step 5..... killing:
EEeeeehhhh, what do you want to hear here.... Just have the PORTD.4 to logic LOW.... nothing more....
Well, chronologically, step 6 happens before step 5 but.... forget it...
Just save some variables to the EEPROM, an external eeprom will be used on later on version to save the Atmega8 EEPROM from the hell of the constant read write thing....wearing the chip off...
So here is the code, that will ONLY protect the battery from low voltage:
' --------[ Device Config]---------------------------------------------------- $regfile = "m8def.dat" $crystal = 16000000 $baud = 19200 ' --------[ Variable Config ]------------------------------------------------- Dim Voltage As Word Dim Currentsum As Word Dim Current1 As Word Dim Current2 As Word ' --------[ Costant Config ]-------------------------------------------------- Const Cut_volt = 9000 ' --------[ General Port Config ]--------------------------------------------- Config Portd.4 = Output ' Kill switch enable Config Portb.1 = Output ' Buzzer circuit ' --------[ Timer Config ]---------------------------------------------------- ' Timer1 Register A Tccr1a = &B00000000 ' Normal Port Operation ' Timer1 Register B Tccr1b = &B00001011 ' Timer set to CTC mode ' Prescaler at 64 ' ORC1A Compare1a = 100 ' Produces a 1237,62Hz frequncy ' for the buzzer ' --------[ ADC config ]------------------------------------------------------ ' ADC status register Adcsra = &B11000111 ' ADC started ' First Convertion also started ' Cause we have a 16MHz clock ' we setted the prescaler to ' 128 so the ADC clock is < 200KHz Admux = &B00000000 ' External reference is applied ' Convertion data are shown right wise ' ADC channel setted to 0, but this ' is just done for setting the ADMUX register ' changes in the process ' --------[ Initialize ]------------------------------------------------------ Portb.1 = 1 ' Turn off the buzzer circuit to save energy Portd.4 = 0 ' The Kill switch is off, letting the button here terminates start up Wait 1 ' Wait some time, so the user is aware that he turns on the circuit ' and no brown out reset turns the circuit back on Tccr1a = &B01000000 ' Send some oscilations to the buzzer Waitms 200 ' for some time Tccr1a = &B00000000 ' then cut the buzzer and Portd.4 = 1 ' enable the supply permenately Voltage = 0 ' Set the variable Voltage = Getadc(0) ' Start a convertion and get the voltage Voltage = Voltage * 13 Voltage = Voltage + 100 ' Do the math so the numbers are familiar with ' human being ' Check voltage If Voltage < Cut_volt Then ' if the voltage is lower than acceptable ( 9V0 ) ' then Tccr1a = &B01000000 Waitms 100 Tccr1a = &B00000000 Waitms 100 Tccr1a = &B01000000 Waitms 100 Tccr1a = &B00000000 Waitms 100 ' warn the user and Portd.4 = 0 ' kill the circuit to save the battery End If ' --------[ Main ]------------------------------------------------------------ Main: Do Voltage = Getadc(0) Current1 = Getadc(1) Current2 = Getadc(2) ' Start a convertion and get the voltage Voltage = Voltage * 13 If Voltage <> 0 Then Voltage = Voltage + 100 End If ' Do the math so the numbers are familiar with ' human being Print Voltage ; " " ; Current1 ; " " ; Current2 ; " " ; Chr(13); ' Send data to UART Loop Until Voltage < Cut_volt ' if the condition is bridged then Tccr1a = &B01000000 Waitms 100 Tccr1a = &B00000000 Waitms 100 Tccr1a = &B01000000 Waitms 100 Tccr1a = &B00000000 Wait 5 ' warn the user and Portd.4 = 0 ' kill the circuit to save the battery End
Here are the results of the program above that shows us only voltage, but also cuts battery when low: