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

TMR1 RTC running slow.

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



Joined: 07 Jun 2006
Posts: 47

View user's profile Send private message

TMR1 RTC running slow.
PostPosted: Wed Jun 07, 2006 11:49 pm     Reply with quote

Can anyone explain this to me. I'm using a 18F4520 running with a 32,768KHz crystal on TMR1. This gives me a 2 second delay. I want it to be 1 second hence the setting of TMR1H to 0x80

If I use the code on top with the set_timer0(0x8000); It works OK, even though I haven't done any long time test for accuracy. datasheet says that it is possible to loose clock cycles doing it this way. They suggest doing it as the second code listing shows. But when I use the second listing it stays at 2 second delay. I have had this code sucessfully working with microchips MCC18 compiler. I am now porting it to PIC-C.

Any help trying to understand this would be wonderful.

Thanks,
Gary

Code:


#byte TMR1H = 0xFCF

int16 _ElapsedSeconds;

#int_TIMER1 HIGH
void TIMER1_isr()
{
   set_timer1(0x8000);
   //TMR1H = TMR1H | 0x80;   /* reset timer for 1 second delay */
   _ElapsedSeconds++;
}

---------------------------------------------Disassembly -------------------
32:                #int_TIMER1 HIGH
33:                void TIMER1_isr()
34:                {
35:                   set_timer1(0x8000);
  0170    0E80     MOVLW 0x80
  0172    6ECF     MOVWF 0xfcf, ACCESS
  0174    6ACE     CLRF 0xfce, ACCESS
36:                   //TMR1H = TMR1H | 0x80;   /* reset timer for 1 second delay */
37:                   _ElapsedSeconds++;
  0176    2A31     INCF 0x31, F, ACCESS
  0178    B4D8     BTFSC 0xfd8, 0x2, ACCESS
  017A    2A32     INCF 0x32, F, ACCESS
38:                }
39:               
  017C    909E     BCF 0xf9e, 0, ACCESS
  017E    EF7E     GOTO 0xfc


Code:

#byte TMR1H = 0xFCF

int16 _ElapsedSeconds;

#int_TIMER1 HIGH
void TIMER1_isr()
{
   //set_timer1(0x8000);
   TMR1H = TMR1H | 0x80;   /* reset timer for 1 second delay */
   _ElapsedSeconds++;
}

---------------------------------------------Disassembly -------------------
32:                #int_TIMER1 HIGH
33:                void TIMER1_isr()
34:                {
35:                   //set_timer1(0x8000);
36:                   TMR1H = TMR1H | 0x80;   /* reset timer for 1 second delay */
  0170    8ECF     BSF 0xfcf, 0x7, ACCESS
37:                   _ElapsedSeconds++;
  0172    2A31     INCF 0x31, F, ACCESS
  0174    B4D8     BTFSC 0xfd8, 0x2, ACCESS
  0176    2A32     INCF 0x32, F, ACCESS
38:                }
39:               
  0178    909E     BCF 0xf9e, 0, ACCESS
  017A    EF7E     GOTO 0xfc
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 08, 2006 12:42 am     Reply with quote

CCS uses the 16-bit access mode for Timer1. This mode is selected
by the RD16 bit in the T1CON register. If you want to use your OR'ing
method of updating TMR1H, then you need to put it into 8-bit mode.
epideath



Joined: 07 Jun 2006
Posts: 47

View user's profile Send private message

PostPosted: Thu Jun 08, 2006 7:28 am     Reply with quote

Thank you! That did the trick. Very Happy
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