main.c File Reference


Detailed Description

Main.

Application note:
AVR453: Smart Battery Reference Design
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
Original author: Rob G. Fries - Apt Inc.
Revision
URL
Date

Definition in file main.c.

#include <iom406.h>
#include <inavr.h>
#include "main.h"
#include "analog.h"
#include "calibration.h"
#include "timer.h"
#include "pack.h"
#include "smbus.h"
#include "gpio.h"
#include "safety.h"
#include "pwrmgmt.h"
#include "ee.h"

Go to the source code of this file.

Defines

#define MODULE_MAIN

Functions

void AlarmConditionsCheck (void)
void AlarmModeDisabledCheck (void)
void BalanceCheck (void)
void ChargeCheck (void)
void DoCalibrate (void)
void InitAll (void)
void main (void)
void MasterSMBusCheck (unsigned char ResetTimer)
void SleepMgr (void)
void ThermalCheck (void)
void WdogMgr (void)

Variables

unsigned char AlarmModeDisabledTimer = 0
unsigned char qtrsectick = 3


Define Documentation

#define MODULE_MAIN

Definition at line 29 of file main.c.


Function Documentation

void AlarmConditionsCheck ( void   ) 

Definition at line 440 of file main.c.

References hibyte, REMAINING_CAPACITY_ALARM, REMAINING_TIME_ALARM, RemainingCap(), SMBV_BattStatus, SMBV_RemCapAlm, SMBV_RemTimeAlm, SMBvar_int, SMBvariables, and TimeToEmpty().

Referenced by main().

void AlarmModeDisabledCheck ( void   ) 

Definition at line 427 of file main.c.

References ALARM_MODE, AlarmModeDisabledTimer, hibyte, SMBV_BattMode, and SMBvariables.

Referenced by main().

void BalanceCheck ( void   ) 

Definition at line 169 of file main.c.

References CellToBalance, DisableCellBalancing(), EnableCellBalancing(), MAX_IMBALANCE, PACKSTACK, and ReadCell().

Referenced by main().

void ChargeCheck ( void   ) 

Todo:
Whenever you move 2X the capacity, either into or out of the pack, you are supposed to increment the CycleCount variable. You do NOT have to have hit both FULL and EMPTY limits.

Definition at line 243 of file main.c.

References CELL_MINV, CELL_NOMINALV, CELL_TOOLITTLEV, CELL_TOOMUCHV, Current1Sec(), DISCHARGING, FullChargeReached(), FullDischargeReached(), FULLY_CHARGED, FULLY_DISCHARGED, hibyte, lobyte, OVER_CHARGED_ALARM, PACK_DISCHG_MAX, PACK_MAX_CHG_C, ReadCell(), RelativeSOC(), SMBV_BattStatus, SMBvariables, TERMINATE_CHARGE_ALARM, and TERMINATE_DISCHARGE_ALARM.

Referenced by main().

void DoCalibrate ( void   ) 

Definition at line 560 of file main.c.

References CAL_CC_BIT_POS, CAL_CC_FAIL, CAL_CC_MASK, CAL_CC_OK, CAL_CC_RUN, CAL_FAIL, CAL_OK, CAL_VREF_BIT_POS, CAL_VREF_FAIL, CAL_VREF_MASK, CAL_VREF_OK, CAL_VREF_RUN, CalibrateCCoffset(), CalibrateVREF(), calibration_state, calibration_state_req, DisableCellBalancing(), EESTORAGE_BGCCR, EESTORAGE_CC_valid, EnableCellBalancing(), NO_CAL, ReadCCOffsetCalibration(), ReadVrefCalibration(), and RUN_CAL.

Referenced by main().

void InitAll ( void   ) 

Todo:
Re-enable the Wdog for your final code. It is disabled here to allow debugging to take place without interference.

Definition at line 56 of file main.c.

References ADCinit(), CCinit(), HWProtectinit(), InitSMBus(), InitSMBvariables(), PBinit(), PinInit(), T0init(), and T1init().

Referenced by main().

void main ( void   ) 

Definition at line 83 of file main.c.

References action_flags, AlarmConditionsCheck(), AlarmModeDisabledCheck(), AlarmModeDisabledTimer, BalanceCheck(), CalculateADCresults(), ChangePowerMode(), ChargeCheck(), Check50uS(), CheckADCScanDone, CheckAlarmMode, CheckCalibRequest, CheckMasterSMBdone, CheckQtrSec, ClrADCScanDone, ClrAlarmMode, ClrCalibRequest, ClrMasterSMBdone, ClrQtrSec, DoCalibrate(), GetGenericTimer(), InitAll(), LEDs, lobyte, MasterSMBusCheck(), OneQtrSecond, POWERMODE_POWERSAVE, qtrsectick, SetGenericTimer(), SetLEDs(), SMB_CmdInterpreter(), SMBV_BattStatus, SMBvariables, StartAdc(), ThermalCheck(), ThermistorSelect, Timer32KHz, and WdogMgr().

void MasterSMBusCheck ( unsigned char  ResetTimer  ) 

Todo:
Only a very basic charge control algorithm has been implemented. It uses the charge state to decide. It is up to the designer to implement a more sophisticated charging algorithm.

Definition at line 465 of file main.c.

References ALARM_MODE, CHARGER_ADDR, CHARGER_MODE, FULLY_CHARGED, hibyte, HOST_ADDR, lobyte, MasterInsertMsg(), OVER_CHARGED_ALARM, PACK_CCCV_C, PACK_CCCV_V, REMAINING_CAPACITY_ALARM, REMAINING_TIME_ALARM, SMB_M_CMD_ALARMWARNING, SMB_M_CMD_CHARGINGCURRENT, SMB_M_CMD_CHARGINGVOLTAGE, SMB_Master(), SMBV_BattMode, SMBV_BattStatus, SMBV_ChgCurrent, SMBV_ChgVoltage, SMBvar_int, SMBvariables, and TERMINATE_CHARGE_ALARM.

Referenced by main().

void SleepMgr ( void   ) 

Definition at line 528 of file main.c.

void ThermalCheck ( void   ) 

Todo:
The following Cell temperature checking is disabled since it is left to the user to choose a specific Thermistor.

Definition at line 384 of file main.c.

References DoShutdown(), GetTemperature(), hibyte, MAX_CELL_TEMPERATURE, MAX_ONCHIP_TEMP, OVER_TEMP_ALARM, SHUTDOWN_REASON_OVERTEMPERATURE, SMBV_BattStatus, and SMBvariables.

Referenced by main().

void WdogMgr ( void   ) 

Todo:
This code can be made more sophisticated to prevent runaways

Definition at line 548 of file main.c.

Referenced by main().


Variable Documentation

unsigned char AlarmModeDisabledTimer = 0

Definition at line 79 of file main.c.

Referenced by AlarmModeDisabledCheck(), and main().

unsigned char qtrsectick = 3

Definition at line 78 of file main.c.

Referenced by main().


Generated on Mon Nov 12 15:59:58 2007 for AVR453 Smart Battery Reference Design by  doxygen 1.5.3