Go to Post I would say FIRST is quite an addiction.............but one of the BEST addictions you'll ever have. - RoboMadi [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Spotlight this post!  
Unread 15-03-2004, 13:33
roknjohn roknjohn is offline
Registered User
#1051
Team Role: Engineer
 
Join Date: Jan 2003
Location: Marion
Posts: 31
roknjohn is an unknown quantity at this point
Timer interrupt hic-cupping - HELP

Trying to set up a 32-bit 10Mhz timer...

I initialized Timer1 like this:
Code:
volatile unsigned int tmsClock = 0;
 
void Initialize_Timer_1(void)  
{
 TMR1L = 0x00;  
 TMR1H = 0x00;
   
 T1CONbits.T1CKPS0 = 0; // 1:1 prescaler 10Mhz
 T1CONbits.T1CKPS1 = 0; 
 T1CONbits.T1OSCEN = 0; // oscillator disabled
 T1CONbits.TMR1CS = 0; // use the internal clock
 T1CONbits.RD16 = 1; // timer 1 register operations are done in one 16-bit access

 PIE1bits.TMR1IE = 1; // Enable interrupt on overflow 
 IPR1bits.TMR1IP = 0; // overflow interrupt is low priority 
 T1CONbits.TMR1ON = 1; // Timer 1 is enablED
}

void Timer_1_Int_Handler(void)
{
 // this function will be called when a timer 1 interrupt occurs
  tmsClock++;
}
The handler simply increments a 16-bit counter, every 0.00655 seconds, which rolls over every 429.49 seconds. Then, I wrote these functions to fetch the 32bit snapshot of the timer:
Code:
unsigned int GetTick(void)  //Gets 16-bit timer value
{
   unsigned char Temp_Buf; // 8-bit temporary buffer
   unsigned int Timer_Snapshot; // 16-bit variable

   Temp_Buf = TMR1L; // TMR1L must be read before TMR1H
   Timer_Snapshot = TMR1H;
   Timer_Snapshot <<= 8; // move TMR1H data to the upper half of the variable
   Timer_Snapshot += Temp_Buf; // we now have all sixteen bits  

   return Timer_Snapshot;
}

unsigned long GetTime(void) //Gets 32-bit timer value
{
   unsigned long ThisTick;
   ThisTick=tmsClock;
   ThisTick <<= 16;		  //Mutliply by 65536
   ThisTick += GetTick();  //Add timer snapshot
   return ThisTick;
}
Now GetTime() works as intended, except every second or two I get a strange (really large) value returned. Any ideas?

BTW: I discovered this error around 3:00am on ship day, which was wreaking havoc on our autonomuous code. Without a controller to test on, I haven't been able to trace the problem.
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Interrupt timer, executing code asap? SeanCassidy Programming 10 07-03-2004 01:47
Problems with interrupt timer actorindp Programming 1 20-02-2004 16:59
Interrupt Handlers and Variable Scope kaszeta Programming 2 14-02-2004 18:30
When would I use an interrupt? Apollo Clark Programming 7 18-01-2004 13:29
Interrupts Questions mightywombat Programming 0 03-01-2004 14:50


All times are GMT -5. The time now is 10:25.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi