90VAC to input microcontroller PIC

Thread Starter

absdoso

Joined Mar 26, 2025
13
Hello everyone,
I have a question related to an AC/DC circuit and a microcontroller. The idea is that my PIC microcontroller can detect when the input voltage exceeds 90V. So, I'm thinking of using a bridge rectifier to convert AC to DC, then a voltage divider to step down the voltage, and finally, a comparator (like the LM393) to compare it with a reference voltage.

Has anyone here had experience with this kind of circuit? Could you give me some advice? Thank you all for reading!
Additional Notes (if needed for clarity):
  • Bridge rectifier (GBU406)→ Converts AC to pulsating DC.
  • Voltage divider → Reduces high voltage to a safe level for the microcontroller.
  • Comparator (LM393) → Compares the scaled-down voltage to a reference (e.g., 2.5V) to trigger the PIC when input > 90V.
Can u guys give me somes suggestions for component values (e.g., resistor ratios) or circuit protection (like a Zener diode) if thats in case?
 

nsaspook

Joined Aug 27, 2009
16,255
https://ww1.microchip.com/downloads...plicationNotes/ApplicationNotes/90003138A.pdf

1743007132536.png

You could use a PIC with the ZCD. You can offset the zero cross point with a resistor to make it switch at the needed voltage.
https://developerhelp.microchip.com/xwiki/bin/view/products/mcu-mpu/8bit-pic/peripherals/zcd/
Setting a Zero Cross Offset
For higher voltages, there may be times when the cross indicator is actually desired at a higher voltage than zero. This can be accomplished with a pull-down resistor. For example, consider a design where the input signal has a peak voltage of 300 V. This would require a 1 megohm resistor to limit the current to the 300 ua the ZCD module requires. The zero cross point will occur when the input voltage at the ZCPINV voltage of 0.75 volts or near zero relative to the 300v peak.

Now if a 7.5k resistor were added from the input pin to ground, the 7.5k resistor would require the ZCP module to source current through the 7.5k resistor to maintain the 0.75 volts ZCPINV level. That current would be equal to:

(6 ) 0.75v / 7.5k = 100ua

The input signal would need to supply that 100 ua extra current to balance out the ZCD input so it will not source or sink current. When the input signal is at 100 volts, then the 1 meg resistor will limit the current to 100 ua thus supplying the 100 ua for the 7.5k pull-down. The ZCD can consequently maintain the ZCPINV voltage without sourcing or sinking current.
The pull-down resistor has shifted the zero cross point from near zero volts to near 100 volts thus offsetting the zero cross detection point.

The same technique can be used to offset the zero cross detect point in the negative direction with a pull-up from the ZCD pin and Vdd of the PIC MCU.
 

Thread Starter

absdoso

Joined Mar 26, 2025
13
Thank you for your feedback! I forgot about the galvanic isolation!!
I’m using a PIC24FJ64GA104 , and the detection needs to be instantaneous (real-time).
Correct me if I’m wrong: So the solution is using a transformer to step down 90V AC to 12/5/3.3V AC, then rectify and condition it for the PIC’s comparator? Could you explain what the best reference voltage is for the comparator’s other analog input?
 

John P

Joined Oct 14, 2008
2,051
I don't know what the effect of an optocoupler would be. You won't get a linear response from it, so detecting a threshold might not work very well, although perhaps you could calibrate it, if you can control the voltage and measure it with a meter you trust. Using a transformer would make the circuit safer and would replace a voltage divider.
 

John P

Joined Oct 14, 2008
2,051
I was thinking of more On/Off control, linear response not needed?
That's not clear in the original question. It's a case of wanting to "detect when the input voltage exceeds 90V" with a mention of a comparator, so I assume there really is a threshold voltage and an on/off result. I think the transition from the high-voltage to the low-voltage side has to be done as an analog quantity.
 

Irving

Joined Jan 30, 2016
5,002
I've been using these cheap 1:1 voltage transformers, ZMPT107, for AC voltage detection. Basically they need a 2mA current on the primary and will produce 0.6v rms across a 300ohm load on the secondary. Feed the output direct to an ADC input via a simple low-pass filter, take a few tens of samples and some simple math will give you the AC voltage within about 2% out of the box, better with calibration. IMHO they are much better, cheaper, and safer, than an opto solution
1743344643859.png

1743344238735.png
 

nsaspook

Joined Aug 27, 2009
16,255
I've been using these cheap 1:1 voltage transformers, ZMPT107, for AC voltage detection. Basically they need a 2mA current on the primary and will produce 0.6v rms across a 300ohm load on the secondary. Feed the output direct to an ADC input via a simple low-pass filter, take a few tens of samples and some simple math will give you the AC voltage within about 2% out of the box, better with calibration. IMHO they are much better, cheaper, and safer, than an opto solution
View attachment 345657

View attachment 345656
+1

That is a good solution to the isolation and linear values issues.
 

Thread Starter

absdoso

Joined Mar 26, 2025
13
I've been using these cheap 1:1 voltage transformers, ZMPT107, for AC voltage detection. Basically they need a 2mA current on the primary and will produce 0.6v rms across a 300ohm load on the secondary. Feed the output direct to an ADC input via a simple low-pass filter, take a few tens of samples and some simple math will give you the AC voltage within about 2% out of the box, better with calibration. IMHO they are much better, cheaper, and safer, than an opto solution
View attachment 345657

View attachment 345656
Thank you so much! I was considering the IRM-02-12, but your transformer is the ideal solution in this case!
 

Thread Starter

absdoso

Joined Mar 26, 2025
13
That's not clear in the original question. It's a case of wanting to "detect when the input voltage exceeds 90V" with a mention of a comparator, so I assume there really is a threshold voltage and an on/off result. I think the transition from the high-voltage to the low-voltage side has to be done as an analog quantity.
You're absolutely right. My primary goal is to enable the PIC to detect when the input AC voltage exceeds 90V and then trigger a 24V output signal (also controlled by a PIC output). That's why I need a comparator to perform this threshold comparison.
 

Irving

Joined Jan 30, 2016
5,002
Thank you so much! I was considering the IRM-02-12, but your transformer is the ideal solution in this case!
Glad I can help.

Make sure your input resistor R101 is rated for the peak AC voltage eg 90 * √2 = 130V and then a safety factor (x 2 isn't unusual), so 250V, particularly if using SMD parts. FYI, here's my schematic & PCB layout for 2 (of 4) sampling ports on 240v AC hence two resistors in series on the primary side and >3mm track spacing between LINE and anything else. I'm using a cheap 4-channel SPI-connected 10-bit ADC because it was easier than trying to run low-voltage analogue through the maze of power wiring and there are not enough ADC ports on an ESP32-S3 (I need 12 channels, and there are only 8 effectively available on the ESP32 if you're using WIFI and I2C), and cheaper than an analogue mux IC!

1743431654537.png1743432196501.png
 
Top