Code

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 2

15146_Code CHARGING CIRCUIT CODE LIST

#define #define #define #define FULL_MODE 1 // Full charging mode STAND_BY_MODE 0 Stand by mode // MosfetOf f ( )PORTD |= _BV(4) MosfetOn() PORTD &= ~_BV(4)

//ADC function unsigned int Adc(unsigned char input){ unsigned int result; // Reading ADC input ADMUX=0xC0+input; // Internal REF 2,56V, Right adjusted result ADCSRA=0XC7; // ADEN, ADSC, -ADATE, -ADIF, -ADIE, ADPS2, ADPS1, ADPS0 // Waiting for conversion end while(!(ADCSRA & _BV(ADIF))); // First read ADSL result = ADCL + (ADCH<<8); return(result); } //Charging algorithm void ChargerSubfunction(void){ int Voltage, temperature; // Input device voltage, static char ChargeMode=FULL_MODE; //ADC of input device voltage Voltage=Adc(1)*2.5*7.666; // 1LSB=2.5mV, divider (22K+3K3)/3K3= 7.666 //Temperature correction temperature=(518-Adc(0))*0.625; // 518 corresponds to 0oC //Two diodes gives 2*2mC/C, 1LSB=2.5mV => 2.5mV/4mV=0.645 Voltage += temperature*4*6; // 4mv/C/Cell, battery have six cells //Checking of input device voltage if(Voltage > 17000)MosfetOn(); // if V>17000mV MOSFET turns-on else { if(ChargeMode == FULL_MODE){ if(Voltage > 15000){ MosfetOff(); // if V>15000mV MOSFET turns-off ChargeMode = STAND_BY_MODE; } else MosfetOn(); } else if(ChargeMode == STAND_BY_MODE){ if(Voltage < 13000){ MosfetOn(); // if V<13000mV MOSFET turns-on ChargeMode = FULL_MODE; } else if(Voltage < 13800) MosfetOn();

else if(Voltage > 14000) MosfetOff(); } } }

You might also like