Here you will see how easily we can make Digital frequency meter by PIC microcontroller using timer 1. To make this project we need clear idea on timer 1 module of PIC16F877 microcontroller. We need to know how we can configure timer 1 module to do our desire work. For that I suggest please refer my previous post “Timer Modules in pic16f877 microcontroller”.

As we know frequency = Number of full circle per second. So for making frequency meter we have to count number of positive pulses for external signal which we have to measure. As I mention earlier we have to configure T1CON (Timer1 Control Register) properly as per our requirement.  For reading external clock (or pulse) we normally set the prescaler 1:1 ratio. It means we do not delay the sampling of the external pulse, but treat the external clock as it is to count number of pulses for specified time duration.

 Timer Modules in pic16f877 microcontroller

So if we run Timer 1 as a counter mode, there are two pins we can use to apply the external clock pulse RC0/T1OSO and RC1/T1OSI. Selection of one of them is controlled by the T1OSCEN bit.

Setting the bit selects RC1/T1OSO and clearing it does for RC0/T1OSI. In our project as we use counter mode is synchronous, we clear the T1SYNC bit. For TMR1CS bit, we set it for external clock counting. Finally, we set the TMR1ON bit to start the Timer1 module. Counting of the rising edge of the external clock pulse would increase the TMR1 registers by one for every external clock. And TMR1 register made with two 8 bit register TMR1L and TMR1H.When the content of TMR1 crosses from FFFFh to 0000h, the Timer1 interrupt bit TMR1IF would be set, if interrupt is enabled. Usually, when we count number of pulses within a period, we disable the interrupt, and after the lapse of the time, we stop the timer and read the content of TMR1 register.


To make our project “Digital frequency meter by PIC microcontroller using timer 1” Then what will be our bit pattern of TICON register? For counting external clock pulses entered to the pin 15 RC0/T1OSO, bit pattern of T1CON register would be 00000010. When we start the counting, we set the TMR1ON, bit0 of the T1CON and that time bit pattern of T1CON register will be 00000011.


In bellow you see the circuit diagram for simulation in Proteus for our project “Digital frequency meter by PIC microcontroller using timer 1 “.

frequecy meter

In bellow you will find the complete c code written in mikro c pro for pic. Here i used inbuilt delay program ( ms_delay(1000)) for 1 sec time interval.


Embedded C Code
// Name : Digital frequency meter by PIC microcontroller using timer 1
// Author : Subham Dutta
// Date : 22-07-14
// Website :
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D7 at RB0_bit;
sbit LCD_D6 at RB1_bit;
sbit LCD_D5 at RB2_bit;
sbit LCD_D4 at RB3_bit;sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D7_Direction at TRISB0_bit;
sbit LCD_D6_Direction at TRISB1_bit;
sbit LCD_D5_Direction at TRISB2_bit;
sbit LCD_D4_Direction at TRISB3_bit;
// End LCD module connections
void main() {
int c=0,i=0,z=0;
char txt[5],txt1[5],*res;;
lcd_out(1,1,” WORKING..”);
lcd_out(1,1,” WORKING….”);
lcd_out(1,1,” WORKING……”);
T1CON= 0B00000011;delay_ms(1000);
T1CON= 0B00000010;
c= TMR1L;
i= TMR1H * 256;
z= c+i;
lcd_out(1,1,” FREQUENCY IS”);
lcd_out(2,7,” Hz”);