# Phase differences of PWM square waves

From my understanding, pins 3 and 11 both use timer2, so I'm wondering if I use a simple analogWrite(3, 127) and analogWrite(11, 127), which both generate 50% duty cycle square waves...will they be in phase since they come from the same timer? This is crucial for my project, as I'm doing phase-sensitive detection (lock-in) and I need to figure out how to measure phase differences, and correct them.

Also, mildly related, are there any simple methods to multiply two waves? I could accurately measure phase differences with pulseIn() if I could multiply the waves coming from my output pins.

You have it right: they will both be in phase because they are coming from the same timer.

To "multiply" two waves...not sure on the intent. Are you talking about multiplication of sinusoidal waves after filtering the digital outputs?

-- The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected

RuggedCircuits: You have it right: they will both be in phase because they are coming from the same timer.

To "multiply" two waves...not sure on the intent. Are you talking about multiplication of sinusoidal waves after filtering the digital outputs?

-- The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected

Thanks for the fast reply, knowing that the waves will be in phase simplifies things greatly.

As far as multiplying two waves: assume two square waves, each of amplitude 1 and 50% duty cycle. If they're in phase, upon multiplying them together, you should see no change. Where the waves coincide, multiplying the amplitudes still yields 1 when the wave is "on" and 0 when the wave is "off". Now, suppose they're out of phase by 90 degrees. Then, I should see a new square wave, of amplitude 1 but 25% duty cycle. Waves out of phase by 180 degrees should cancel entirely. Multiplying my square waves should only affect duty cycle and preserve amplitude. That's what I'm trying to do to measure phase with pulseIn().

So multiply really being a logical AND of the digital levels.
Can use an external AND gate and brings its output back in for measuring?