I can't seem to get timer 1 working with an external osc on timer 1 on a PIC18F27J13 . Code works fine with the internal clock.
I have a 32768 crystal across T1OSO and T1OSI with a 12pf cap going to ground just as specified in the datasheet. I have a DIP package so the crystal is between pins 11 and 12.
Any idea what could be wrong?
I have a 32768 crystal across T1OSO and T1OSI with a 12pf cap going to ground just as specified in the datasheet. I have a DIP package so the crystal is between pins 11 and 12.
Any idea what could be wrong?
Code:
// PIC18F27J13 Configuration Bit Settings
// 'C' source line config statements
// CONFIG1L
#pragma config WDTEN = OFF // Watchdog Timer (Disabled - Controlled by SWDTEN bit)
#pragma config PLLDIV = 1 // 96MHz PLL Prescaler Selection (PLLSEL=0) (No prescale (4 MHz oscillator input drives PLL directly))
#pragma config CFGPLLEN = OFF // PLL Enable Configuration Bit (PLL Disabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset (Enabled)
#pragma config XINST = OFF // Extended Instruction Set (Disabled)
// CONFIG1H
#pragma config CP0 = OFF // Code Protect (Program memory is not code-protected)
// CONFIG2L
#pragma config OSC = INTOSC // Oscillator (INTOSC)
#pragma config SOSCSEL = HIGH // T1OSC/SOSC Power Selection Bits (High Power T1OSC/SOSC circuit selected)
#pragma config CLKOEC =OFF // EC Clock Out Enable Bit (CLKO output disabled on the RA6 pin)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor (Enabled)
#pragma config IESO = ON // Internal External Oscillator Switch Over Mode (Enabled)
// CONFIG2H
#pragma config WDTPS = 32768 // Watchdog Postscaler (1:32768)
// CONFIG3L
#pragma config DSWDTOSC = INTOSCREF// DSWDT Clock Select (DSWDT uses INTRC)
#pragma config RTCOSC = T1OSCREF// RTCC Clock Select (RTCC uses T1OSC/T1CKI)
#pragma config DSBOREN = OFF // Deep Sleep BOR (Disabled)
#pragma config DSWDTEN = OFF // Deep Sleep Watchdog Timer (Disabled)
#pragma config DSWDTPS = G2 // Deep Sleep Watchdog Postscaler (1:2,147,483,648 (25.7 days))
// CONFIG3H
#pragma config IOL1WAY = ON // IOLOCK One-Way Set Enable bit (The IOLOCK bit (PPSCON<0>) can be set once)
#pragma config ADCSEL = BIT10 // ADC 10 or 12 Bit Select (10 - Bit ADC Enabled)
#pragma config PLLSEL = PLL4X // PLL Selection Bit (Selects 4x PLL)
#pragma config MSSP7B_EN = MSK7 // MSSP address masking (7 Bit address masking mode)
// CONFIG4L
#pragma config WPFP = PAGE_127 // Write/Erase Protect Page Start/End Location (Write Protect Program Flash Page 127)
#pragma config WPCFG = OFF // Write/Erase Protect Configuration Region (Configuration Words page not erase/write-protected)
// CONFIG4H
#pragma config WPDIS = OFF // Write Protect Disable bit (WPFP<6:0>/WPEND region ignored)
#pragma config WPEND = PAGE_WPFP// Write/Erase Protect Region Select bit (valid when WPDIS = 0) (Pages WPFP<6:0> through Configuration Words erase/write protected)
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
#include <xc.h>
unsigned char ccpInterrupt = 0;
unsigned char tmrInterrupt = 0;
void main(void) {
OSCCONbits.IRCF0 = 1;
OSCCONbits.IRCF1 = 1;
OSCCONbits.IRCF2 = 1;
T1CONbits.TMR1CS = 3; // Timer1 clock source is external
T1CONbits.T1CKPS = 0; // 1:1 Prescale value
T1CONbits.RD16 = 0; // Enables register read/write of Timer1 in one 16-bit operation
PIR1bits.TMR1IF = 0; // Clear Timer 1 interrupt flag
PIE1bits.TMR1IE = 1; // Enable interrupt for Timer 1
INTCONbits.GIE = 1;
INTCONbits.PEIE = 1;
TMR1L = 0;
TMR1H = 0;
TRISCbits.TRISC0 = 0;
TRISCbits.TRISC1 = 0;
T1CONbits.TMR1ON = 1; // Timer 1 on
while(1)
{
}
return;
}
__interrupt(high_priority) void interrupts_highPriority(void)
{
if (PIR1bits.TMR1IF == 1)
{
PIR1bits.TMR1IF = 0;
tmrInterrupt = 1;
}
}