Timer 1 and Xtal OSC?

Discussion in 'Embedded Systems and Microcontrollers' started by spinnaker, Mar 9, 2012.

  1. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    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:

    Code ( (Unknown Language)):
    1.  
    2.     //Timer1 Registers Prescaler= 1 - TMR1 Preset = 65475 - Freq = 32786.89 Hz - Period = 0.000030 seconds
    3.     T1CONbits.T1CKPS1 = 0;   // bits 5-4  Prescaler Rate Select bits
    4.     T1CONbits.T1CKPS0 = 0;   // bit 4
    5.     T1CONbits.T1OSCEN = 1;   // bit 3 Timer1 Oscillator Enable Control bit 1 = on
    6.     T1CONbits.NOT_T1SYNC = 1;    // bit 2 Timer1 External Clock Input Synchronization Control bit...1 = Do not synchronize external clock input
    7.     T1CONbits.TMR1CS = 2;    // bit 1 Timer1 Clock Source Select bit...0 = Internal clock (FOSC/4)
    8.     TMR1H = 255;             // preset for timer1 MSB register
    9.     TMR1L = 195;             // preset for timer1 LSB register
    10.     T1CONbits.TMR1ON = 1;    // bit 0 enables timer
    11.  
    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?
     
  2. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    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.
     
    spinnaker likes this.
  3. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016

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

    Senior Member

    Sep 7, 2009
    2,803
    594
    I dug out the datasheet and it turns out it shouldn't make any difference:
     
  5. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    OK so what is my issue then? Could it be the caps?
     
  6. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016

    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.
     
  7. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016
    Yay That did it! It was the caps!
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I know your problem is gone. But have you given the setting of SOSCSEL (CONFIG2L<4:3>) any thought also
     
  9. Markd77

    Senior Member

    Sep 7, 2009
    2,803
    594
    Sorry, my C skills are nonexistent, I thought that T1CONbits.blah would be 0 or 1. Maybe one day I will have made enough mistakes to understand C.
     
  10. spinnaker

    Thread Starter AAC Fanatic!

    Oct 29, 2009
    4,887
    1,016

    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.
     
Loading...