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.
hello sir,
I want to detect the period of an square wave (say 0 & 2 volts)using a microcontroller (Atmel 89c51). Kindly provide me with some details. I shall be forever grateful.
Regards
roy_biplab_89@yahoo.co.in
Should I use an external timer IC for measuring the period or will the existing external crystal oscillator of the microcontroller be enough for the measurement..?