An uninterruptible power system has a transformer with a primary connected to input terminals, a secondary connected to output terminals, a static switch connected between the input terminals and the primary, and an auxiliary primary connected to an inverter which is supplied by a battery to provide output voltage to the output terminals when a main AC power system connected to the input terminals has failed. The primary has multiple taps at different voltage levels and a buck-boost winding. The taps of the transformer are switched and the buck-boost winding is controlled to provide either buck, boost, or pass-by to allow control of the output voltage from the transformer to within a few percent of a desired voltage level despite large changes in the input voltage. A battery charger coupled to the auxiliary primary operates as a boost converter to provide current to charge the battery at a current level which tracks the input voltage from the AC power system, thereby providing a substantially unity power factor to the AC power system. The voltage control of the output voltage also controls the voltage at the output of the auxiliary primary to which the battery charger is connected, whereby the voltage applied to the charger is substantially regulated and the output power of the charger itself is substantially regulated. The charger can be operated in programmable modes to provide a desired charge configuration for the battery. Detection of faults in the AC power system is enhanced by accurate detection of the zero crossings of the input voltage from the AC power system, and by comparison of the AC input power waveform with an adaptive reference.