Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
December 10, 2016, 02:08:34 02:08


Login with username, password and session length


Pages: [1]
Print
Author Topic: PLS HELP, PIC16F877 TIMER0 PROBLEM  (Read 2005 times)
0 Members and 1 Guest are viewing this topic.
microtech
Newbie
*
Offline Offline

Posts: 29

Thank You
-Given: 13
-Receive: 16


« on: September 30, 2010, 08:28:54 20:28 »

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/*60;
SEC = 0;

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

static void interrupt
isr()
{

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

}
}
Logged
TomJackson69
V.I.P
Active Member
*****
Offline Offline

Posts: 221

Thank You
-Given: 23
-Receive: 63


« Reply #1 on: September 30, 2010, 09:48:23 21:48 »

Assume that each RB0 int is one revolution.

How do you get TMR0 = 250 equal ONE second? I think at 4MHz, 250 count is 62.5uS that is:
1/4000000 = 0.000000250
So 1000000uS/ 62.5uS = 16000

You will need few variables to keep track of overall operation. Let say we have:
-   Num_Of_62_5uS
-   Num_Of_Sec _



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

     if(Num_Of_62_5uS == 16000)
     {
        Num_Of_Sec += 1;   // increase number of second count (do you need to wait this long to update???)
         RPM = count * 60;   // you have got the RPM
            // Now print out or do whatever with it…
     }
}
 
Other way to do is use TMR0 interrupt. Since it count from 0 to 255 and roll back to 0 and generate INT. You can calculate how long it takes for TMR0 INT. Than find how many TMR0_INT to get one second. When you get to one second than get the count value. This count value multiply to 60 you get the RPM.

Please check to make sure the PIC16F877 has one instruction per clock cycle.

This is just an idea, you must test your program to see if it is correct.

Tom
« Last Edit: September 30, 2010, 09:51:55 21:51 by TomJackson69 » Logged

Con Rong Chau Tien
Top
Senior Member
****
Online Online

Posts: 325

Thank You
-Given: 38
-Receive: 1633


« Reply #2 on: October 01, 2010, 12:50:37 00:50 »

Maybe easier to connect sensor to RC2/CCP1 pin and use Timer1 Capture Mode to measure time between pulses. Then RPM = 60/time.

http://books.google.co.uk/books?id=RFLtu4fej00C&lpg=PA135&ots=nrH3pDSdYl&dq=PIC%20microchip%20RPM&pg=PA135#v=onepage&q&f=false

Embedded C Programming and the Microchip PIC
http://www.sonsivri.com/forum/index.php?topic=26650.0
Logged
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC