Measure Input Frequency

The setup for Measure Input Period to measure the input period can also be used to measure the frequency of an unknown clock. Set up the timer as per Table 2-6. But instead of selecting a system oscillator as a timer clock, connect the unknown signal from the I/O pin (PPS input) or CLC. Then select the ERS input as a pulse train or clock of known period TSAMPLE (for example, the output of a crystal-clocked timer or a Pulse-Width Modulator (PWM)). The CIF interrupt will occur with each cycle of ERS, and the frequency of the input is then the captured value in TUxyCR/TSAMPLE.

As an example, suppose the ERS-input timer is set to overflow 100 times every second, making TSAMPLE = 10 ms. Let’s say that when CIF occurs, the value of TUxyCR = 7300. Upon calculation, the input frequency comes out to be 7300/10 ms = 730 kHz.