Phase detector - Page 1
Forum section: electronics / beginners

author: Rigolon
author_rank: Regular Contributor
timestamp: October 24, 2017, 10:57:43 am
content: Hi all, newbie here on the forum.Starting by saying that english is not my main language, if there are some mistakes or something confusing, please let me know.So, i'm not sure if i should've post this on the RF part of the forum, but since I understand almost nothing about this circuit or how it works i hope you guys can help me.I am working on a phase detector project and found this one that intrigues me:https://uploaddeimagens.com.br/imagens/phase_detector-jpgU1 and U2 are SPST switches and the IN signal are PWM that have a phase difference of 180º between each other.I've made a few simulations and with frequency of 1kHz or higher the output gives a quite good DC signal (The higher frequency the better DC signal).But i quite don't undestand how does this circuit works, it seems to have a gain but how do i calculate it? Can anyone help me understand how the circuit works? What is the influence of the PWM being 180º from each other? (In this circuit when the PWM are 180º it gives about 4.6V and when in phase about -1.85V)And it's possible to change something so i would be able to work with lower frequencys, about 100Hz?PS: I need a circuit capable of detecting small phase shifts with good precision, are there any better phase detectors circuits?I've tried building a diode ring mixer, but it didn't worked as well as i hoped to.Thank you all.

author: Benta
author_rank: Super Contributor
timestamp: October 24, 2017, 02:57:34 pm
content: Do you mean square wave (instead of PWM)?

author: Rigolon
author_rank: Regular Contributor
timestamp: October 24, 2017, 03:21:13 pm
content: Well, yes and no.It's indeed a square wave, but it's being generated by a microcontroller.It's wrong to adress it as PWM?

author: Mjolinor
author_rank: Frequent Contributor
timestamp: October 24, 2017, 04:15:05 pm
content: Why not use an EXOR gate? They don't come any simpler.I think possibly I am not understanding your requirements.

author: Rigolon
author_rank: Regular Contributor
timestamp: October 24, 2017, 05:09:36 pm
content: Quote from: Mjolinor on October 24, 2017, 04:15:05 pmI started to "play" with the EXOR, it seems to work as i intented.But i would still like to understand how this mixer circuit works. Just for knowledge purpose

author: orolo
author_rank: Frequent Contributor
timestamp: October 24, 2017, 10:14:06 pm
content: The concept is interesting. Assume that the signals U1 and U2 are square waves 180 degrees out of phase and with 50% duty cycle, at the same frequency of V1. The opamp is acting as an inverting integrator. When U1 is up, the signal is felt at the inverting input, and the op amp integrates -V1 (it's an inverting integrator). When U2 is up, the signal is felt in the noninverting input, so the op amp integrates +V1.The result is that you are integrating the V1 signal multiplied by a square wave that alternates between +1 and -1 at the same frequency. The spectrum of that product has a DC component that is dependent(*) on the phase difference between V1 and the square wave. When you integrate it, you get a voltage curve at the output of the op amp with slope proportional to the phase deviation. The slope is, therefore, twice the sine of the phase difference, times the gain of the integrator, a few hundreds I'd say.The output will eventually saturate, so I assume this phase detector is part of a PLL or some similar circuit.To increase bandwidth, alter the RC sections R4/C1 and R7/C2 accordingly.(*) Linearly, for small phase deviations. It's twice the sine of the phase difference.Edit: Oh, I forgot the 1 Meg resistor at the feedback loop. The DC component won’t be integrated but amplified x10. The circuit won’t saturarte then.

author: katzohki
author_rank: Frequent Contributor
timestamp: October 24, 2017, 10:28:43 pm
content: You might like to check out this video, there is some good info related to phase detectors in it:

author: David Hess
author_rank: Super Contributor
timestamp: October 25, 2017, 04:50:36 am
content: Multipliers can be used as phase detectors. An exclusive-OR gate is a single bit multiplier. Diode ring mixers multiply and can be used as phase detectors. This example is a simplification of an active FET ring mixer.

author: Rigolon
author_rank: Regular Contributor
timestamp: October 25, 2017, 10:55:56 am
content: First of all thank you everyone that took time to help me.I am starting to understand quite well how this circuit works.Orolo, thanks to you i finally understood very easily (kind embarrassed that i didn't see the +1 and -1 multiplaction).But there are a few things that i still don't get.If i understood right, i can assume that when U1(wich acttualy goes on the non-inverting input) are in phase with V1, therefore U2 is 180º of V1, it works as a full wave rectifier. If this is correct, with an unity gain my output should be the DC singal with voltage equal to the amplitude in V1.Quote from: orolo on October 24, 2017, 10:14:06 pmIf what i said above is correct, and i didn't make any mistakes in my simulation, the signal is being amplified around x4.6. In my simulation i noticed that, excluding R4 and R7, every other resistor has influence on the gain, but i couldn't calculate the exact relation between them.

author: orolo
author_rank: Frequent Contributor
timestamp: October 25, 2017, 04:47:38 pm
content: You're right, the phase detector you posted is trying to do too much: it wants to be a x10 amplifier at DC, and at the same time a low pass filter (integrator) at higher frequencies. The gain becomes kludgy, and that's the reason of the 68k R3 resistor, which is only in the noninverting arm: a way to tune the gain controlling the discharge rate of C1 when the switch U1 is off.If we dispose of the low pass filtering, that you can do in another stage after all, I think we can build a good phase detector with more predictable and elegant gain, and half the switches, resistors and caps as a bonus. Here it is:The idea is the following. Imagine that V1 is a sinewave, \$V1 = V\, \sin(\omega t + \phi)\$, with phase \$\phi\$, of high enough frequency (for this circuit, 1KHz is enough). Using the switch, the signal is passed to the noninverting arm only for half the period, charging the capacitor, while for the other half of the period the switch is off, discharging the capacitor by essentially the same resistance (1% error).The net effect is that, at the noninverting input, you see half the wave low pass filtered by the 100k/1uF filter. The voltage at the noninverting input will be, after stabilising, the average of that half wave over its period:\$\frac{1}{2\pi}\int_0^{\pi}V\,\sin(t + \phi)\, dt \ = \ \frac{V}{\pi}\, \cos\phi \$So note that at the noninverting input, even without using the op amp yet, we already have phase detection. If we pass a 1V sinewave of phase zero, we expect a voltage at the noninverting input of 1/pi = 318mV, and in fact it's easy to check that this is the case.So the rest of the circuit gives a noninverting gain of 22/7, for a precise detection of phase following:\$V_{out} \ = \ \frac{22V_{in}}{7\pi}\,\cos\phi \ \approx \ V\,\cos\phi \$Of course, 22/7 is not pi, but it's close enough. The next best thing would be 355/113. So with this circuit you get the input amplitude of the wave multiplied by the cosine of its phase. If you input a 1V amplitude wave, you get the cosine of the phase. That's easy to check in simulation:Here you can see a very good cosine taken from the outputs of this phase detector at different phases, from 0 degrees to 360, when the input is a 1V amplitude sinewave. This is simpler and more predictable, and you can get rid of the ripple with a subsequent, dedicated low pass filter.The LTspice schematic, with embedded model for TL072, is attached below.

author: Rigolon
author_rank: Regular Contributor
timestamp: October 25, 2017, 06:05:25 pm
content: Orolo,I've been studying phase detectors in these past few days, and even though i found a lot of informations, for a begginer to understand it was very complicated.Thank you for giving such good and easy explanations and for taking your time to awnser with so much details and care.Just a few more questionsThe 22/7 it's the resistors on the feedback right? Just asking because in the schematic it's 15k and 7k.And the frequency (the 1kHz you used) it's ajusted by the R3 and C2 on the non-inverting input?PS:I wanna be like you when i grow up hahaha

author: orolo
author_rank: Frequent Contributor
timestamp: October 25, 2017, 06:25:16 pm
content: Quote from: Rigolon on October 25, 2017, 06:05:25 pmRemember that anon-inverting amplifierhas gain (R1+R2)/R1 = (15+7)/7 = 22/7 = 3.1428...QuoteYes, for thisRC low passthe -3dB point is 1/(6.2832*R*C) = 1/(6.2832*1e5*1e-6) = 1.6Hz. A bit extreme, but in the line of the original circuit.QuoteNah, we both want to grow up to be like the really talented people here. I'm just a hobbyist.

author: Mjolinor
author_rank: Frequent Contributor
timestamp: October 25, 2017, 07:01:18 pm
content: Best to not grow up at all really. I'm 62 years old and still no idea what I want to do when I grow up but I have sure tried a lot of things so far.

author: Rigolon
author_rank: Regular Contributor
timestamp: October 25, 2017, 07:05:07 pm
content: Orolo,Probably my last questionR2 is responsible for something? Or it works as something like a pull-down resistor?Quote from: Mjolinor on October 25, 2017, 07:01:18 pmIf possible I really wouldn't grow up at all hahaha. But since there is no escape I hope to at least be able to learn a lot and help people like these guys are helping me today.

author: orolo
author_rank: Frequent Contributor
timestamp: October 25, 2017, 07:23:57 pm
content: Quote from: Rigolon on October 25, 2017, 07:05:07 pmYes, when the switch closes, this resistor grounds the input signal, turning it into 0V. Otherwise, when the switch is closed the input would be floating.QuoteThat's the spirit, trying to give something back. Building a trivial project, I found myself carefully studying battery discharge curves and adjusting the circuit for maximum efficiency, and then wondered how far I've come since I started following Dave's videos and this forum.