Measure time between signals (get phase)


I need to measure the time between two signals to get the phase. The problem is that the frecuency of the signals are around 100kHz. I don't know how is the best way to get the phase (which are around 200ns). I see to use input capture but the best frecuency of the timers is the TIMER_CLOCK1 which is 42MHz -> 23ns of period, but it bad accurracy. Are any way to get the phase with the Arduino Due? Using Sysclk or anything with that microcontroller which used the 84MHz. I have a the circuit with two comparators that trigger when each signal passes through 0V down flank. So I can use two pins of arduino or modify the circuit if it's necesary more pins.

My idea is something like this but i see your coments:

(This are the originals signals, no the comparator outputs)
I think with the time between the two timers i get the phase, but I dont know how to implement the code with registers to do this.

Thanks so much for any help.

Hi @javierch23
my suggestion is use of interrupts.
One interrupt for each signal.

RV mineirin

The ESP32 has a PCNT, which workes in the Arduino IDE, that can detect:

The ESP32 PCNT API The PCNT is module included with the ESP32 that does not require CPU time to operate. One setup the PCNT does its thing and the program queries for results.

Did you look at phase detector circuits? If the signals are both square wave with the same frequency all you need is an XOR and a low pass filter. Then you can use the ADC to get good precision.