overcharge and discharge protection for flashlight  - Page 1
Forum section: electronics / projects

author: jeffd1988
author_rank: Newbie
timestamp: August 06, 2015, 07:54:53 pm
content: hi guys new here I'm Jeff i have bad grammar and this might seem trivial and really long to you but I am looking for some projects to do that involve programing that is new to me I'm in what i call an arduino bubble and what i want to do is slowly move out of arduino so anyway i started a teardown of an LED flashlight that charges off a small solar panel that when shorted it outputs 65ma in full sun and 4.6v with no load now when i bought this it came completely dead so i left it in the sun to charge but it never held a charge good i checked the mah of the battery it has 200mah tops and this is right after i charged it if it had sat for 12hours it might even be a lot less... it says 700mah and its a 2s AAA 2.4v pack ni-mh but i did some more testing and there is no over-charge protection or under-voltage protectionits just a switch that opens and closes a circuit to a bust/buck or invert converter but it can only step down from about 3.9v after that the voltage starts to go up and out of control so it can't use a lipobut it can bust down to .4v so it should work if i put new battery's in it but they would probably go bad because of over discharge so what i want to do is take a attiny45 and program it to turn the light on or turn a load on to prevent it from over charging and to keep it from over discharging i was thinking i could use a mosfet to open and close the circuit between the battery and the switch to prevent over discharge now i would need to get an attiny45v so the voltage go's low enough but i have attiny45 20pu's so i can start prototyping now if you have come up with any problems with doing this so for just let me know the only thing i could think of is that the bat voltage go's to low the attiny shuts down and leaves the output pin high to the mosfet i don't think it can even do that but if it did the battery would over discharges but i don't see how that could happen if it's checking to see if the voltage is to low all the time when the LED is on. so what i need to learn is sleep modes the adc and interrupts im sorry this is getting so long but is it possible to wake the attiny45 from an external interrupt and a timer?i found some info on sleeping herehttp://www.technoblogy.com/show?KX0and some code that i think i can change to work with the attiny45Code:// Function created to obtain chip's actual Vcc voltage value, using internal bandgap reference// This demonstrates ability to read processors Vcc voltage and the ability to maintain A/D calibration with changing Vcc// Results printed to serial monitor @ 38400 baud are volt X 100, i.e 5 volts = 500// Now works for 168/328 and mega boards.// Thanks to "Coding Badly" for direct register control for A/D mux// 1/13/10 "retrolefty"int battVolts; // made global for wider avaliblity throughout a sketch if needed, example for a low voltage alarm, etc// value is volts X 100, 5 vdc = 500void setup(void){Serial.begin(38400);Serial.print("volts X 100");Serial.println( "\r\n\r\n" );delay(100);}void loop(void){for (int i=0; i <= 3; i++) battVolts=getBandgap(); //4 readings required for best stable value?Serial.print("Battery Vcc volts = ");Serial.println(battVolts);Serial.print("Analog pin 0 voltage = ");Serial.println(map(analogRead(0), 0, 1023, 0, battVolts));Serial.println();delay(1000);}int getBandgap(void){#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)// For mega boardsconst long InternalReferenceVoltage = 1115L; // Adust this value to your boards specific internal BG voltage x1000// REFS1 REFS0 --> 0 1, AVcc internal ref.// MUX4 MUX3 MUX2 MUX1 MUX0 --> 11110 1.1V (VBG)ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX4) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);#else// For 168/328 boardsconst long InternalReferenceVoltage = 1050L; // Adust this value to your boards specific internal BG voltage x1000// REFS1 REFS0 --> 0 1, AVcc internal ref.// MUX3 MUX2 MUX1 MUX0 --> 1110 1.1V (VBG)ADMUX = (0<<REFS1) | (1<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (1<<MUX1) | (0<<MUX0);#endif// Start a conversionADCSRA |= _BV( ADSC );// Wait for it to completewhile( ( (ADCSRA & (1<<ADSC)) != 0 ) );// Scale the valueint results = (((InternalReferenceVoltage * 1024L) / ADC) + 5L) / 10L;return results;}i would need to change the code to use the vcc as Vref and the Input Channel stays 1.1v internal reference but mux1 needs to change to 0 here is the new codeCode:ADMUX = (0<<REFS1) | (0<<REFS0) | (0<<ADLAR) | (1<<MUX3) | (1<<MUX2) | (0<<MUX1) | (0<<MUX0);wouldn't this be the same as above im new to c language i know almost nothing about itCode:ADMUX = 0b00001100;there is also a note for setting input channel to 1.1v ref (vgb) that reads"After switching to internal voltage reference the ADCrequires a settling time of 1ms before measurements are stable. Conversions starting before this may not be reliable. The ADC must be enabled during the settling time""The ADC must be enabled during the settling time" does it mean i need to set the ADEN bit in Register ADCSRA to 1 after i set the input channel to 1.1v vref (vbg) or just that the adc needs to be enabled while the 1ms is taking place not necessarily be enabled during the settling timeso this is my project if anyone wants to help me with it i would like that