Found this article on microchips site.
http://ww1.microchip.com/downloads/en/DeviceDoc/chapter 3.pdf
They have a section Measuring a period of a square wave with averaging that I am not understanding.
1. Configure control bits CCPxM3:CCPxM0
(CCPxCON<3:0>) to capture every 16th
rising edge of the waveform.
2. Configure the Timer1 prescaler so Timer1 will
run 16 TMAX(1) without overflowing.
3. Enable the CCP interrupt (CCPxIE bit).
4. When a CCP interrupt occurs:
a) Subtract saved captured time (t1) from
captured time (t2) and store (use Timer1 interrupt flag as overflow indicator).
b) Save captured time (t2).
c) Clear Timer1 flag if set.
d) Shift value obtained in step 4.a right four
times to divide by 16 – this result is the
period (T).
Steps 1-4c are easy enough. They lose me on 4d. I understand the dividing part but wouldn't you need 16 samples to average and divide by 16?
They go on to say the advantages are:
Fewer CCP interrupts to disrupt program flow
How is this possible?
http://ww1.microchip.com/downloads/en/DeviceDoc/chapter 3.pdf
They have a section Measuring a period of a square wave with averaging that I am not understanding.
1. Configure control bits CCPxM3:CCPxM0
(CCPxCON<3:0>) to capture every 16th
rising edge of the waveform.
2. Configure the Timer1 prescaler so Timer1 will
run 16 TMAX(1) without overflowing.
3. Enable the CCP interrupt (CCPxIE bit).
4. When a CCP interrupt occurs:
a) Subtract saved captured time (t1) from
captured time (t2) and store (use Timer1 interrupt flag as overflow indicator).
b) Save captured time (t2).
c) Clear Timer1 flag if set.
d) Shift value obtained in step 4.a right four
times to divide by 16 – this result is the
period (T).
Steps 1-4c are easy enough. They lose me on 4d. I understand the dividing part but wouldn't you need 16 samples to average and divide by 16?
They go on to say the advantages are:
Fewer CCP interrupts to disrupt program flow
How is this possible?