* settings and supported devices see readme.html\r
*\r
* \author\r
* Atmel Corporation: http://www.atmel.com \n\r
* Support email: avr@atmel.com\r
*\r
* settings and supported devices see readme.html\r
*\r
* \author\r
* Atmel Corporation: http://www.atmel.com \n\r
* Support email: avr@atmel.com\r
*\r
// +/- BAT_CURRENT_HYST.\r
if ((adcs_avgIBAT_tmp < 0) ||\r
(adcs_avgIBAT_tmp < (ChargeParameters.Current - BAT_CURRENT_HYST))) {\r
// +/- BAT_CURRENT_HYST.\r
if ((adcs_avgIBAT_tmp < 0) ||\r
(adcs_avgIBAT_tmp < (ChargeParameters.Current - BAT_CURRENT_HYST))) {\r
if(!PWM_IncrementDutyCycle()) {\r
#ifdef ABORT_IF_PWM_MAX\r
// If the duty cycle cannot be incremented, flag error and\r
if(!PWM_IncrementDutyCycle()) {\r
#ifdef ABORT_IF_PWM_MAX\r
// If the duty cycle cannot be incremented, flag error and\r
}\r
} else if ((adcs_avgIBAT_tmp >= 0) &&\r
(adcs_avgIBAT_tmp > (ChargeParameters.Current + BAT_CURRENT_HYST))) {\r
}\r
} else if ((adcs_avgIBAT_tmp >= 0) &&\r
(adcs_avgIBAT_tmp > (ChargeParameters.Current + BAT_CURRENT_HYST))) {\r
if(!PWM_DecrementDutyCycle()) {\r
#ifdef ABORT_IF_PWM_MIN\r
// If the duty cycle cannot be decremented, flag error and\r
if(!PWM_DecrementDutyCycle()) {\r
#ifdef ABORT_IF_PWM_MIN\r
// If the duty cycle cannot be decremented, flag error and\r
// If Master has flagged for a charge inhibit, pause charging.\r
// (This is to prevent damage during prolonged serial communication.)\r
if (eeprom_read_byte(&BattControl[BattActive]) & BIT_BATTERY_CHARGE_INHIBIT) {\r
// If Master has flagged for a charge inhibit, pause charging.\r
// (This is to prevent damage during prolonged serial communication.)\r
if (eeprom_read_byte(&BattControl[BattActive]) & BIT_BATTERY_CHARGE_INHIBIT) {\r
*\r
* The function also checks if the battery temperature is within limits,\r
* if mains is OK, and if BatteryCheck() returns TRUE.\r
*\r
* The function also checks if the battery temperature is within limits,\r
* if mains is OK, and if BatteryCheck() returns TRUE.\r
unsigned int adcs_rawNTC_tmp, adcs_VBAT_tmp;\r
signed int adcs_avgIBAT_tmp;\r
unsigned char sreg_saved;\r
unsigned int adcs_rawNTC_tmp, adcs_VBAT_tmp;\r
signed int adcs_avgIBAT_tmp;\r
unsigned char sreg_saved;\r
// (Gets overridden if either mains is failing, or the battery changes.)\r
for (i = 0x01; i != 0; i <<= 1) {\r
if (HaltParameters.HaltFlags & i) {\r
// (Gets overridden if either mains is failing, or the battery changes.)\r
for (i = 0x01; i != 0; i <<= 1) {\r
if (HaltParameters.HaltFlags & i) {\r
switch (i) {\r
// Is VBAT less than the recorded maximum?\r
case HALT_VOLTAGE_DROP:\r
// Update VBATMax if VBAT is higher. Evaluate for halt otherwise.\r
if (adcs_VBAT_tmp > HaltParameters.VBATMax) {\r
HaltParameters.VBATMax = adcs_VBAT_tmp;\r
switch (i) {\r
// Is VBAT less than the recorded maximum?\r
case HALT_VOLTAGE_DROP:\r
// Update VBATMax if VBAT is higher. Evaluate for halt otherwise.\r
if (adcs_VBAT_tmp > HaltParameters.VBATMax) {\r
HaltParameters.VBATMax = adcs_VBAT_tmp;\r
if (adcs_rawNTC_tmp > HaltParameters.LastNTC) {\r
HaltParameters.LastNTC = adcs_rawNTC_tmp;\r
Time_Set(TIMER_TEMP,0,30,0);\r
if (adcs_rawNTC_tmp > HaltParameters.LastNTC) {\r
HaltParameters.LastNTC = adcs_rawNTC_tmp;\r
Time_Set(TIMER_TEMP,0,30,0);\r
// Is the increase in temperature greater than the set threshold?\r
} else if ((HaltParameters.LastNTC - adcs_rawNTC_tmp) >=\r
(BattData.ADCSteps * HaltParameters.TemperatureRise)) {\r
// Is the increase in temperature greater than the set threshold?\r
} else if ((HaltParameters.LastNTC - adcs_rawNTC_tmp) >=\r
(BattData.ADCSteps * HaltParameters.TemperatureRise)) {\r
// temperature is rising faster than we want.\r
// If not, update LastNTC and reset timer.\r
if (Time_Left(TIMER_TEMP)) {\r
// temperature is rising faster than we want.\r
// If not, update LastNTC and reset timer.\r
if (Time_Left(TIMER_TEMP)) {\r
// battery and flag it as exhausted. Make ST_ERROR next state.\r
if (HaltParameters.HaltFlags & HALT_FLAG_EXHAUSTION) {\r
PWM_Stop();\r
// battery and flag it as exhausted. Make ST_ERROR next state.\r
if (HaltParameters.HaltFlags & HALT_FLAG_EXHAUSTION) {\r
PWM_Stop();\r
Battery_t tmp = eeprom_read_byte(&BattControl[BattActive]);\r
tmp &= ~BIT_BATTERY_ENABLED; // Enabled = FALSE;\r
eeprom_write_byte(&BattControl[BattActive], tmp);\r
Battery_t tmp = eeprom_read_byte(&BattControl[BattActive]);\r
tmp &= ~BIT_BATTERY_ENABLED; // Enabled = FALSE;\r
eeprom_write_byte(&BattControl[BattActive], tmp);\r
BattData.Exhausted = TRUE;\r
SetErrorFlag(ERR_BATTERY_EXHAUSTED);\r
ChargeParameters.NextState = ST_ERROR;\r
}\r
}\r
break;\r
BattData.Exhausted = TRUE;\r
SetErrorFlag(ERR_BATTERY_EXHAUSTED);\r
ChargeParameters.NextState = ST_ERROR;\r
}\r
}\r
break;\r
// Battery too cold or hot?\r
if ((BattData.Temperature <= HaltParameters.TemperatureMin) ||\r
(BattData.Temperature >= HaltParameters.TemperatureMax)) {\r
// Battery too cold or hot?\r
if ((BattData.Temperature <= HaltParameters.TemperatureMin) ||\r
(BattData.Temperature >= HaltParameters.TemperatureMax)) {\r