Measuring "phase" difference between two square waves

I'm using an Arduino Uno. Using digital pins 12 and 13 as the input channels.

Here is my code:

#include <math.h>

void setup() {
Serial.begin(9600);
pinMode(12, INPUT);
pinMode(13, INPUT);
}

void loop()
{
unsigned long t1, t2;

if (digitalRead(12) == HIGH)
{
t1 = micros();
}
if (digitalRead(13) == HIGH)
{
t2 = micros();
}

float vout = 5*(t2-t1)/1000000;
Serial.print(t1);
Serial.println(" = t1");
Serial.print(t2);
Serial.println(" = t2");
Serial.print(t2-t1);
Serial.println(" = difference");
Serial.print(vout);
Serial.println(" = vout");
}

The frequency of the input square waves is 40kHz. The output dc voltage is going to control a voltage controlled oscillator. I need to be able to either subtract or add (based on whether the phase difference is positive or negative) the dc voltage to a set "control voltage" of 5V.