I am trying to make a UPS circuit. I need to have a high speed measurement for the input AC voltage (220 Vrms) (in order to know whether to turn on/off the inverter). I had tried using this circuit:

enter image description here

It works, but it is very slow: it takes more than 500 ms just to detect any change in the voltage, which need to works simultaneously with the input AC sine wave.

Is there a better design than this (such as RMS to DC converters or voltage to frequency converter)?


Voltage needs to be measured for different processes too so using just optocouplers with some resistors won't be good (I don't need just a voltage detector).

Input voltage is from isolated DC-DC transformer 24 VDC.

"Sense GND" is the ground for this circuit.

Low voltage trigger is approx 8.5 VDC (180 Vrms) and high voltage trigger is approx 12.4 VDC (260 Vrms).

  • \$\begingroup\$ Did you design this circuit yourself, or did you get the schematic from somewhere? \$\endgroup\$ Jan 17 at 0:05
  • \$\begingroup\$ There really is no "best" method, there are just methods that are more or less suitable for what you want to achieve. So... What do you want to achieve? How fast does your circuit need to react? What does it trigger when it does trip an overvoltage or undervoltage event? Do you want to detect individual cycles of "bad AC voltage", or just a time-averaged value, or something entirely different? Or do you want to know when the AC line voltage crosses certain thresholds during each cycle? \$\endgroup\$ Jan 17 at 1:18
  • 1
    \$\begingroup\$ @JonathanS. First of all I need to be able to measure the 220 VAC waveform precisely, in the same time I need the measurement to be "real time" so no delays must be there. the circuit must take no longer than 1 ms to react. I need to measure "bad AC voltage" mostly. \$\endgroup\$ Jan 17 at 9:23
  • 1
    \$\begingroup\$ The only time specified in the datasheet was 200 ms for OCP. I would expect it to be slow with long integration time. Buy it, build a test circuit and try it? \$\endgroup\$
    – winny
    Jan 17 at 10:43
  • 1
    \$\begingroup\$ Since a half-cycle takes 10ms, asking to respond to any AC parameter within 1ms is asking to predict the future. A response time of a few half-cycles is more reasonable. The computer system you're trying to protect should also be able to handle a few half-cycles of undervoltage before it resets - there's no power at the zero crossings after all. Instantaneous overvoltage can be detected within 1ms though. \$\endgroup\$ Jan 17 at 17:29

2 Answers 2


The problem

The task is to detect both over-voltage and under-voltage, and to signal this condition within, let's say, 2 mains cycles, about 40ms.

A strategy

To detect under-voltage, the easiest "discrete" solution I can think of is to detect the presence of voltage above the minimum 180V, using a comparator, and use that to trigger a resettable monostable (one-shot) multivibrator, with a pulse duration somewhere between 1 and 2 mains cycles, say 30ms.

As long as the minimum threshold of 180V is reached, every 20ms, this monostable output will remain active, but a single "missing" cycle, or low-voltage cycle will permit the monostable to time-out. That means you're looking for a timed-out monostable state to indicate an under-voltage condition.

Over-voltage detection can employ a similar technique. Here, though, you would trigger a one-shot pulse every time a comparator detects more than 260V. The monostable output pulse should be about 30ms long, so that it remains active for as long as incoming over-voltage pulses (every 20ms) keep re-triggering it. This time, a timed-out state will indicate NO over-voltage condition.

Since we are now detecting instantaneous voltages, the switching thresholds change to \$260V_{RMS} \times \sqrt{2} = 360V\$ and \$180V_{RMS} \times \sqrt{2} = 250V\$

An implementation

Something like this could work:


simulate this circuit – Schematic created using CircuitLab

You do not need diodes D3, D4, D5 or D6. They are there purely to make the simulation properly emulate the open-collector outputs of the '393 comparators. If you use push-pull output comparators, then you must include these diodes.

You do need D1. This prevents comparator inputs being exposed to negative potentials, which could damage the comparators, and would definitely make them misbehave.

CMP1 output goes LOW when over-volt is detected. This discharges C2. If no over-voltage condition is detected, C2 is left to charge, and potential \$V_A\$ reaches \$\frac{2}{3}\$ of the 24V supply after \$R_3 \times C_2 = 33ms\$. That brings CMP3 output high, signalling no over-voltage.

CMP2 output goes HIGH when under-volt is detected, permitting C1 to charge, and \$V_B\$ to rise. As long as an input exceeding 250V potential arrives within \$R_{10} \times C_1 = 33ms\$, C1 is discharged. Otherwise, \$V_B\$ will reach \$\frac{2}{3}\$ of the supply, causing CMP4 output to go low, signalling under-voltage.

CMP3 and CMP4 outputs are connected wire-AND. If either goes low (there's an under- or over-voltage condition), \$V_{OUT}=0V\$. Only when both CMP3 and CMP4 outputs are high does \$V_{OUT}=24V\$, signalling power is within acceptable bounds.

Here's a simulation showing \$V_{OUT}\$ responding to a line input which goes in and out of bounds:

enter image description here enter image description here

Some improvements

There are a few improvements that can be made. As it is, when the inputs of CMP3 and CMP4 are pulled high, they are outside of their permissible range, so while this won't harm them, they might do strange things. It would be better to take some limiting measures there. I'll leave it like this for the moment, though, because my brain is tired.

I haven't shown them, but you shouldn't omit the usual power supply decoupling capacitors across the supply rails near the ICs.

I've made no effort to mitigate noise immunity. There are a few things one can do to help with this, such as small capacitances to remove higher frequency components of the various signals. It would be prudent to introduce positive feedback around CMP1 and CMP2, for some hysteresis, which would suppress spurious transitions near the switching thresholds.

Don't use a single resistor for R9. You should distribute the line voltage between several resistors in series, totalling close to 425kΩ, such as 6 × 68kΩ + 1 × 15kΩ.

  • \$\begingroup\$ Impressive! I have some questions if you may. Firstly, why the delay (wait) time would be 33 ms, won't that just give a delayed response from the comparator, which will not be suitable for a UPS operation? Secondly, what is the science behind connecting multiple resistors from the AC path to the circuit like for the 425kΩ resistor here? Third, what is the use of the multivibrator here, or you mean it is just the comparators output? \$\endgroup\$ Jan 17 at 10:15
  • 2
    \$\begingroup\$ @HazardousVoltage The multiple resistors are to divide the 300V into multiple chunks, say, 50V across each resistor, so that no individual resistor gets anywhere near its max. rated voltage. It also keeps the largest distance possible between two points of very different potential, so no arcing in air can occur. \$\endgroup\$ Jan 17 at 11:02
  • 1
    \$\begingroup\$ @HazardousVoltage The monostable (one-shot) multivibrators here are implemented using comparators and RC delay elements, so I can combine voltage level sensing, and triggering, timing, and the logical AND function with minimal components. You could use 74HC123 ICs or similar, but you'd still need comparators, and gates, and another, lower, supply voltage. There's probably an even better (lower component count) way to do this, but I don't want to spend days designing something. \$\endgroup\$ Jan 17 at 11:06
  • 1
    \$\begingroup\$ @HazardousVoltage The 30ms wait can be longer, but it can't be less than a single mains cycle of 20ms. The principle I outlined in the section "a strategy" requires that the monostables do not timeout before the beginning of the next cycle, the next possible "reset". If they timeout too soon, their outputs would always be oscillating at 50Hz, regardless of an over- or under-voltage condition. The earliest you can know if an existing over- or under-voltage condition has gone away, is quite some time later, maybe even after a complete cycle up and down of voltage has completed! \$\endgroup\$ Jan 17 at 11:16
  • 1
    \$\begingroup\$ @HazardousVoltage Remember, we are not measuring average, or RMS voltage any more (like your existing design does, with that RC filter at the input), we are monitoring the instantaneous voltage at all instants in time. After an over-voltage has been noticed, you won't know if it's been resolved until the next time the voltage rises to its peak again, which will be nearly one whole cycle (20ms) later. That's why I choose to wait 1.5 cycles, or 30ms, before permitting the monostable to clear itself automatically by timing out. \$\endgroup\$ Jan 17 at 11:23

Software-assisted version of Simon Fitch's circuit:

Three comparators compare instantaneous rectified mains voltage with three constant thresholds:

  • Overvoltage threshold, which should be higher than the expected peak mains voltage

Under normal circumstances, the output of this comparator never triggers. If it does, the micro knows instantly that mains voltage is over the limit, and turns on the UPS to protect the load from overvoltage.

  • Undervoltage threshold, which should be lower than the lowest expected peak mains voltage. For 230V mains, which has a normal peak of 320V, maybe around 250V threshold should do the trick.

Under normal circumstances, this comparator will trigger on every peak. So for 50Hz it will trigger every 10ms. This goes either to a MCU GPIO with a Pin Change Interrupt on it, or a MCU timer in capture mode. In both cases the MCU can measure the time interval between two consecutive pulses, and if it is higher than say 15ms, it decides there is an undervoltage.

  • Mains presence threshold, maybe 100V or so.

This is not strictly necessary, but by using the same logic as the previous one, it can allow the MCU to know that mains is present even in an undervoltage condition where the previous comparator is not triggering.

Since you need isolation, you have to decide if you put the comparators:

  • On the mains side (non-isolated), and then you isolate the outputs with opto couplers.

This makes voltage sensing very simple (a resistor divider) but it adds extra complication by requiring a separate power supply for the comparators, which must be isolated from the rest of the circuit's power supply. Otherwise the optocouplers would be useless.

  • On the microcontroller side, isolated from mains

This makes voltage sensing more complicated, because you need an isolated voltage sensor, otherwise known as the cheapest transformer you can get. But the comparators can use the same power supply as the rest of the circuit.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.