CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

How can I calculate interrupt time?? (TMR0)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
fuzzy



Joined: 26 Feb 2005
Posts: 64

View user's profile Send private message

How can I calculate interrupt time?? (TMR0)
PostPosted: Sat Apr 29, 2006 6:02 am     Reply with quote

Code:

#define INTS_PER_SECOND 76     // (20000000/(4*256*256))

BYTE seconds;      // A running seconds counter
BYTE int_count;    // Number of interrupts left before a second has elapsed


#int_rtcc                          // This function is called every time
void clock_isr() {                 // the RTCC (timer0) overflows (255->0).
                                   // For this program this is apx 76 times
    if(--int_count==0) {           // per second.
      ++seconds;
      int_count=INTS_PER_SECOND;
    }

}

 set_timer0(0);
   setup_counters( RTCC_INTERNAL, RTCC_DIV_256 | RTCC_8_BIT);
   enable_interrupts(INT_RTCC);
   enable_interrupts(GLOBAL);


this code is a compiler's example.

What does it mean this expression: (20000000/(4*256*256)) ?

As i can understand 20000000 is clock frequency.
256 is prescaler division. What are 4 and the second 256??

Thanks
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sat Apr 29, 2006 7:22 am     Reply with quote

Quote:
As i can understand 20000000 is clock frequency.
256 is prescaler division.
True.

Quote:
What are 4 and the second 256??
The 4 comes from the timers being driven at Fosc / 4. This is related to the PIC using 4 clock cycles to execute a single instruction.

The 256 is the maximum value your timer can count up to before overflowing, at overflow an interrupt is generated and the timer starts counting at 0 again. For 8-bit timers use 256 and for 16 bit timers 65536.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group