Pic16f877 timer 0 problem.

Status
Not open for further replies.

rajtech

Member level 2
Joined
Dec 25, 2007
Messages
45
Helped
4
Reputation
8
Reaction score
2
Trophy points
1,288
Activity points
1,569
Hi,
I am using pic17f877 to measure motor speed in RPM.
I connect sensor output(pulse) to RB0 interrupt.
Turn ON Timer0 and check the RB0 pin for every 1 sec to count the pulse and then multiply the data with 60 to get RPM -- per 1 min.
Here is my code, Pls help me to check and advice me , is this is the correct way of calculate the RPM. tHANKS.

CRYSTAL FREQ: 4 MHZ

if (TMR0 ==250 ){
TMR0 = 0;
SEC ++;


if(SEC == 1000 ){ //
RPM = (count/8)*60;
SEC = 0;

}
}
/////////////////////////////////////

static void interrupt
isr()
{

if(INTF==1)
{
INTF=0;
count++;

}
}
 

You have totally misunderstood the point of a timer. Read the Timer0 descritpion in PIC16F877 datasheet or the "Mid-Range MCU" information document provided on the microchip website.
 

Use the Timer0 interrupt for sampling. Use INTERRUPTS. Don't poll the value in main().
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…