Measuring "phase" difference between two square waves

The problem is in the code you didn't post.

Also tell us which Arduino you're using and how it's wired up.