25.02.2012, 02:59 PM
Kritik?
Du hast immer noch zum Ende von ChargeBattery diese "if-else"-Sache drin. Ich empfahl, die if-Klammer mit einem return abzuschließen und Dir so die else Anweisung zu sparen.
void ChargeBattery (void) {
if (CHARGEirq) { // check battery 2x / 1sec
CHARGEirq = 0; // done
// DC input powering the charger?
DDRB &= ~(ChargeInOut|BatteryIn); // ADC-ports=input
ADMUX = ADMUXdefault |(1<<MUX1); // ADCin=ChargeInOut=pin3=PB4=ADC2, result left adj
ADCSRA = ADCSRAdefault; // start ad-conversion
while (0 == (ADCSRA & (1<<ADIF))); // irq-flag set at eof ad-conversion
ADCSRA |= (1<<ADIF); // clear irq flag
VChargeInOut = ADCH; // bit9..2 , 8bit result
// measure Battery voltage
ADMUX = ADMUXdefault |(1<<MUX1)|(1<<MUX0); // ADCin=BattMoni=pin2=PB3=ADC3
ADCSRA = ADCSRAdefault; // start ad-conversion
while (0 == (ADCSRA & (1<<ADIF))); // irq-flag set at eof ad-conversion
ADCSRA |= (1<<ADIF); // clear irq flag
VBattery = ADCH; // bit9..2 , 8bit result
ADCSRA &= ~(1<<ADEN); // done: ADC=off saves power during sleep
DDRB = DDRBdefault; // restore portmodes
// 2-point hysteretic battery charge
if (VChargeInOut>MainsThreshold) { // external DC-input?
EXTon = 1;
if (VBattery<VChargeMin) {
PORTB &= ~ChargeInOut; // active lo
CHARGEon = 1;
}
if (VBattery>VChargeMa {
PORTB |= ChargeInOut; // passive hi
CHARGEon = 0;
}
return;
}
// else // unnötig
EXTon = 0;
}
}
Du hast immer noch zum Ende von ChargeBattery diese "if-else"-Sache drin. Ich empfahl, die if-Klammer mit einem return abzuschließen und Dir so die else Anweisung zu sparen.
void ChargeBattery (void) {
if (CHARGEirq) { // check battery 2x / 1sec
CHARGEirq = 0; // done
// DC input powering the charger?
DDRB &= ~(ChargeInOut|BatteryIn); // ADC-ports=input
ADMUX = ADMUXdefault |(1<<MUX1); // ADCin=ChargeInOut=pin3=PB4=ADC2, result left adj
ADCSRA = ADCSRAdefault; // start ad-conversion
while (0 == (ADCSRA & (1<<ADIF))); // irq-flag set at eof ad-conversion
ADCSRA |= (1<<ADIF); // clear irq flag
VChargeInOut = ADCH; // bit9..2 , 8bit result
// measure Battery voltage
ADMUX = ADMUXdefault |(1<<MUX1)|(1<<MUX0); // ADCin=BattMoni=pin2=PB3=ADC3
ADCSRA = ADCSRAdefault; // start ad-conversion
while (0 == (ADCSRA & (1<<ADIF))); // irq-flag set at eof ad-conversion
ADCSRA |= (1<<ADIF); // clear irq flag
VBattery = ADCH; // bit9..2 , 8bit result
ADCSRA &= ~(1<<ADEN); // done: ADC=off saves power during sleep
DDRB = DDRBdefault; // restore portmodes
// 2-point hysteretic battery charge
if (VChargeInOut>MainsThreshold) { // external DC-input?
EXTon = 1;
if (VBattery<VChargeMin) {
PORTB &= ~ChargeInOut; // active lo
CHARGEon = 1;
}
if (VBattery>VChargeMa {
PORTB |= ChargeInOut; // passive hi
CHARGEon = 0;
}
return;
}
// else // unnötig
EXTon = 0;
}
}