Hi,
The interrupt version of the frequency counter was in FCV5 which I have converted to FCV4 for you. Here is some explanation of the program:
Variables:
You will see four variables declared in the program. Two of them are byte count and update_display and two are int freq and Display_Freq. freq variable is used for accumulating number of input pulses in one second whereas Display_Freq is used to display that number of pulse in display.
Update_display variable is used to update display data. If update_display =1 only then display will be re-written and you will see this variable is initialized 0 outside the loop and set to 1 in TMR_INT macro after 1 s which is cleared again after displaying in LCD.
Count variable is used to count number of TMR0 interrupt which ultimately helps to measure 1 s. If you look at the properties of TMR0 interrupt (double click on TMR0 enable icon), you will see interrupt frequency is 75 and if you look at TMR_INT macro you will see we have incremented count and looking for count to be 75. So count is initialized before loop and and cleared after 1 s completion.
Interrupts:
I have used here two interrupts as you see. One is TMR0 interrupt for measuring 1 s. The other is RB0INT which is used to detect every input pulse for counting. If you double click RB0INT enable macro and enter into properties you can see we only detects rising edge of pulses but you can change that to falling edge..that's doesn't matter as long as you are using rectangular pulses.
RBOINT calls Read_input macro where I have Freq = Freq+1 which means each time this macro will be called Freq will be increased. In other word it's counting number of pulses until it cleared in TMR_INT macro after 1 s.
Before loop and after 1 s we have cleared tmr0 register using c code to ensure that when program starts 1 s it's really close to 1 s as this register keeping the track of time with count variable.
Main
In main, the always true loop waits for update_display to be set to display number into LCD and then reset freq variable for next 1 s and clear update_display to avoid writing display continuously in between one sec.
Hope that clear now.
![Smile :)](./images/smilies/icon_smile.gif)