Automatic battery charger for variable input voltage