problem understanding timers :/

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
sayf alawneh
Posts: 1
Joined: Thu Oct 02, 2014 9:38 am

problem understanding timers :/

Post by sayf alawneh » Thu Oct 02, 2014 9:43 am

guys i really need help my project is to make a frequency counter (frequency meter) can cout frequency up to 5Mhz using TMR1 or TMR0 i am lookig since 2 weeks in every where but still cant understand cause every body explain it different way than the other ,,,, i just need to know the maximum frequency i can count using both timers and whatt is the relation between the max frequency i can count and the crystal oscillator ?
also lot of guys told me to use TMR1 but why TMR1 and not TMR0 ??? i know TMR1 is 16 bit and TMR0 is 8 bits
for my project i used TMR1 and i really dont know why :(
as a test i used PWM from pic16f877a and sent the pWM pulse to T1CkI in another 16f877a
but the accuracy wasnt good !! for example a pwm of 15 k HZ was read 15252 HZ an error of 252 HZ ???
also i couldnt read more than 30Khz i couldnt get the needed range from 1 hz to 5Mhz !! also i need good accuracy is the problem in the code??? here is the counter code guys
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;
void main() {
int c=0,i=0,n=0;
char txt[5],txt1[5],*res;;
lcd_out(1,1," WORKING.");
lcd_out(1,1," WORKING ");
T1CON= 0B00000011;delay_ms(1000);
T1CON= 0B00000010;
c= TMR1L;
i= TMR1H * 256;
n= c+i;
lcd_out(1,1," FREQUENCY IS");
lcd_out(2,7," Hz ");
and the PWm code is simple just to generate a pulse with 15Khz
guys am really a newbie please i need help i really need it please explain to me as a newbie
i only have 5 days to finish this project :(

Support Volunteer
Posts: 1244
Joined: Sun Nov 09, 2008 2:11 am
Location: Minot, N.D.

Re: problem understanding timers :/

Post by skimask » Thu Oct 02, 2014 7:43 pm

5 days?
I ignore "one post wonders".

Support Volunteer
Posts: 2823
Joined: Tue Sep 08, 2009 12:07 pm
Location: Philadelphia, USA

Re: problem understanding timers :/

Post by waltr » Fri Oct 03, 2014 6:40 am

Open the DATA SHEET and go to the TMR/PWM sections. Then do the math shown to determine what frequencies you can get.
Hint: 15kHz exactly is not possible with any XTAL frequency. If you really need exactly 15kHz then you will need a XTAL of a specific frequency.

Post Reply