move magic values to defines

This commit is contained in:
Olaf Rempel 2007-10-08 00:15:31 +02:00
parent 82fd0d1138
commit 4202fb9fc5
1 changed files with 12 additions and 6 deletions

View File

@ -58,6 +58,12 @@
#define MOD_CHARGING 0x01
#define MOD_READY 0x02
#define VOLTAGE_CONNECT 9000
#define VOLTAGE_CHARGE 12450
#define CURRENT_CHARGE 16000
#define CURRENT_READY 2000
#define VOLTAGE_REMOVE 1000
static void lcd_wait_busy(void)
{
uint8_t status;
@ -222,11 +228,11 @@ ISR(TIMER0_OVF_vect)
* and a current limit of 1.6A
*/
if (mode == MOD_CHARGING) {
if (voltage < 12425 && current < 15500)
if (voltage < (VOLTAGE_CHARGE -25) && current < (CURRENT_CHARGE -500))
if (pwm < 0xff)
pwm++;
if (voltage > 12450 || current > 16000)
if (voltage > VOLTAGE_CHARGE || current > CURRENT_CHARGE)
if (pwm > 0x00)
pwm--;
@ -240,19 +246,19 @@ ISR(TIMER0_OVF_vect)
switch (mode) {
case MOD_WAITING:
/* start charging when a voltage > 9V is detected (lipo connected) */
if (voltage > 9000)
if (voltage > VOLTAGE_CONNECT)
mode = MOD_CHARGING;
break;
case MOD_CHARGING:
/* end charging if voltage > 12.42V and current < 200mA */
if (voltage > 12425 && current < 2000)
/* end charging if voltage > 12.45V and current < 200mA */
if (voltage >= VOLTAGE_CHARGE && current < CURRENT_READY)
mode = MOD_READY;
break;
case MOD_READY:
/* wait for lipo disconnect */
if (voltage < 1000)
if (voltage < VOLTAGE_REMOVE)
mode = MOD_WAITING;
break;
}