EEVblog Electronics Community Forum

Electronics => Projects, Designs, and Technical Stuff => Topic started by: Delta on November 18, 2015, 02:40:22 pm

Title: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Delta on November 18, 2015, 02:40:22 pm
I'm building a microcontroller based project, which will run of the 5VSB from an ATX PSU, and the MCU will turn on the PSU when it needs to power stuff up.

I'd like to use the 50hz line frequency as a timebase for the a software RTC in the MCU (I know I could use a 32k crystal, or a proper RTC chip of module, but this is just a hobby project, and I'd like to try using the line freq as a reference), so is there a way to pick it out of the PSU?

I've looked at some schematics, and I think the answer will be a big "no".  So if that's the case, is there a safe way to get a 50hz reference without connecting directly to the mains.  I don't want to use an additional transformer.
I was thinking some kind of inductive coupling to a mains conductor, driving a high impedance FET input.  I know 50/60hz can find its way into all sorts of circuits and cause problems, so how can I harness it constructively?

Cheers!
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Richard Crowley on November 18, 2015, 02:49:00 pm
http://www.atmel.com/images/doc2508.pdf (http://www.atmel.com/images/doc2508.pdf)
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: dom0 on November 18, 2015, 02:59:07 pm
Quote
I don't want to use an additional transformer.
I was thinking some kind of inductive coupling to a mains conductor, driving a high impedance FET input.

You don't want to use an additional transformer, but an inductive coupler (aka transformer) would be okay? ;-)

The issue with coupling to a single mains conductor would be that you're looking at the current flow, not the voltage. So you'd get very little output in stand by mode, but you'd also have to cope with much larger outputs under load. The easiest, and safest, way is to use either an opto coupler based zero-crossing detector or a small mains transformer. The opto solution will have less stand by losses.

e: Of course a real RTC is still simpler and doesn't need mains at all.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Paul Price on November 18, 2015, 03:16:33 pm
This is how I do it:
Almost any optoisolator can be used instead in the schematic below.. like the xx 817 4-pin devices so common in use.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: TerraHertz on November 18, 2015, 10:49:53 pm
Previous thread here:
  https://www.eevblog.com/forum/projects/zero-cross-detector-circuit-will-this-give-me-the-irq-i-need-for-phase-control/ (https://www.eevblog.com/forum/projects/zero-cross-detector-circuit-will-this-give-me-the-irq-i-need-for-phase-control/)
  http://www.dextrel.net/diyzerocrosser.htm (http://www.dextrel.net/diyzerocrosser.htm)

Things I'd add to that circuit (see pic)
* A zener to ensure the voltage across C1 never exceeds ratings of the cap or Vcb of the transistor. Also makes the ZC pulse timing more stable.
* The input resistors R1 & R2 are exposed to half mains voltage, and small metal film resistors tend to go open circuit after a while under such stress. It's better to split each into at least two.
* Wouldn't hurt to make the filtering referenced to ground at the input.

(Oops, I left out the current limiting R in series with the opto.)
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: tggzzz on November 18, 2015, 11:03:02 pm
http://www.atmel.com/images/doc2508.pdf (http://www.atmel.com/images/doc2508.pdf)
And understand absolutely fully what is meant by and implied by "It should be noted that this solution will not give any galvanic isolation for the microcontroller against the AC mains".
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Delta on November 19, 2015, 01:14:31 am
http://www.atmel.com/images/doc2508.pdf (http://www.atmel.com/images/doc2508.pdf)
And understand absolutely fully what is meant by and implied by "It should be noted that this solution will not give any galvanic isolation for the microcontroller against the AC mains".

Yep, that jumped right out at as soon as I saw the schematic!  An MCU hanging off the mains on a few resistors!  :wtf:

Thanks very much for all the suggestions, although I'm starting to think that if I really want to use the grid freq I'm as well just using a small transformer...
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: pmbrunelle on November 19, 2015, 02:45:14 am
Since I too live in a first world country with decent electrical service, I consider any quartz clock to be total junk compared to using the line frequency for timekeeping.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: vk6zgo on November 19, 2015, 03:55:19 am
http://www.atmel.com/images/doc2508.pdf (http://www.atmel.com/images/doc2508.pdf)
And understand absolutely fully what is meant by and implied by "It should be noted that this solution will not give any galvanic isolation for the microcontroller against the AC mains".

Yep, that jumped right out at as soon as I saw the schematic!  An MCU hanging off the mains on a few resistors!  :wtf:

Thanks very much for all the suggestions, although I'm starting to think that if I really want to use the grid freq I'm as well just using a small transformer...

And Mains transformers can be very small---some of those used in older style plugpacks/wall warts may fit in an odd spot in your power supply.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Ian.M on November 19, 2015, 04:24:23 am
Since its only a timekeeping signal, it doesn't need to be in phase with the mains.  => a capacitive dropper (X2 cap with a series anti-surge safety resistor) driving the two LEDs of a dual optocoupler connected in anti-parallel, with the phototransistors arranged as a push-pull output stage powered from the 5V rail, could pick off a logic level 50Hz squarewave with very low risk.   Obviously adequate clearances *MUST* be maintained, so either make a proper PCB (not forgetting mounting holes with generous safety clearances if there's anywhere it can safely be screwed down), and I'd add two holes per wire sized to their insulated O.D. to loop them through to mechanically anchor them before soldering, or build it with point to point wiring on BARE perfboard.   

If you go the perfboard route, after testing it thoroughly, epoxy pot it, and secure it inside the PSU chassis with 3M VHB tape.  The PCB will need mounting pillars and fibreboard insulation under it and must be mounted in the live 'zone' of the PSU, unless you decide to pot it and treat it like the perfboard version.


Wire to the AC input to the bridge rectifier (*MUST* be after the fuse), the 5V bus and 0V.   Sleeve the input and output side wiring separately so its double-insulated and cable-tie it firmly in place.  Use a new good quality ATX PSU as it isn't worth putting the time to mod it safely into a cheap or used one.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Paul Price on November 19, 2015, 04:35:13 am
TerraHertz:

The two 220K resistors in my circuit are forming a voltage divider with the 22K resistor so that the voltage across the 10uF capacitor is not going to rise to a level to need a zener diode to limit the voltage to a safe value. There is additional voltage peak attenuation by the 10uF capacitor itself at the line frequency in addition to the 22K divider resistor. The capacitor discharges each half cycle through the 1K resistor and optoisolator.

Adding a zener does not make the output more stable, it is the stable zero-cross time of the mains voltage that makes the output signal stable.

This circuit can be constructed far cheaper and far smaller than using a transformer and the required additional circuitry to try to do the same job.

Adding filter caps to ground is not needed, the circuit is completely isolated from the mains by the optoisolator and if the values of the caps are not carefully chosen to be small in value the attenuation would make this circuit inoperable. This circuit could be connected to the ATX P/S PCB at the point where the AC line voltage is already being filtered by the capacitor-common mode choke circuit that directly connects to the bridge rectifier of the ATX supply.

Ian.M: My circuit requires an optoisolator that can be salvaged from an old ATX supply or from any other SMPS equipment at zero cost. Buying a rarer breed of back to back LED optoisolator would be a more expensive way to accomplish the goal here. Also the size of and cost of the 250RMS capacitor for the voltage divider  is a factor. Also, using just a capacitor voltage divider seems to be a simple solution, but this circuit idea will likely cause a clock to run fast as there will be spurious timing pulses generated because of not filtering out mains voltages glitches.

There is no need to buy a new ATX power supply either, as it takes no more time to add this mod to an used power supply than to a new one. If the ATX power supply was previously probably working fine powering a PC, it would be foolish to discard it simply because it is used but working well and also opening the case and modding a new ATX supply would void its warranty.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: NiHaoMike on November 19, 2015, 06:44:05 am
Yep, that jumped right out at as soon as I saw the schematic!  An MCU hanging off the mains on a few resistors!  :wtf:
That's fine if the resistors are rated to withstand the mains voltage. In practice, that means using at least two 1/4W resistors in series (preferably 3 or more - they're cheap!) and having values high enough to keep the currents low. Definitely not a good project for a beginner (really, nothing directly interfacing to the mains would be), but I have seen it used in various commercial products.

One trick you can try, if the PSU has active PFC, is to try picking up the EMI generated by the PFC. You're looking for a 50-120kHz or so tone that pulses at twice the mains frequency. Main problem is that at light loads, the PSU would start period skipping and then it's basically impossible to get a reliable signal.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: eneuro on November 19, 2015, 07:19:52 am
So if that's the case, is there a safe way to get a 50hz reference without connecting directly to the mains.  I don't want to use an additional transformer.

I'd rather do it with a few kV galvanic inulation from mains, so H11AA1 if you could source it or two cheapy PC817 with its input connected in anti parallel with additional current limiting resistors on 230VAC mains side ;)

AC Zero crossing detect, H11AA1 troubleshooting (https://www.eevblog.com/forum/beginners/ac-zero-crossing-detect-h11aa1-troubleshooting/msg595245/#msg595245)

Proof of concept using low reverse voltage LEDs looks like this and it shows why we need to put those diodes/LEDs in anti parallel like internal H11AA1 input ones to survive 325Vmax AC mains  :popcorn:

(http://s5.postimg.org/4u1qs942v/proind_after_soldering_forum.jpg)

Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Ian.M on November 19, 2015, 07:24:12 am
... This circuit could be connected to the ATX P/S PCB at the point where the AC line voltage is already being filtered by the capacitor-common mode choke circuit that directly connects to the bridge rectifier of the ATX supply.

Ian.M: My circuit requires an optoisolator that can be salvaged from an old ATX supply or from any other SMPS equipment at zero cost. Buying a rarer breed of back to back LED optoisolator would be a more expensive way to accomplish the goal here. Also the size of and cost of the 250RMS capacitor for the voltage divider  is a factor. Also, using just a capacitor voltage divider seems to be a simple solution, but this circuit idea will likely cause a clock to run fast as there will be spurious timing pulses generated because of not filtering out mains voltages glitches.

There is no need to buy a new ATX power supply either, as it takes no more time to add this mod to an used power supply than to a new one. If the ATX power supply was previously probably working fine powering a PC, it would be foolish to discard it simply because it is used but working well and also opening the case and modding a new ATX supply would void its warranty.

So your circuit can use the PSU's in-built line in filtering and MOV protection but you wont allow mine the same privilege, even though I specified connection at the bridge rectifier?

You wire the optocoupler back to back, it doesn't come that way.  Either use two singles or a dual.  The whole point is to minimise the component count on the live side.   You can use a pure resistive dropper, but to get a good low impedance output needs a reasonable LED current, so that's three resistors running moderately warm.  A cap dropper using a 0.047uF X2 cap isn't large or expensive, nor is a 6K8 resistor, and that will deliver you approx 3.5mA RMS through the LEDs.   Spikes only matter if they occur close enough to the zero crossing to reverse polarity to the LEDs, and if such a glitch even makes it accross the isolation barrier (due to the response time of  the LEDs and phototransistors) is easily filtered out on the low voltage side in software or hardware.

On the subject of used PSUs.  New, they are commodity products, and you don't need a gold plated one.  If the used or s--tty PRC PSU fails, assuming it doesn't take out your custom MCU board, you've got all the hassles or stripping it down to retrieve your opto module, getting a replacement, and refitting the module.  For a one-off, initially fitting it is likely to take something like half an hour, if you are doing the job right with all wiring properly secured. Unless you value your time at less than minimum wage, it just isn't worth using crap.  I *MIGHT* consider a lightly used premium brand PSU, but the standby supply in a modern PC leads a fairly hard life, and IMHO its better to start from new.  On the warranty issue, sure its voided, but that's what burn-in testing is for.  Stick a good load on it or stick it in a system and run it for a few days before cracking it open.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: vk6zgo on November 19, 2015, 07:43:33 am
Quote
I don't want to use an additional transformer.
I was thinking some kind of inductive coupling to a mains conductor, driving a high impedance FET input.

You don't want to use an additional transformer, but an inductive coupler (aka transformer) would be okay? ;-)

The issue with coupling to a single mains conductor would be that you're looking at the current flow, not the voltage. So you'd get very little output in stand by mode, but you'd also have to cope with much larger outputs under load. The easiest, and safest, way is to use either an opto coupler based zero-crossing detector or a small mains transformer. The opto solution will have less stand by losses.

e: Of course a real RTC is still simpler and doesn't need mains at all.

If the output is low on standby,that would be the level to go for,& when it increases,just clip it.

I still think the small mains transformer idea is by far simpler & more reliable than any other,however.
ATX power supplies aren't tiny,so there is enough room for a small transformer.
I have seen smaller SMPS which include a small power transformer to keep various circuitry alive in standby.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: eneuro on November 19, 2015, 07:46:54 am
This HV cables with 3mm LEDs in anti parallel I've used to detect HV flyback DC vs AC on other pins with limited output current to a few mA  :popcorn:

(http://s8.postimg.org/6u7mgmfed/HV_40_VDC_LEDs_probe.jpg)

For direct mains of course current limiting resistors in series with those anti parallel LEDs needed.

Beaty of this solution is it can easy survive a few kV transients as shown in HV experiments I've made using such low reverse voltage diodes in antiparallel  8)


Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Ian.M on November 19, 2015, 08:02:25 am
You could probably get away with a small class Y1 cap and series 1M resistor direct from mains live to a Schmidt trigger MCU input with external Schottky clamping.  Allocate 1% of the permitted no-fault earth leakage current for the class of appliance to the cap, and you've still got plenty to toggle a MCU pin. 
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Jeroen3 on November 19, 2015, 08:31:13 am
I've heard of cheap alarm clocks that run at superspeed if you (or your neighbour) have variable frequency drives.

But I prefer 32Khz oscillators, if properly trimmed these are very accurate. You can use mains line to trim it I guess.

Don't scopes get mains trigger from a wire tie-wrapped against the power supply wire?
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: dom0 on November 19, 2015, 08:38:29 am
Don't scopes get mains trigger from a wire tie-wrapped against the power supply wire?

That totally depends on the scope.

e: I have no idea why this thread has become so long. What the fuck?
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Ian.M on November 19, 2015, 08:53:55 am
I'm just surprised it hasn't mutated into the great illegal/unsafe capacitive dropper PSU debate!  :-DD

I've seen similar threads about ZCD circuits on other forums go to a hundred or more posts with flames to the left and flames to the right and SPICE models attached in place of artillery support.  |O
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: tggzzz on November 19, 2015, 09:33:04 am
I'm just surprised it hasn't mutated into the great illegal/unsafe capacitive dropper PSU debate!  :-DD
I've seen similar threads about ZCD circuits on other forums go to a hundred or more posts with flames to the left and flames to the right and SPICE models attached in place of artillery support.  |O

Oh dear. Too true.

Anybody that used a spice simulation of such a circuit must, repeat must create and debug all of the prototype circuit on a breadboard. Let's ensure the Dunning-Kruger effect causes a candidate for a Darwin Award sooner rather than later :)
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Ian.M on November 19, 2015, 09:42:43 am
There's no real problem debugging it (or cap dropper PSus) on a breadboard.  Use an AWG driving a small audio power amp for the simulated mains waveform complete with 'databurst', waveform distortion and other transients + a 100V line transformer to get a reasonably realistic voltage then scale selected component values to go from 100V RMS to 240V RMS.

Having learned how to build safe mains circuits on veroboard* in my youth, the prospect of breadboarding a ZCD circuit with ordinary test bench safety precautions does not worry me.  OTOH I certainly wouldn't breadboard the 10A TRIAC on the other end of the ZCD circuit! O0

* Hint: strip whole tracks to achieve required creepage distancea
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: tggzzz on November 19, 2015, 09:54:08 am
There's no real problem debugging it on a breadboard.  Use an AWG driving a small audio power amp for the simulated mains waveform complete with 'databurst', waveform distortion and transients + a 100V line transformer to get a reasonably realistic voltage then scale selected component values to go from 100V RMS to 240V RMS.
No AWG. The whole point is to use the mains directly, just like in the real circuit :) If you don't then then you won't have a visceral understanding of the "effects" that can happen when dealing with mains - doubly so if there are large motor transients or lightning strikes on the mains supply.

Anyone thinking of connecting to the mains directly should understand why these components exist http://uk.farnell.com/MarketingProductList?CMP=e-email-191115-Bourns&orderCode=2495067,2495068,2495069,2495070,2495071 (http://uk.farnell.com/MarketingProductList?CMP=e-email-191115-Bourns&orderCode=2495067,2495068,2495069,2495070,2495071)

For the humour impaired, attaching mains to a breadboard is a really really REALLY bad idea - worthy of the Darwin Award
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Ian.M on November 19, 2015, 10:14:30 am
No AWG. The whole point is to use the mains directly, just like in the real circuit :) If you don't then then you won't have a visceral understanding of the "effects" that can happen when dealing with mains - doubly so if there are large motor transients or lightning strikes on the mains supply.

Anyone thinking of connecting to the mains directly should understand why these components exist http://uk.farnell.com/MarketingProductList?CMP=e-email-191115-Bourns&orderCode=2495067,2495068,2495069,2495070,2495071 (http://uk.farnell.com/MarketingProductList?CMP=e-email-191115-Bourns&orderCode=2495067,2495068,2495069,2495070,2495071)
Same goes for designing or modifying any mains powered electronics that isn't on the secondary side of a conventional transformer or commercial SMPSU with regulatory approvals.

Also for the humour impaired:  I wasn't advocating exceeding the breadboard's peak voltage ratings or even approaching them, and the 50 or 60 Hz supply suggested would be (A) fully floating and (B) current limited.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: wraper on November 19, 2015, 11:25:16 am
H11AA1 optocoupler + resistor in series.
http://www.vishay.com/docs/83608/h11aa1.pdf (http://www.vishay.com/docs/83608/h11aa1.pdf)
(http://sensuino.net/lib/exe/fetch.php?media=wiki:h11aa1.png)
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: eneuro on November 19, 2015, 06:21:29 pm
H11AA1 optocoupler + resistor in series.
Problem with your two 33k resistors in series is that... you will have close to 0.4W power disipation in each of them so total close to 0.8W  :-DMM
That is why I've used  four 100k grouped with two so 50k x 2, which gives ~0.13W per each 100k resistor so even classic 100k 1/4W THT looks not so bad  ;)
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: wraper on November 20, 2015, 03:52:37 pm
H11AA1 optocoupler + resistor in series.
Problem with your two 33k resistors in series is that... you will have close to 0.4W power disipation in each of them so total close to 0.8W  :-DMM
That is why I've used  four 100k grouped with two so 50k x 2, which gives ~0.13W per each 100k resistor so even classic 100k 1/4W THT looks not so bad  ;)
But what's the point if you can use 2x 1W resistors. Or alternatively can use H11AA3 or H11AA4 with higher CTR and increase resistance thus reducing the power.
Also using 1/4 w resistors might be not so good idea because for most of them you are closing to their max rated voltage.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Ian.M on November 20, 2015, 04:09:07 pm
Its only for timekeeping so phase shift is not a problem.   Use a 0.047uF X2 cap in place of one of the resistors and make the other one a lot smaller (6K8 is probably about right), then the dissipation drops to milliwatts.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: eneuro on November 20, 2015, 04:09:17 pm
Also using 1/4 w resistors might be not so good idea because for most of them you are closing to their max rated voltage.
It depends how those THT resistors are mounted  ;)
Thermal heat shrink  can be used and aditionally filled with electric insulator inside PCB case, so its 7mm mount pins length can be fine, while we have two in series.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Ian.M on November 20, 2015, 04:22:52 pm
Also using 1/4 w resistors might be not so good idea because for most of them you are closing to their max rated voltage.
It depends how those THT resistors are mounted  ;)
Thermal heat shrink  can be used and aditionally filled with electric insulator inside PCB case, so its 7mm mount pins length can be fine, while we have two in series.
Nothing to do with mounting.  Spiral cut (trimmed) film resistors have a max voltage rating..  exceed it and they can flash over turn to turn, narrowing the film, causing hot-spotting leading to failure.  Typically such resistors have a 200V rating, leaving very little margin on the peaks with two in series if the mains supply is at its upper tolerance limit.  Add >10% transients at or near the peak and you are FUBARed. 
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: klunkerbus on November 20, 2015, 05:13:06 pm
Isn't filtering required to keep transients on the power line from messing up the timekeeping?  I built a controller as a class project decades ago that used a transformer secondary for a clock source. The clock in the controller ran annoyingly fast, which I attributed to noise falsely clocking the counter chain.  I remember that a few attempts at filtering maybe helped but didn't fix the problem.  Since then, I've avoided trying to use the power line frequency as a timing source. 

For any of my microcontroller hobby projects where I have an I2C interface available, my current preference for a clock or timing source is the Adafruit chrono-dot https://www.adafruit.com/products/255 (https://www.adafruit.com/products/255).  Temperature compensated, battery backup, and square wave options from 1 Hz to 32,768 Hz if that's what the project needs.  Using one of these allows me to focus on the real function of the project underway without having to hassle with clock issues.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: eneuro on November 20, 2015, 05:22:23 pm
For any of my microcontroller hobby projects where I have an I2C interface available...
Yep, many RTC with I2C interface have output pin available which can be configured with choosen frequency based on its internal oscilator, so once after MPU restet we connect with such RTC, setup to given frequency and enable on output pin and no need to mess with unpredictable mains with transients from neighbours inductive loads, etc  ;)
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Jeroen3 on November 20, 2015, 06:10:38 pm
Add >10% transients at or near the peak and you are FUBARed.
More like 2kV spikes for less than a millisecond. Refer to your local safety standard for the testing method in your area.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Ian.M on November 20, 2015, 06:26:17 pm
Yes.  Anecdotally, I've found that failed SMPSUs with:

* One startup resistor usually had it O/C.
* Two series startup resistors frequently had one or both O/C.
* Three or more series startup resistors usually had another fault.

That's drawing power from a DC bus that usually had a large reservoir cap on it, and usually with MOV transient protection.

Direct from mains is an order of magnitude worse, and resistive droppers that aren't very carefully specified just wont be reliable.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: mich41 on November 20, 2015, 07:41:44 pm
The capacitive way:

C=2n7, R=220k, the green wire loosely touches a mains cable.

20mV/div
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: eneuro on November 20, 2015, 08:10:09 pm
Add >10% transients at or near the peak and you are FUBARed.
More like 2kV spikes for less than a millisecond.
I still better like oryginal idea with resistors, while even at 2kV transient divided by 100k series resistance we get ~20mA via those antiparallel diodes which are usually capable of 50mA or so.
If we add fuse and higher voltage rated resistors it looks like it should be difficult make blackout in home grid, while at worse case scenario if we'll have HV spark and high current which destroys those anti parallel diodes, than fuse breaks circuit.
Anyway, I'm using those crappy THT 7mm 1/4W resistors (2x 100k  two in series ) with PC817 and... 1N4007 diode in anti parallel on its input  in spot welder to detect after fuse mains positive/negative pulse for phase shift control in MPU (software averaging is used to remove noise crap by calculating moving average mains period regardless it is 50Hz or 60Hz MPu detects this) and so far no problem what so ever ;)
Maybe I'll test it with a few kV flyback HV instead of mains to see if we destroy those THT resistors hidden in thermal heat shrinks and filled with hot glue together with PC817 and diode, than additional heat shrink, so whole AC sensor with resistors is hidden inside and no air gaps to jump spikes between resitor legs....
I will make such experiment in spare time  :popcorn:
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Delta on November 20, 2015, 11:57:53 pm
Wow, didn't expect this thread to cause so many replies!

Thanks for all the tips, however due to a change in the project's requirements (no need for an ATX PSU, all the loads will be mains powered controlled by relays) I'm going the transformer route.

The MCU circuitry and relays will run from a 12 supply, so I sifted through my collection of plug packs, and found one that was actually screwed together!  On opening it, to my great delight (sad, isn't it?) I found a centre-tapped secondary with a two diode rectifier.  I have tapped off one side before the diode and done as the attached schematic ("X" goes to Schmitt triggered timer clock input pin on the MCU).

Any problems or gotchas with this arrangement?  It seems to be working fine...
I don't have any diodes kicking around, so I've used a 3mm red LED (Vf = 1.8v) to clamp the negative half cycles.  The transistor is a BC548.  I couldn't find much info about max reverse Vbe, but I read that they will Zener at a certain point, normally around 8v?

I await your criticism!  :)
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: vk6zgo on November 21, 2015, 02:19:15 am
Way back in the "Dream Time",early versions of analog TV sync generators used to lock the field rate to the local Mains frequency,before they gave that up as a bad idea & went to crystal locked divider chains from 2X line frequency.

They didn't clock the thing directly from the Mains,but used it to "synch"a fairly stable oscillator,so that in case of a loss of an incoming cycle,a glitch,or whatever,it would remain on frequency.(An early form of Phase locking).

This is similar to the way field syncs are used in a TV receiver.
If you look at the vertical scan waveform without any input to the RX,it is quite stable,& close to correct frequency.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: TerraHertz on November 21, 2015, 03:09:57 am
TerraHertz:

The two 220K resistors in my circuit are forming a voltage divider with the 22K resistor so that the voltage across the 10uF capacitor is not going to rise to a level to need a zener diode to limit the voltage to a safe value. There is additional voltage peak attenuation by the 10uF capacitor itself at the line frequency in addition to the 22K divider resistor. The capacitor discharges each half cycle through the 1K resistor and optoisolator.

Oddly enough, I understand perfectly well how it works. And also that the values chosen *assume* the mains is always going to be a nice sine wave at 250VAC RMS, 50Hz.
Which isn't a safe assumption.  The zener suggestion is to cope with cases where the mains is not well behaved.

Quote
Adding a zener does not make the output more stable, it is the stable zero-cross time of the mains voltage that makes the output signal stable.

Actually, if the zener is chosen to clip the cap's charge for much of each half cycle, it will make the timing of the leading and falling edges of the output pulse more uniform, by eliminating most of the influence of non-sinusoid and peak voltage variations of the mains waveform.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: eneuro on November 21, 2015, 10:53:15 am
I await your criticism!  :)

It can be as simple as it is, when you have transformer, while power disipation will be orders of magnitude lower on transformer secondary, so transformer in your design is fine, but I like have MPU optoisolated from power source if easy possible - I mean trafo secondary ;)

(http://s16.postimg.org/5duoj544l/protempomat_sensor_rpm_forum.jpg)

This thing was designed to.. sense alternator RPM based on its AC waveforms on choosen two of three available output three phase.
Notice, only one cheapy EL817 was used with cut off frequency ~80kHz and... SMD led in antiparallel to optoisolator input diode, so we have also light indicator that we have AC input present.

Output with additional 10k pullup to MPU VCC and interruptpin enabled to sense pulses and calculate moveing average to avoid any transients and estimate pulses frequency-with optional filtering on MPU pin, but when we can do it in software we can get good estimation of pules frequency and get rid of any noise pulses, etc  :popcorn:

BTW: Probably I will send this small PCB to manufacture with this additional pullup resistor and make this PCB 1/4 inch wide and 1 inch long, while it can then fit into thermal heat shrink and can be reused in many projects where we need sensing AC waveforms zero crossing and have a few kV insulation from MPU etc  :)
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: dom0 on November 21, 2015, 11:31:29 am
I await your criticism!  :)

It can be as simple as it is, when you have transformer, while power disipation will be orders of magnitude lower on transformer secondary, so transformer in your design is fine, but I like have MPU optoisolated from power source if easy possible - I mean trafo secondary ;)

Keep in mind that small mains transformers have lots of core losses (up to several Watts). There are ECO transformers with larger cores that have less losses. The low power dissipation of the opto-coupler version will be hard to beat with a transformer, not to mention size and weight.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Delta on November 21, 2015, 12:05:04 pm
Aye, I'm with you on that mate.  I will order some opto couplers (any specific?  a few have been suggested here, are any available TH?) for next time I want to do something like this.

But for now, as the project will be powered from this transformer anyway, being able to pick of the mains freq in an easy safe way comes for free!

It's gained 7 secs in the last 12 hours (midnight til midday) as compared with a digital watch, so not bad I think.  I'm guessing the grid freq was a bit higher through the night due to low load.

I'm going to (try to) add some code to record the min and max freqs it sees, to determine if it's picking up any noise or glitches on the waveform.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: vk6zgo on November 21, 2015, 01:14:04 pm
Maybe I was a bit indirect in my earlier remarks about how things were "mains locked".

It wasn't just a Greybeard maundering on about "the good old days"(it was way before my time,anyway).

The point was,that using the Mains signal "direct",any glitches may look like additional,or missing cycles,whilst,using the signal to phase lock a "free running" oscillator will iron out these perturbations.

That's why the TV guys did it back in the late 1930s.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: tggzzz on November 21, 2015, 04:10:33 pm
I'm guessing the grid freq was a bit higher through the night due to low load.

No need to guess. See http://www.gridwatch.templar.co.uk/download.php (http://www.gridwatch.templar.co.uk/download.php) and fight your way through the skewomorphic interface to find:
Code: [Select]
 2015-11-20 18:00:03	49.946999
 2015-11-20 18:05:03 49.981998
 2015-11-20 18:10:02 49.959999
 2015-11-20 18:15:02 50.012001
 2015-11-20 18:20:08 50.006001
 2015-11-20 18:25:03 49.998001
 2015-11-20 18:30:04 49.957001
 2015-11-20 18:35:05 49.948002
 2015-11-20 18:40:03 49.993999
 2015-11-20 18:45:03 49.966
 2015-11-20 18:50:01 49.956001
 2015-11-20 18:55:02 49.910999
 2015-11-20 19:00:04 50.02
 2015-11-20 19:05:03 50.013
 2015-11-20 19:10:02 49.976002
 2015-11-20 19:15:03 50.022999
 2015-11-20 19:20:04 50.022999
 2015-11-20 19:25:02 50.092999
 2015-11-20 19:30:02 50.051998
 2015-11-20 19:35:01 50.007999
 2015-11-20 19:40:03 50.112
 2015-11-20 19:45:02 50.009998
 2015-11-20 19:50:01 49.966999
 2015-11-20 19:55:02 49.990002
 2015-11-20 20:00:02 50.044998
 2015-11-20 20:05:02 49.928001
 2015-11-20 20:10:02 49.931999
 2015-11-20 20:15:03 49.959999
 2015-11-20 20:20:06 49.973999
 2015-11-20 20:25:01 50.012001
 2015-11-20 20:30:04 49.942001
 2015-11-20 20:35:01 50.007
 2015-11-20 20:40:01 50.035999
 2015-11-20 20:45:02 49.941002
 2015-11-20 20:50:03 50.006001
 2015-11-20 20:55:02 49.984001
 2015-11-20 21:00:02 49.943001
 2015-11-20 21:05:03 50.015999
 2015-11-20 21:10:02 50.042
 2015-11-20 21:15:03 50.063
 2015-11-20 21:20:04 49.964001
 2015-11-20 21:25:02 49.987999
 2015-11-20 21:30:02 49.986
 2015-11-20 21:35:02 49.919998
 2015-11-20 21:40:02 49.941002
 2015-11-20 21:45:02 49.946999
 2015-11-20 21:50:02 49.937
 2015-11-20 21:55:01 49.959999
 2015-11-20 22:00:04 50.043999
 2015-11-20 22:05:03 49.976002
 2015-11-20 22:10:02 50.019001
 2015-11-20 22:15:01 49.977001
 2015-11-20 22:20:02 49.967999
 2015-11-20 22:25:03 49.918999
 2015-11-20 22:30:02 49.91
 2015-11-20 22:35:02 50.028
 2015-11-20 22:40:01 49.991001
 2015-11-20 22:45:03 50.025002
 2015-11-20 22:50:02 50.028
 2015-11-20 22:55:01 50.203999
 2015-11-20 23:00:02 50.129002
 2015-11-20 23:05:02 49.834
 2015-11-20 23:10:01 49.974998
 2015-11-20 23:15:01 50.077999
 2015-11-20 23:20:03 50.015999
 2015-11-20 23:25:01 50.021
 2015-11-20 23:30:04 50.043999
 2015-11-20 23:35:01 49.987
 2015-11-20 23:40:02 50.008999
 2015-11-20 23:45:02 49.991001
 2015-11-20 23:50:03 49.938999
 2015-11-20 23:55:01 49.98
 2015-11-21 00:00:05 50.047001
 2015-11-21 00:05:02 49.986
 2015-11-21 00:10:02 49.965
 2015-11-21 00:15:03 49.957001
 2015-11-21 00:20:03 49.942001
 2015-11-21 00:25:02 50.001999
 2015-11-21 00:30:03 49.971001
 2015-11-21 00:35:02 49.923
 2015-11-21 00:40:01 49.950001
 2015-11-21 00:45:02 49.944
 2015-11-21 00:50:01 49.914001
 2015-11-21 00:55:02 49.924999
 2015-11-21 01:00:01 50.027
 2015-11-21 01:05:01 50.063999
 2015-11-21 01:10:02 50.077999
 2015-11-21 01:15:01 50.084999
 2015-11-21 01:20:02 50.070999
 2015-11-21 01:25:01 49.997002
 2015-11-21 01:30:03 49.976002
 2015-11-21 01:35:01 50.033001
 2015-11-21 01:40:02 50.145
 2015-11-21 01:45:02 50.080002
 2015-11-21 01:50:01 50.074001
 2015-11-21 01:55:01 50.050999
 2015-11-21 02:00:02 50.036999
 2015-11-21 02:05:02 49.902
 2015-11-21 02:10:02 49.935001
 2015-11-21 02:15:02 50.023998
 2015-11-21 02:20:06 50.022999
 2015-11-21 02:25:02 50.014
 2015-11-21 02:30:02 50.033001
 2015-11-21 02:35:03 49.929001
 2015-11-21 02:40:01 49.994999
 2015-11-21 02:45:02 50.042999
 2015-11-21 02:50:02 50.082001
 2015-11-21 02:55:06 50.067001
 2015-11-21 03:00:03 50.054001
 2015-11-21 03:05:02 50.001999
 2015-11-21 03:10:03 49.981998
 2015-11-21 03:15:05 49.959
 2015-11-21 03:20:02 49.964001
 2015-11-21 03:25:02 50.013
 2015-11-21 03:30:03 50.057999
 2015-11-21 03:35:02 50.026001
 2015-11-21 03:40:02 50.02
 2015-11-21 03:45:03 50.077999
 2015-11-21 03:50:01 50.084
 2015-11-21 03:55:03 50.042
 2015-11-21 04:00:02 50.046001
 2015-11-21 04:05:02 49.963001
 2015-11-21 04:10:04 49.969002
 2015-11-21 04:15:01 49.978001
 2015-11-21 04:20:04 49.973
 2015-11-21 04:25:01 49.950001
 2015-11-21 04:30:02 49.918999
 2015-11-21 04:35:02 49.939999
 2015-11-21 04:40:02 50
 2015-11-21 04:45:02 50.023998
 2015-11-21 04:50:02 49.977001
 2015-11-21 04:55:02 50.015999
 2015-11-21 05:00:05 50.015999
 2015-11-21 05:05:02 49.963001
 2015-11-21 05:10:02 49.941002
 2015-11-21 05:15:02 49.946999
 2015-11-21 05:20:04 49.948002
 2015-11-21 05:25:03 49.938999
 2015-11-21 05:30:01 49.953999
 2015-11-21 05:35:04 50.081001
 2015-11-21 05:40:09 50.091999
 2015-11-21 05:45:06 50.085999
 2015-11-21 05:50:02 50.042999
 2015-11-21 05:55:02 50.014
 2015-11-21 06:00:02 50.032001
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: eneuro on November 21, 2015, 05:38:17 pm
The low power dissipation of the opto-coupler version will be hard to beat with a transformer, not to mention size and weight.
There is nothing to beat, since we already had 50 Hz transformer on this questioned schematic, so while we already plan to use transformer in some design, than it doesn't mater how much more we loose in comparision to opto-coupler version.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Delta on November 22, 2015, 01:18:43 pm
I'm guessing the grid freq was a bit higher through the night due to low load.

No need to guess. See http://www.gridwatch.templar.co.uk/download.php (http://www.gridwatch.templar.co.uk/download.php) and fight your way through the skewomorphic interface to find:


I'm a massive fan of that website already!  But it kept telling me the server was too busy to prepare the csv file for download, so cheers for the info.  However looking at the data implies that my 7 second gain was not due to a higher freq.....
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Jeroen3 on November 22, 2015, 01:31:31 pm
Mains frequency is only guaranteed for to be within spec when averaged over a large period of time. This means you can have "high" momentary errors.
50 Hz +/- 1% during 99,9% of a year
50 Hz +2% / -4% all the time
Should be in NEN-EN 50160:2000
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Ian.M on November 22, 2015, 01:39:17 pm
Noise at the zero crossing occasionally provides extra pulses.   See post #38 above for the best solution, but a software PLL is a P.I.T.A to implement properly even with a hardware timer available.  Cheap&Dirty: Try locking out the input for 19us after detecting a pulse on it (i.e: if you are using an interrupt driven count, start a timer in the pin ISR to interrupt again in 19us, disable the interrupt pin, then in the timer ISR, re-enable the pin ISR and disable the timer and its interrupt.)
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: tggzzz on November 22, 2015, 01:42:06 pm
You may or may not find the techniques described at https://entertaininghacks.wordpress.com/2015/02/23/vetinari-digital-clock/ useful. I used an at85 MCU to count the mains cycles when turning a 40-year old digital clock (one of the first) into a Vetinari clock.

Note that there is no long-term performance assessment, since I still haven't put it back on the wall.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: tggzzz on November 22, 2015, 01:44:02 pm
Mains frequency is only guaranteed for to be within spec when averaged over a large period of time. This means you can have "high" momentary errors.
50 Hz +/- 1% during 99,9% of a year
50 Hz +2% / -4% all the time
Should be in NEN-EN 50160:2000

And I wouldn't guarantee that over the winter in the UK, given the (grossly negligent) lack of generating capacity :( We've already had a "notice of insufficiency", and it wasn't even cold at the time.
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Delta on November 22, 2015, 08:48:56 pm
Well I have made some changes.  I was using the 50hz pulse as a clock input to a timer, but am now using it to trigger an interrupt.  The ISR uses a timer to measure the time between pulses, at 50hz the period should be 20000uS, if it's less than 19800uS or more than 20200uS, the software ignores it.

I'm still itching to get the scope out to see exactly what I'm getting at the input to my MCU....  :-BROKE
Title: Re: Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU?
Post by: Delta on November 22, 2015, 09:54:36 pm
Looks pretty good to me!  I am enjoying this daft project, every day's a school day!  Thanks for all the help.  :)