charge.h File Reference


Detailed Description

Headerfile for NIMHcharge.c and LIIONcharge.c.

Contains definitions and declarations related to the charge state.

Application note:
AVR458: Charging Li-Ion Batteries with BC100
Documentation
For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com
$Name$
Revision
2261
$RCSfile$
URL
http://svn.norway.atmel.com/AppsAVR8/avr463_Charging_NiMH_Batteries_with_BC100/tags/20070904_release_code_1.0/code/IAR/charge.h
Date
2007-08-10 09:28:35 +0200 (fr, 10 aug 2007)

Definition in file charge.h.

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

unsigned char Charge (unsigned char inp)
 Controls the charging.


Function Documentation

unsigned char Charge ( unsigned char  inp  ) 

Controls the charging.

This function contains the charging algorithm itself, divided into stages.
For each stage the PWM may be started/stopped, and the timer, halt-requirements and charge parameters may be set.
The charging functions return whatever state is next, and as long as no errors occur this is the next charging stage.

Note:
If more stages are needed simply define more states in menu.h, include them in menu_state[] in menu.c, then add the cases to this function.

This algorithm is for NiMH batteries.

Definition at line 64 of file NIMHcharge.c.

References BAT_TEMPERATURE_MAX, BAT_TEMPERATURE_MIN, BAT_TIME_PREQUAL, BAT_VOLTAGE_DROP, BAT_VOLTAGE_MAX, BAT_VOLTAGE_PREQUAL, BattActive, BattControl, BattData, Batteries_struct::Capacity, Batteries_struct::Charged, ChargeParameters, ConstantCurrent(), ChargeParameters_struct::Current, CurrentState, HALT_FLAG_EXHAUSTION, HALT_TEMPERATURE_RISE, HALT_TIME, HALT_VOLTAGE_DROP, HALT_VOLTAGE_MAX, HaltParameters_struct::HaltFlags, HaltParameters, HaltParameters_struct::LastNTC, Batteries_struct::MaxTime, ChargeParameters_struct::NextState, PWM_Start(), PWM_Stop(), ST_BATCON, ST_ENDCHARGE, ST_FASTCHARGE, ST_INIT, ST_LOWRATECHARGE, ST_PREQUAL, ST_SLEEP, HaltParameters_struct::TemperatureMax, HaltParameters_struct::TemperatureMin, HaltParameters_struct::TemperatureRise, Time_Set(), TIMER_CHG, TRUE, HaltParameters_struct::VBATMax, HaltParameters_struct::VoltageDrop, and HaltParameters_struct::VoltageMax.

00065 {
00066         unsigned char NextState;
00067 
00068         switch (CurrentState) {
00069         // First stage is a prequalification. Attempt to charge battery to 1 V,
00070         // using a 0.1 C current, within 2 minutes.
00071         // If this fails, the battery is likely damaged.
00072         // If it succeeds, start a fast charge.
00073         case ST_PREQUAL:
00074                 
00075                 // Set up charge current and next state.
00076                 ChargeParameters.Current = BattData.Capacity / 10;
00077                 ChargeParameters.NextState = ST_FASTCHARGE;
00078                 
00079                 // Halt charge on voltage limit or timeout.
00080                 // Timeout means battery exhaustion.
00081                 HaltParameters.HaltFlags = (HALT_VOLTAGE_MAX | HALT_TIME |
00082                                             HALT_FLAG_EXHAUSTION);
00083                 
00084                 // Set up voltage limit and temperature limits.
00085                 HaltParameters.VoltageMax = BAT_VOLTAGE_PREQUAL;
00086                 HaltParameters.TemperatureMin = BAT_TEMPERATURE_MIN;
00087                 HaltParameters.TemperatureMax = 35;
00088                 
00089                 // Reset temperature measurement for HaltNow().
00090                 HaltParameters.LastNTC = 0;
00091                 
00092                 // Start PWM and charge timer before calling the charge function.
00093                 PWM_Start();
00094                 Time_Set(TIMER_CHG, BAT_TIME_PREQUAL, 0, 0);
00095                 
00096                 // Call charge function, get next state.
00097                 NextState = ConstantCurrent();
00098         break;
00099 
00100 
00101         // Second stage is a fast charge. Charge at 1.0 C for at most 1.5 hours,
00102         // until either rate of temperature increase or voltage reaches limit, or
00103         // the voltage drops sufficiently.
00104         // Timeout doesn't mean battery exhaustion now.
00105         case ST_FASTCHARGE:
00106 
00107                 // Set up charge current and next state.
00108                 ChargeParameters.Current = BattData.Capacity;
00109                 ChargeParameters.NextState = ST_LOWRATECHARGE;
00110                 
00111                 // Halt charge on voltage limit, timeout, voltage drop or rate of 
00112                 // temperature increase.
00113                 HaltParameters.HaltFlags = (HALT_VOLTAGE_MAX | HALT_TIME |
00114                                             HALT_VOLTAGE_DROP | HALT_TEMPERATURE_RISE);
00115                 
00116                 // Set up limits for voltage, voltage drop, temperature and rate of 
00117                 // temperature increase (1 degree C per minute).
00118                 HaltParameters.VoltageMax = BAT_VOLTAGE_MAX;
00119                 HaltParameters.VoltageDrop = BAT_VOLTAGE_DROP;
00120                 HaltParameters.TemperatureMax = BAT_TEMPERATURE_MAX;
00121                 HaltParameters.TemperatureRise = 1;
00122                 
00123                 // Reset maximum voltage measurement for HaltNow().
00124                 HaltParameters.VBATMax = 0;
00125 
00126                 // Start timer, PWM should still be running.
00127                 Time_Set(TIMER_CHG, BattData.MaxTime, 0, 0);
00128 
00129                 // Call charge function, get next state.
00130                 NextState = ConstantCurrent();
00131         break;
00132 
00133 
00134         // Last stage is a trickle charge. Charge at 0.1 C for at most 30 minutes,
00135         // until either rate of temperature increase or voltage reaches limit.
00136         case ST_LOWRATECHARGE:
00137                 
00138                 // Set up charge current and next state.
00139                 ChargeParameters.Current = BattData.Capacity / 10;
00140                 ChargeParameters.NextState = ST_ENDCHARGE;
00141                 
00142                 // Halt charge on voltage limit, timeout or temperature rise.
00143                 // Use the same requirements as during the last stage (ST_FASTCHARGE).
00144                 HaltParameters.HaltFlags = (HALT_VOLTAGE_MAX | HALT_TIME |
00145                                             HALT_TEMPERATURE_RISE);
00146 
00147                 // Start timer, 30 minutes.
00148                 Time_Set(TIMER_CHG, 30, 0, 0);
00149                 
00150                 // Call charge function, get next state.
00151                 NextState = ConstantCurrent();
00152         break;
00153 
00154 
00155         // Charging is done!
00156         case ST_ENDCHARGE:
00157 
00158                 // Stop the PWM output and flag battery as charged.
00159                 PWM_Stop();
00160                 BattData.Charged = TRUE;
00161                 
00162                 // If the other battery is enabled go to ST_BATCON, otherwise
00163                 // go to ST_SLEEP.
00164                 if (BattControl[(BattActive+1)%2].Enabled) {
00165                         NextState = ST_BATCON;
00166                 } else {
00167                         NextState = ST_SLEEP;
00168                 }               
00169         break;
00170 
00171 
00172         default:  // Shouldn't end up here. Reinitialize for safety.
00173                 NextState = ST_INIT;
00174                 break;
00175         }
00176 
00177         // Return the next state to main().
00178         return(NextState);
00179 }

Here is the call graph for this function:


Generated on Tue Sep 4 19:17:57 2007 for AVR463 Charging NiMH Batteries with ATAVRBC100 by  doxygen 1.5.2