Timer Calculator

General discussion on mikroC PRO for PIC.
Post Reply
Author
Message
Sy
Posts: 708
Joined: 10 Dec 2009 13:41
Location: UK

Timer Calculator

#1 Post by Sy » 19 Jan 2013 11:22

Originally I was using the PIC Timer Calculator application from http://pictimer.picbingo.com/, however the application displayed an expiry message, and the download links on the site no longer work.

So I downloaded the mikroElektronika Timer Calculator application from libstock. On the first project I used it for I was using a PIC16F887 running at 8Mhz, the timer I set-up was a 100ms timer and the results were great.

I've not moved onto my EasyPICv7 which has a PIC18F45K22 running at 32Mhz, I've set-up the application for the PIC18, Timer0, 32Mhz, 100ms, it does display a dialog warning me of a small difference in the requested 100ms period to the actual timer accuracy, but this is in the ns, difference error was 0.000249999%. However when I use the code produce the actual timing seems way out and nothing like 100ms.

This is the code I got from the application:

Code: Select all

void InitTimer0(){
  T0CON	 = 0x83;
  TMR0H	 = 0x3C;
  TMR0L	 = 0xAF;
  GIE_bit	 = 1;
  TMR0IE_bit	 = 1;
}
 
void Interrupt(){
  if (TMR0IF_bit){ 
    TMR0IF_bit = 0;
    TMR0H	 = 0x3C;
    TMR0L	 = 0xAF;
    //Enter your code here
  }
} 
Kind Regards,
Sy

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Timer Calculator

#2 Post by janni » 19 Jan 2013 15:51

Maybe processor is not running at 32MHz? Settings are correct (accurate reload value is 0x3CB0, not 0x3CAF, but that's minor issue).

If you want to avoid extraneous first interrupt, clear TMR0IF bit before enabling Timer0 interrupts (especially when you turn the timer on before loading it's registers).

Sy
Posts: 708
Joined: 10 Dec 2009 13:41
Location: UK

Re: Timer Calculator

#3 Post by Sy » 19 Jan 2013 16:58

Doh!, thanks Janni, that was it...
Kind Regards,
Sy

Post Reply

Return to “mikroC PRO for PIC General”