epideath
Joined: 07 Jun 2006 Posts: 47
|
TMR1 RTC running slow. |
Posted: Wed Jun 07, 2006 11:49 pm |
|
|
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
|
|
|