IB Peter Feucht kabelbw.de> writes: > I developped a small battery operated device, using a 16F684, everything > works fine. Now the customer shows up, and wants to have any sort of > batt-low indication. For already 1000 PCS are made and assembled, there i= st You can use statistics to determine if the BORs are becoming too frequent (= a sign for low battery). It works like so: - A new battery may cause BORs at turn on and turn off, several even. Let's= call this number of BORs N1, say, 3. Also, they will occur during the 'turn on' = or 'turn off' phase, which you can account for with a state machine in the sof= tware. - A weak battery will cause BORs every now and then, when external loads ar= e connected especially. They will occur in normal operation (not when startin= g and stopping, see above state machine). Let's call this new number of BORs N2, = which will normally be way bigger than 3, but let's say 5 for now. - If any of your comparator or ADC inputs depend on battery voltage directl= y you can change your code to 'measure' battery voltage using those. Now you can implement a state machine like: if( ResetOccurredByBor() && (State !=3D ST_STOP) ) { // do not count BORs when stopping power - assumes mcu can turn its // own power off in some way IncrementNumBors(); } if( UserPressedNumBorReset() ) { // start fresh cycle, hope batteries are n= ew SetNumBors(0); SetLockout(0); while( UserPressedBorReset() ); // wait ... } tmp =3D GetState(); if( (t =3D=3D ST_START) || (t =3D=3D ST_STOP) ) { if( GetNumBors() > MAX_N1 ) SetLockout(2); // most severe, battery very w= eak or bad contacts } else { if( GetNumBors() > MAX_N2 ) SetLockout(1); // likely weak battery, resets= in mid-operation,=20 } switch( GetLockout() ) { case 0: ; // all is well, operate normally break; case 1: ; // battery may be low, turn on low battery ind., try to work break; case 2: ; // we don't want to work at all, battery end ind., loop forever lockout: goto lockout; } =20 Where Lockout is a variable you set which shuts down the device (or makes i= t=20 in-operable and indicates low battery). You can even set the Lockout bit in EEPROM so it will require a device reset on battery change from the user (pushing a specified button, not the reset mcu signal). The State and NumBo= rs variables above should me located in a place that is not wiped by RESET (us= ually RAM assuming the mcu always has power and is sleeping between active uses),= and if you use a C compiler be sure to edit the startup code so those locations= are really left alone during initialization, if your compiler's startup code wi= pes all ram by default. You can refine this by having additional steps of NumBors > LOW_N1 etc to indicate imminent battery failure. And, yes, this is a hack, unless you have comparator or ADC information abo= ut something directly related to battery state, but you have 1000 products and= your good name (?) to save. -- Peter --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .