Imperfect rectification with a rectifier diode


I've got an old electronic clock, from the 70's, and after opening it, I noticed that it uses the 50 Hz mains power supply frequency as reference.
So, wondering how accurate could be this frequency, I've built this simple circuit to measure it :

The input come from an AC to AC wall 12 V transformer.
The first diode acts as a rectifier, creating a positive half wave, and the zener diode cut it to +5.1V max.
The mosfet is, may be, optional, but helps to feed an arduino pin with a perfect +5V square signal.
The arduino counts the pulses, and after 50 increases a seconds counter.
The number of seconds is sent via serial USB to a computer (a Raspberry pi), which checks this value against its own time counter, synchronized with Network Time Protocol. The two values are recorded in a text file, so it is possible to make statistics and draw graphs about mains frequency stability.

Connecting an oscilloscope to the A mark of the circuit above, I noticed that the AC voltage was not perfectly rectified. There is residual positive voltage when the AC is negative :

I also noticed that when I touch the wires, the shape of the curve improved, so I replace my own body by a 22k resistor, connecting A to ground :

Then I obtained the desired curve :

So I will be pleased if someone with better electronical understanding than me explains why there is such residual positive voltage without the 22k resistor...



The MOSFET gate is capacitive, so it holds voltage once the diode is reversed biased and cut off, and
variousl leakages through the diode and zener probably dominated the voltage curve until shorted out
with 22k (which is much lower resistance than any leakage or an oscilloscope probe).

The two values are recorded in a text file, so it is possible to make statistics and draw graphs about mains frequency stability.

And.... What did you find?

It should be far-better than a quartz crystal clock. Electric utilities try to be "perfect" and they "correct" over-time, so there should be no long-term drift or error accumulation. And of course, there can be variations in network latency but those errors won't accumulate and so the total error should small over a long time too. ...Short-term "stability" errors may be in your measurement set-up. :wink:

Some electric utilities also us GPS clocks to keep all of the power plants in-synch and in-phase, and I guess they have to compensate for phase-shifts over long-distance transmission lines.

Analog electric clocks have also used synchronous motors for a long time to keep "perfect" time (as long as there's no power interruption).

Short term deviations from the target value of 50/60 Hz are used as a monitor of the "health" of the power grid, and together with phase adjustments, to control the flow of power from one section of the grid to another.

Use a schmitt trigger CMOS gate in place of the MOSFET. Keep the diode, zener, and resistors.

@MarkT : thanks, that's the reason. Furthermore I suspect the breadboard to have some capacitance also. I often have this kind of trouble (bad contacts and residual capacitance) with solderless breadboards.

@Polymorph : a schmitt trigger was my first thought but I don't have one.

@DVDdoug & jremington : I live in Reunion Island, a french territory where mains power is 230V @ 50Hz.
I've measured the frequency during nine and half days and it appears to be neither accurate nor stable. It oscillates fast between 49.8 and 50.2 Hz, with an average at 50.02 Hz. The timer gains 332 s during the test, that is 35 s/day.
I had noticed this before with my old LED 50Hz clock. It's the reason I opened it, hoping to find a way to adjust it (I thought it was driven by quartz).

Similar experiment have been done, with interesting reports, here :


It oscillates fast between 49.8 and 50.2 Hz,

with an average at 50.02 Hz.

Not a problem.

That would be a problem for mains powered clocks.
How did you measure that. Surely not with an Arduino with resonator reference.

To measure this, use a common mains powered (alarm) clock.
It would be running fast if average mains frequency wasn't exactly 50.000000 Hz

How did you measure that. Surely not with an Arduino with resonator reference.

Explained above.
The arduino just counts the pulses with :

attachInterrupt(digitalPinToInterrupt(2), pulse, RISING);

The pulse() function send a tick to a computer via serial each 50 pulses.
A program in the computer records the ticks and compares them with its own timer synchronized with NTP.

Arduino code :

#define ECHO 2		// pin qui reçoit la fréquence à mesurer ( !!! 3-5 V maxi !!! )
#define FREQUENCE 50

unsigned int p=0;
unsigned long sec=0;

void setup()
	pinMode(ECHO, INPUT);
      	attachInterrupt(digitalPinToInterrupt(ECHO), pulse, RISING);
void pulse()
	if (p==0)

void loop() {}

BTW the original circuit is wrong - it is relying on parasitic characterisrics of the parts such as leakage current and parasitic capacitance of diodes. With ideal parts you should see 5.1V on point A all the time because "the current has nowhere to go" from this point.

An small NPN transistor would do better here.

1N4148 diode from base to ground (cathode to base).
(10k) resistor from AC-in to base.
Nothing else, except a 2k2 10k collector resistor.
You can remove that one too if you use internal pull up on the Arduino pin.

Experiment with adding a 10-100n cap from base to ground.
That low pass filter will keep out mains spikes that could add unwanted pulses/counts.
A time window might also be needed in your software if your mains is "poluted".

You can make a schmitt trigger with just an Op Amp with a little positive feedback.

An small NPN transistor would do better here.

Brillant. I build your circuit and the output is a neat 5V square. Simpler than mine also.

@Polymorph : Thanks for the tip. I will experiment this.