Measuring the signal period is a common problem in embedded systems. This can be measuring the time between two events or measuring signal frequency f=1/T and so on.
Measuring the time interval or period is based on comparing event time t with discrete-time usually produced by a timer. This usually is done by filling the event time t with discrete-time intervals t. According to this, the discrete-time signal period has to be much shorter than event time: t<< t. Then counting these short time intervals, we can determine the event time.
In figure 1 above, we see the signal period (1), we need to measure. Circuit logic detects when the signal crosses zero and forms a digital impulse. After the period passes, the logic cuts that impulse, and so we have a square impulse which length is equal to the sine wave signals period (2). When the start of the signal period is detected, the system timer starts counting (filling the square impulse), and when the period ends up, the timer stops counting. As a result, we have m timer counts during signal periods. So embedded system knows the time of one-timer count and timer counted m times during the period, then signal period can easily calculate t=T=m*t. Usually, it is more convenient to operate with integer numbers, so if we know system timers frequency, then the signal period will be T=m/Ftimer.
Having this data, we can calculate the frequency of the input signal. This is how frequency meters usually works. If you need to measure higher frequencies where the signal period is shorter than the timer counter one clock period, then you should use an additional circuit where the main part is frequency divider â€“ usually it is digital counter IC.
Using this methodology, it is easy to measure the phase shift of the signal. I am not going into details as the picture above describes an idea quite well.