How to measure frequency of sine wave using pic microcontroller? I found the article on this website http://microcontrollerslab.com/sine-wave-frequency-measurement-using-pic/ But I didn't understand code. Anyone can help me to understand code on this website?
This is the key element of the frequency measurement code:
TMR0=0; // clear TMR0 Delay_ms(1000); // Delay 1 Sec ... Display_Freq(TMR0/2); // divide by 2
The author is using the TMR0 timer/counter to count the zero-crossing events of the input signal. (The article uses a transformer to step down 220VACrms 50Hz mains line frequency to 9VACrms, then uses a full bridge rectifier and a resistive divider to generate the zero-crossing event signal. I'm not sure how they intended to test this circuit.)
After running the counter for 1 second, the value in the counter is equal to double the frequency, because each full-wave rectified cycle has two pulses.
The rest of the code in
Display_Freq(f) is just user interface code, to convert the numerical frequency into characters to display on the LCD.