Digital frequency meter by PIC microcontroller using timer 1 (0-9999 Hz)
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.
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 “.
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.
From Schematic to PCB Production, Just Need One Tool
Free Circuit Design Software: learn to use Editor quickly and easily
Cheapest PCB: 10pcs 2-layers 10cm×10cm only $8.21, 3-day build time, 100% E-test
Current Project / Post can also be found using:
- frequency meter proteus microchip