Timer 1 and Xtal OSC?

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
I have a Pic 18F27J53. I have configured Timer 1 to work from the internal RC OSC and it works fine.

I then added a 32,768 XTAL between pins T1OSI and T1OSO on my pic that is pins 11 and 12. Also have one cap going from each pin to ground.

The timer does not function in this mode. Here is my code to initializr the timer:

Rich (BB code):
    //Timer1 Registers Prescaler= 1 - TMR1 Preset = 65475 - Freq = 32786.89 Hz - Period = 0.000030 seconds
    T1CONbits.T1CKPS1 = 0;   // bits 5-4  Prescaler Rate Select bits
    T1CONbits.T1CKPS0 = 0;   // bit 4
    T1CONbits.T1OSCEN = 1;   // bit 3 Timer1 Oscillator Enable Control bit 1 = on
    T1CONbits.NOT_T1SYNC = 1;    // bit 2 Timer1 External Clock Input Synchronization Control bit...1 = Do not synchronize external clock input
    T1CONbits.TMR1CS = 2;    // bit 1 Timer1 Clock Source Select bit...0 = Internal clock (FOSC/4)
    TMR1H = 255;             // preset for timer1 MSB register
    TMR1L = 195;             // preset for timer1 LSB register
    T1CONbits.TMR1ON = 1;    // bit 0 enables timer
It must be my dyslexia or something but when I ordered parts somehow I ordered 22pf caps and the xtal calls for 12pf caps.

I don't have any 12pfs on hand to try.

Would this be too large of a capacitance to cause the xtal osc not to function at all or do I have another issue?
 

Markd77

Joined Sep 7, 2009
2,806
I haven't used 18F chips but on 16F chips it is important to set the pins as input or output correctly, otherwise it won't work.
T1CONbits.TMR1CS = 2;
Should this be 0 or 1?
I think two 22pF crystals in series is 11pF if you ordered spares.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
I haven't used 18F chips but on 16F chips it is important to set the pins as input or output correctly, otherwise it won't work.

Should this be 0 or 1?
I think two 22pF crystals in series is 11pF if you ordered spares.

OK so I should try setting T1OSI as an input and T1OSO as an output?
 

Markd77

Joined Sep 7, 2009
2,806
I dug out the datasheet and it turns out it shouldn't make any difference:
When Timer1 is enabled, the RC1/CCP8/T1OSI/UOE/
RP12 and RC0/T1OSO/T1CKI/RP11 pins become
inputs. This means the values of TRISC<1:0> are
ignored and the pins are read as ‘0’.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
I haven't used 18F chips but on 16F chips it is important to set the pins as input or output correctly, otherwise it won't work.

Should this be 0 or 1?
I think two 22pF crystals in series is 11pF if you ordered spares.

This is what the datasheet says.

bit 7-6 TMR1CS<1:0>: Timer1 Clock Source Select bits
10 = Timer1 clock source is the T1OSC or T1CKI pin
01 = Timer1 clock source is the system clock (FOSC)(1)
00 = Timer1 clock source is the instruction clock (FOSC/4)

I read that as I need to set TMR1CS to 2.

I have some extra caps I will try putting 2 in series.

This is breadboarded BTW.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
I know your problem is gone. But have you given the setting of SOSCSEL (CONFIG2L<4:3>) any thought also

I am currently using SOSCSEL = HIGH but I will probably change it to LOW. I am not sure I understand the purpose of DIG.

Timer 1 is driving an RTC and it is keeping pretty good time. No drift noticed yet after about 24 hours.
 
Top