Any way to pick off the 50/60hz line frequency at low voltage from an ATX PSU? - Page 1
Forum section: electronics / projects

author: Delta
author_rank: Super Contributor
timestamp: November 18, 2015, 02:40:22 pm
content: 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!

author: Richard Crowley
author_rank: Super Contributor
timestamp: November 18, 2015, 02:49:00 pm
content: http://www.atmel.com/images/doc2508.pdf

author: dom0
author_rank: Super Contributor
timestamp: November 18, 2015, 02:59:07 pm
content: QuoteYou 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.

author: Paul Price
author_rank: Super Contributor
timestamp: November 18, 2015, 03:16:33 pm
content: 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.

author: TerraHertz
author_rank: Super Contributor
timestamp: November 18, 2015, 10:49:53 pm
content: Previous thread here: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.htmThings 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.)

author: tggzzz
author_rank: Super Contributor
timestamp: November 18, 2015, 11:03:02 pm
content: Quote from: Richard Crowley on November 18, 2015, 02:49:00 pmAnd understandabsolutely fullywhat 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".

author: Delta
author_rank: Super Contributor
timestamp: November 19, 2015, 01:14:31 am
content: Quote from: tggzzz on November 18, 2015, 11:03:02 pmYep, that jumped right out at as soon as I saw the schematic! An MCU hanging off the mains on a few resistors!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...

author: pmbrunelle
author_rank: Regular Contributor
timestamp: November 19, 2015, 02:45:14 am
content: 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.

author: vk6zgo
author_rank: Super Contributor
timestamp: November 19, 2015, 03:55:19 am
content: Quote from: Delta on November 19, 2015, 01:14:31 amAnd Mains transformers can beverysmall---some of those used in older style plugpacks/wall warts may fit in an odd spot in your power supply.

author: Ian.M
author_rank: Super Contributor
timestamp: November 19, 2015, 04:24:23 am
content: 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.

author: Paul Price
author_rank: Super Contributor
timestamp: November 19, 2015, 04:35:13 am
content: 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.

author: NiHaoMike
author_rank: Super Contributor
timestamp: November 19, 2015, 06:44:05 am
content: Quote from: Delta on November 19, 2015, 01:14:31 amThat'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.

author: eneuro
author_rank: Super Contributor
timestamp: November 19, 2015, 07:19:52 am
content: Quote from: Delta on November 18, 2015, 02:40:22 pmI'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 sideAC Zero crossing detect, H11AA1 troubleshootingProof 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

author: Ian.M
author_rank: Super Contributor
timestamp: November 19, 2015, 07:24:12 am
content: Quote from: Paul Price on November 19, 2015, 04:35:13 amSo 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.

author: vk6zgo
author_rank: Super Contributor
timestamp: November 19, 2015, 07:43:33 am
content: Quote from: dom0 on November 18, 2015, 02:59:07 pmIf 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.

author: eneuro
author_rank: Super Contributor
timestamp: November 19, 2015, 07:46:54 am
content: 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 mAFor 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

author: Ian.M
author_rank: Super Contributor
timestamp: November 19, 2015, 08:02:25 am
content: 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.

author: Jeroen3
author_rank: Super Contributor
timestamp: November 19, 2015, 08:31:13 am
content: 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?

author: dom0
author_rank: Super Contributor
timestamp: November 19, 2015, 08:38:29 am
content: Quote from: Jeroen3 on November 19, 2015, 08:31:13 amThat totally depends on the scope.e: I have no idea why this thread has become so long. What the fuck?

author: Ian.M
author_rank: Super Contributor
timestamp: November 19, 2015, 08:53:55 am
content: I'm just surprised it hasn't mutated into the great illegal/unsafe capacitive dropper PSU debate!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.

author: tggzzz
author_rank: Super Contributor
timestamp: November 19, 2015, 09:33:04 am
content: Quote from: Ian.M on November 19, 2015, 08:53:55 amOh 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

author: Ian.M
author_rank: Super Contributor
timestamp: November 19, 2015, 09:42:43 am
content: 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

author: tggzzz
author_rank: Super Contributor
timestamp: November 19, 2015, 09:54:08 am
content: Quote from: Ian.M on November 19, 2015, 09:42:43 amNo AWG. The whole point is to use the mains directly, just like in the real circuitIf 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 existhttp://uk.farnell.com/MarketingProductList?CMP=e-email-191115-Bourns&orderCode=2495067,2495068,2495069,2495070,2495071For the humour impaired, attaching mains to a breadboard is a really really REALLY bad idea - worthy of the Darwin Award

author: Ian.M
author_rank: Super Contributor
timestamp: November 19, 2015, 10:14:30 am
content: Quote from: tggzzz on November 19, 2015, 09:54:08 amSame 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.

author: wraper
author_rank: Unknown
timestamp: November 19, 2015, 11:25:16 am
content: H11AA1 optocoupler + resistor in series.http://www.vishay.com/docs/83608/h11aa1.pdf

author: eneuro
author_rank: Super Contributor
timestamp: November 19, 2015, 06:21:29 pm
content: Quote from: wraper on November 19, 2015, 11:25:16 amProblem 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.8WThat 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

author: wraper
author_rank: Unknown
timestamp: November 20, 2015, 03:52:37 pm
content: Quote from: eneuro on November 19, 2015, 06:21:29 pmBut 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.

author: Ian.M
author_rank: Super Contributor
timestamp: November 20, 2015, 04:09:07 pm
content: 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.

author: eneuro
author_rank: Super Contributor
timestamp: November 20, 2015, 04:09:17 pm
content: Quote from: wraper on November 20, 2015, 03:52:37 pmIt depends how those THT resistors are mountedThermal 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.

author: Ian.M
author_rank: Super Contributor
timestamp: November 20, 2015, 04:22:52 pm
content: Quote from: eneuro on November 20, 2015, 04:09:17 pmNothing 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.

author: klunkerbus
author_rank: Unknown
timestamp: November 20, 2015, 05:13:06 pm
content: 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-dothttps://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.

author: eneuro
author_rank: Super Contributor
timestamp: November 20, 2015, 05:22:23 pm
content: Quote from: klunkerbus on November 20, 2015, 05:13:06 pmYep, 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

author: Jeroen3
author_rank: Super Contributor
timestamp: November 20, 2015, 06:10:38 pm
content: Quote from: Ian.M on November 20, 2015, 04:22:52 pmMore like 2kV spikes for less than a millisecond. Refer to your local safety standard for the testing method in your area.

author: Ian.M
author_rank: Super Contributor
timestamp: November 20, 2015, 06:26:17 pm
content: 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.

author: mich41
author_rank: Regular Contributor
timestamp: November 20, 2015, 07:41:44 pm
content: The capacitive way:C=2n7, R=220k, the green wire loosely touches a mains cable.20mV/div

author: eneuro
author_rank: Super Contributor
timestamp: November 20, 2015, 08:10:09 pm
content: Quote from: Jeroen3 on November 20, 2015, 06:10:38 pmI 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 everMaybe 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

author: Delta
author_rank: Super Contributor
timestamp: November 20, 2015, 11:57:53 pm
content: 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!

author: vk6zgo
author_rank: Super Contributor
timestamp: November 21, 2015, 02:19:15 am
content: 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.

author: TerraHertz
author_rank: Super Contributor
timestamp: November 21, 2015, 03:09:57 am
content: Quote from: Paul Price on November 19, 2015, 04:35:13 amOddly 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.QuoteActually, 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.

author: eneuro
author_rank: Super Contributor
timestamp: November 21, 2015, 10:53:15 am
content: Quote from: Delta on November 20, 2015, 11:57:53 pmIt 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 secondaryThis 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, etcBTW: 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

author: dom0
author_rank: Super Contributor
timestamp: November 21, 2015, 11:31:29 am
content: Quote from: eneuro on November 21, 2015, 10:53:15 amKeep 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.

author: Delta
author_rank: Super Contributor
timestamp: November 21, 2015, 12:05:04 pm
content: 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.

author: vk6zgo
author_rank: Super Contributor
timestamp: November 21, 2015, 01:14:04 pm
content: 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.

author: tggzzz
author_rank: Super Contributor
timestamp: November 21, 2015, 04:10:33 pm
content: Quote from: Delta on November 21, 2015, 12:05:04 pmNo need to guess. Seehttp://www.gridwatch.templar.co.uk/download.phpand fight your way through the skewomorphic interface to find:Code:2015-11-20 18:00:0349.9469992015-11-20 18:05:0349.9819982015-11-20 18:10:0249.9599992015-11-20 18:15:0250.0120012015-11-20 18:20:0850.0060012015-11-20 18:25:0349.9980012015-11-20 18:30:0449.9570012015-11-20 18:35:0549.9480022015-11-20 18:40:0349.9939992015-11-20 18:45:0349.9662015-11-20 18:50:0149.9560012015-11-20 18:55:0249.9109992015-11-20 19:00:0450.022015-11-20 19:05:0350.0132015-11-20 19:10:0249.9760022015-11-20 19:15:0350.0229992015-11-20 19:20:0450.0229992015-11-20 19:25:0250.0929992015-11-20 19:30:0250.0519982015-11-20 19:35:0150.0079992015-11-20 19:40:0350.1122015-11-20 19:45:0250.0099982015-11-20 19:50:0149.9669992015-11-20 19:55:0249.9900022015-11-20 20:00:0250.0449982015-11-20 20:05:0249.9280012015-11-20 20:10:0249.9319992015-11-20 20:15:0349.9599992015-11-20 20:20:0649.9739992015-11-20 20:25:0150.0120012015-11-20 20:30:0449.9420012015-11-20 20:35:0150.0072015-11-20 20:40:0150.0359992015-11-20 20:45:0249.9410022015-11-20 20:50:0350.0060012015-11-20 20:55:0249.9840012015-11-20 21:00:0249.9430012015-11-20 21:05:0350.0159992015-11-20 21:10:0250.0422015-11-20 21:15:0350.0632015-11-20 21:20:0449.9640012015-11-20 21:25:0249.9879992015-11-20 21:30:0249.9862015-11-20 21:35:0249.9199982015-11-20 21:40:0249.9410022015-11-20 21:45:0249.9469992015-11-20 21:50:0249.9372015-11-20 21:55:0149.9599992015-11-20 22:00:0450.0439992015-11-20 22:05:0349.9760022015-11-20 22:10:0250.0190012015-11-20 22:15:0149.9770012015-11-20 22:20:0249.9679992015-11-20 22:25:0349.9189992015-11-20 22:30:0249.912015-11-20 22:35:0250.0282015-11-20 22:40:0149.9910012015-11-20 22:45:0350.0250022015-11-20 22:50:0250.0282015-11-20 22:55:0150.2039992015-11-20 23:00:0250.1290022015-11-20 23:05:0249.8342015-11-20 23:10:0149.9749982015-11-20 23:15:0150.0779992015-11-20 23:20:0350.0159992015-11-20 23:25:0150.0212015-11-20 23:30:0450.0439992015-11-20 23:35:0149.9872015-11-20 23:40:0250.0089992015-11-20 23:45:0249.9910012015-11-20 23:50:0349.9389992015-11-20 23:55:0149.982015-11-21 00:00:0550.0470012015-11-21 00:05:0249.9862015-11-21 00:10:0249.9652015-11-21 00:15:0349.9570012015-11-21 00:20:0349.9420012015-11-21 00:25:0250.0019992015-11-21 00:30:0349.9710012015-11-21 00:35:0249.9232015-11-21 00:40:0149.9500012015-11-21 00:45:0249.9442015-11-21 00:50:0149.9140012015-11-21 00:55:0249.9249992015-11-21 01:00:0150.0272015-11-21 01:05:0150.0639992015-11-21 01:10:0250.0779992015-11-21 01:15:0150.0849992015-11-21 01:20:0250.0709992015-11-21 01:25:0149.9970022015-11-21 01:30:0349.9760022015-11-21 01:35:0150.0330012015-11-21 01:40:0250.1452015-11-21 01:45:0250.0800022015-11-21 01:50:0150.0740012015-11-21 01:55:0150.0509992015-11-21 02:00:0250.0369992015-11-21 02:05:0249.9022015-11-21 02:10:0249.9350012015-11-21 02:15:0250.0239982015-11-21 02:20:0650.0229992015-11-21 02:25:0250.0142015-11-21 02:30:0250.0330012015-11-21 02:35:0349.9290012015-11-21 02:40:0149.9949992015-11-21 02:45:0250.0429992015-11-21 02:50:0250.0820012015-11-21 02:55:0650.0670012015-11-21 03:00:0350.0540012015-11-21 03:05:0250.0019992015-11-21 03:10:0349.9819982015-11-21 03:15:0549.9592015-11-21 03:20:0249.9640012015-11-21 03:25:0250.0132015-11-21 03:30:0350.0579992015-11-21 03:35:0250.0260012015-11-21 03:40:0250.022015-11-21 03:45:0350.0779992015-11-21 03:50:0150.0842015-11-21 03:55:0350.0422015-11-21 04:00:0250.0460012015-11-21 04:05:0249.9630012015-11-21 04:10:0449.9690022015-11-21 04:15:0149.9780012015-11-21 04:20:0449.9732015-11-21 04:25:0149.9500012015-11-21 04:30:0249.9189992015-11-21 04:35:0249.9399992015-11-21 04:40:02502015-11-21 04:45:0250.0239982015-11-21 04:50:0249.9770012015-11-21 04:55:0250.0159992015-11-21 05:00:0550.0159992015-11-21 05:05:0249.9630012015-11-21 05:10:0249.9410022015-11-21 05:15:0249.9469992015-11-21 05:20:0449.9480022015-11-21 05:25:0349.9389992015-11-21 05:30:0149.9539992015-11-21 05:35:0450.0810012015-11-21 05:40:0950.0919992015-11-21 05:45:0650.0859992015-11-21 05:50:0250.0429992015-11-21 05:55:0250.0142015-11-21 06:00:0250.032001

author: eneuro
author_rank: Super Contributor
timestamp: November 21, 2015, 05:38:17 pm
content: Quote from: dom0 on November 21, 2015, 11:31:29 amThere 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.

author: Delta
author_rank: Super Contributor
timestamp: November 22, 2015, 01:18:43 pm
content: Quote from: tggzzz on November 21, 2015, 04:10:33 pmI'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.....

author: Jeroen3
author_rank: Super Contributor
timestamp: November 22, 2015, 01:31:31 pm
content: 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 year50 Hz +2% / -4% all the timeShould be in NEN-EN 50160:2000

author: Ian.M
author_rank: Super Contributor
timestamp: November 22, 2015, 01:39:17 pm
content: 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.)

author: tggzzz
author_rank: Super Contributor
timestamp: November 22, 2015, 01:42:06 pm
content: You may or may not find the techniques described athttps://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 Istillhaven't put it back on the wall.

author: tggzzz
author_rank: Super Contributor
timestamp: November 22, 2015, 01:44:02 pm
content: Quote from: Jeroen3 on November 22, 2015, 01:31:31 pmAnd I wouldn't guarantee that over the winter in the UK, given the (grossly negligent) lack of generating capacityWe've already had a "notice of insufficiency", and it wasn't even cold at the time.

author: Delta
author_rank: Super Contributor
timestamp: November 22, 2015, 08:48:56 pm
content: 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....

author: Delta
author_rank: Super Contributor
timestamp: November 22, 2015, 09:54:36 pm
content: Looks pretty good to me! I am enjoying this daft project, every day's a school day! Thanks for all the help.