Measuring signal period is common problem in embedded systems. This can be measuring time between two events or measuring signal frequency f=1/T and so on.
Measuring of time interval or period is based on comparing of event time t with discrete time usually produced by timer. This usually is done by filling the event time t with discrete time intervals Δt. According to this, 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.
Fig1. Filling interval with impulses
In figure 1 above we see the signal period (1) we need to measure. Circuit logic detects when signal crosses zero and forms digital impulse. After period passes the logic cuts that impulse and so we have square impulse which length is equal to sine wave signals period (2). When start of signal period is detected, then system timer start counting (filling the square impulse) and when period ends up, 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 period, then signal period can easily calculated: t=T=m* Δt. Usually it is more convenient to operate with integer numbers so if we know system timers frequency, then signal period will be T=m/Ftimer.
Hawing this data we can calculate the frequency of input signal. This is how frequency meters usually works. If you need to measure higher frequencies where signal period is shorter than timer counter one clock period, then you should use additional circuit where main part is frequency divider – usually it is digital counter IC.
Fig 2. Phase shift measurement
Using this methodology it is easy to measure phase shift of signal. I am not going in to details as picture above describes an idea wuit well.
This might be a good project idea for someone.