Timer 1 not running on PIC18F27J13

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
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?



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;
  }
   
   
}
 

Picbuster

Joined Dec 2, 2013
1,058
in your setup T1CONbits.TMR1CS = 3; // Timer1 clock source is external

in manual
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 (F OSC) (1)
00 = Timer1 clock source is the instruction clock (FOSC/4)

TMR1CS<1:0>: 3 not (11) not available

Picbuster
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Thanks guys. Wow do I feel stupid. I think it was the forest and the trees sort of thing. ;)

Well that is corrected but still not working. So I guess next to look at is the crystal itself. I do sort of things tacked in there on an old prototype board. I just designed a new board with crystals in the design.
 

jayanthd

Joined Jul 4, 2015
945
Thanks guys. Wow do I feel stupid. I think it was the forest and the trees sort of thing. ;)

Well that is corrected but still not working. So I guess next to look at is the crystal itself. I do sort of things tacked in there on an old prototype board. I just designed a new board with crystals in the design.
TMR1ON_bit = 1 ?
 

jayanthd

Joined Jul 4, 2015
945
This is wrong.

Code:
T1CONbits.TMR1CS =  3;  // Timer1 clock source is external
If you are using Oscillator as clock source then it is internal and not external.

External clock source is used in counters where T0CKI or T1CKI pins are used with respective timers.

OSCCON, OSCCON2 and OSCTUNE registers are not configured properly. They need to be configured for Internal Oscillator usage.
 

Ian Rogers

Joined Dec 12, 2012
1,136
This is wrong.

Code:
T1CONbits.TMR1CS =  3;  // Timer1 clock source is external
If you are using Oscillator as clock source then it is internal and not external.

External clock source is used in counters where T0CKI or T1CKI pins are used with respective timers.

OSCCON, OSCCON2 and OSCTUNE registers are not configured properly. They need to be configured for Internal Oscillator usage.
I am also confused!!!

@spinnaker Are you using a separate crystal on T1OSC 1 and T1OSC0??? Or are you sourcing the clock from the system clock??

I'm sorry about my posts but I had assumed an external crystal for timer1..
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
This is wrong.

Code:
T1CONbits.TMR1CS =  3;  // Timer1 clock source is external
If you are using Oscillator as clock source then it is internal and not external.

External clock source is used in counters where T0CKI or T1CKI pins are used with respective timers.

OSCCON, OSCCON2 and OSCTUNE registers are not configured properly. They need to be configured for Internal Oscillator usage.

Please don't confuse things further. I am not using an external system clock yet. Only a timer 1 external clock.

xtal on T1CKI/T1CKO only.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Original code is wrong
T1CONbits.TMR1CS = 3; // Timer1 clock source is external

It should be
T1CONbits.TMR1CS = 2; // Timer1 clock source is external

Or
T1CONbits.TMR1CS1 = 1; // Timer1 clock source is external
 

jayanthd

Joined Jul 4, 2015
945
[While reading I had missed that he is using separate crystal for Timer1 externally.

Still the OSCCON, OSCCON2 and OSCTUNE regsiters needs to be configured. His system oscillator is not working. If it works then I guess that his timer will also work.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
[While reading I had missed that he is using separate crystal for Timer1 externally.

Still the OSCCON, OSCCON2 and OSCTUNE regsiters needs to be configured. His system oscillator is not working. If it works then I guess that his timer will also work.

Why are you referring to me in the third person?

My system osc IS working T1 is not working. Do me a favor and stop posting to this thread. all you are doing is confusing the issue.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Thanks. I really think it is the crystal but I am posting the code below. I muddied the waters a bit by adding code for the RTCC. I wanted to see if at least that was running. I have a prototype board all etched out. All I need to do is finish population it and will do so later this evening to see if that fixes the issue.

I can also tear out the RTCC stuff later.


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;
unsigned char tmr1L;

#define   PICRTCC_BYTE   unsigned char
#define   PICRTCC_BOOL   unsigned char

#define _XTAL_FREQ 8000000
struct PICRTCC_time
{

  union
  {
  struct
  {
  PICRTCC_BYTE HRONE : 4;
  PICRTCC_BYTE HRTEN : 2;
  PICRTCC_BYTE HRNOTUSED : 2;
  } BCDparts;
  PICRTCC_BYTE BCDval;
  } hour;


  union
  {
  struct
  {
  PICRTCC_BYTE MINONE : 4;
  PICRTCC_BYTE MINTEN : 3;
  PICRTCC_BYTE MINNOTUSED : 1;

  } BCDparts;
  PICRTCC_BYTE BCDval;
  } minute;


  union
  {
  struct
  {
  PICRTCC_BYTE SECONE : 4;
  PICRTCC_BYTE SECTEN : 3;
  PICRTCC_BYTE SECNOTUSED : 1;

  } BCDparts;
  PICRTCC_BYTE BCDval;
  } second;   

};


struct PICRTCC_date
{
  union
  {
  struct
  {
  PICRTCC_BYTE YRONE : 4;
  PICRTCC_BYTE YRTEN : 4;
  } BCDparts;
  PICRTCC_BYTE BCDval;
  } year;


  union
  {
  struct
  {
  PICRTCC_BYTE MTHONE : 4;
  PICRTCC_BYTE MTHTEN : 1;
  PICRTCC_BYTE MTHNOTUSED : 3;
  } BCDparts;
  PICRTCC_BYTE BCDval;
  } month;


  union
  {
  struct
  {
  PICRTCC_BYTE DAYONE : 4;
  PICRTCC_BYTE DAYTEN : 2;
  PICRTCC_BYTE DAYNOTUSED : 2;
  } BCDparts;
  PICRTCC_BYTE BCDval;
  } day;


  union
  {
  struct
  {
  PICRTCC_BYTE WKDY : 2;
  PICRTCC_BYTE WKDYNOTUSED : 6;
  } BCDparts;
  PICRTCC_BYTE BCDval;
  } weekday;




};



void PICRTCC_init();
void PICRTCC_lockRTC();
void PICRTCC_unlockRTC();

void PICRTCC_setWeekDay(PICRTCC_BYTE dow);
void PICRTCC_setMonth(PICRTCC_BYTE tens, PICRTCC_BYTE ones);
void PICRTCC_setDay(PICRTCC_BYTE tens, PICRTCC_BYTE ones);
void PICRTCC_setYear(PICRTCC_BYTE tens, PICRTCC_BYTE ones);
void PICRTCC_setHour(PICRTCC_BYTE tens, PICRTCC_BYTE ones);
void PICRTCC_setMinutes(PICRTCC_BYTE tens, PICRTCC_BYTE ones);
void PICRTCC_setSeconds(PICRTCC_BYTE tens, PICRTCC_BYTE ones);

#define PICRTCC_isBusy() RTCCFGbits.RTCSYNC !=0
void PICRTCC_readDateTime(struct PICRTCC_date*, struct PICRTCC_time*);

#define PICRTCC_getTens(x) ((x & 0xF0) >> 4)
#define PICRTCC_getOnes(x) (x & 0x0F)

void PICRTCC_readDateTime(struct PICRTCC_date *d, struct PICRTCC_time *t)
{   
   
  PICRTCC_BYTE rtcc_year1;
  PICRTCC_BYTE rtcc_month1;
  PICRTCC_BYTE rtcc_day1;
  PICRTCC_BYTE rtcc_weekday1;
  PICRTCC_BYTE rtcc_hours1;
  PICRTCC_BYTE rtcc_minutes1;
  PICRTCC_BYTE rtcc_seconds1;

  PICRTCC_BYTE rtcc_year2;
  PICRTCC_BYTE rtcc_month2;
  PICRTCC_BYTE rtcc_day2;
  PICRTCC_BYTE rtcc_weekday2;
  PICRTCC_BYTE rtcc_hours2;
  PICRTCC_BYTE rtcc_minutes2;
  PICRTCC_BYTE rtcc_seconds2;

  PICRTCC_BYTE b;

  do
  {
  // Set pointer to the year
  RTCCFGbits.RTCPTR0 = 1;
  RTCCFGbits.RTCPTR1 = 1;

  d->year.BCDval = RTCVALL;  // Get the year
  b = RTCVALH;  // Read RTCVALH to decrement it

  d->day.BCDval = RTCVALL;  // Get the day
  d->month.BCDval = RTCVALH;  // Get the month, read decrements pointer

  t->hour.BCDval = RTCVALL;  // Get the hours
  d->weekday.BCDval=RTCVALH;  // Get the weekday, read decrements pointer

  t->second.BCDval = RTCVALL; // Get the seconds
  t->minute.BCDval = RTCVALH; //Get the minutes
   
   
  // Read a second time to check that read did not fall on a rollover boundary
  // Set pointer to the year
  RTCCFGbits.RTCPTR0 = 1;
  RTCCFGbits.RTCPTR1 = 1;
   
  rtcc_year2 = RTCVALL;  // Get the year
  b = RTCVALH;  // Read RTCVALH to decrement it
   
  rtcc_day2 = RTCVALL;  // Get the day
  rtcc_month2 = RTCVALH;  // Get the month, read decrements pointer   
   
  rtcc_hours2 = RTCVALL;  // Get the hours
  rtcc_weekday2 = RTCVALH;  // Get the weekday, read decrements pointer
   
  rtcc_seconds2 = RTCVALL; // Get the seconds
  rtcc_minutes2 = RTCVALH; //Get the minutes
   

  // Keep reading until the two reads agree to check read did not fall on a rollover boundary

  }
  while((rtcc_year2 !=d->year.BCDval) || (rtcc_day2 != d->day.BCDval) || (rtcc_month2 !=  d->month.BCDval) || (rtcc_weekday2 != d->weekday.BCDval) || (rtcc_hours2 != t->hour.BCDval) || (rtcc_minutes2 != t->minute.BCDval)|| (rtcc_seconds2 != t->second.BCDval)  );

  return;
}
void main(void) {
  struct PICRTCC_date d; struct PICRTCC_time t;
   
   
  OSCCONbits.IRCF0 = 1;
   OSCCONbits.IRCF1 = 1;   
   OSCCONbits.IRCF2 = 1;   
   
  T1CONbits.TMR1CS =  1;  // 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;   
   
  RTCCFGbits.RTCEN = 1;  //Enable RTC
   
  TMR1L = 0;
  TMR1H = 0;
   
  TRISCbits.TRISC0 = 0;
  TRISCbits.TRISC1 = 0;
   
   
  T1CONbits.TMR1ON = 1;  // Timer 1 on   
   
   
  __delay_ms(200);
   
  EECON2 = 0x55;
  EECON2 = 0xAA;
  RTCCFGbits.RTCEN = 0;  //Disable RTC
  RTCCFGbits.RTCWREN = 1;  //Enable writing to RTC timer
  RTCCFGbits.RTCPTR0 = 1;  //Set pointers before setting date
  RTCCFGbits.RTCPTR1 = 1;
   
   
   
  RTCCFGbits.RTCPTR0 = 1;  //Set pointers before setting date
  RTCCFGbits.RTCPTR1 = 1;
   
  IPR3bits.RTCCIP = 0;
  PIE3bits.RTCCIE = 1; //RTCC Interrupt enabled
  PIR3bits.RTCCIF = 0;
   
  RTCCFGbits.RTCEN = 1;  //Enable RTC
  RTCCFGbits.RTCWREN = 0;  //Disable writing to RTC timer
   
  RTCCAL = 0x00;
   
   

  while(1)
  {   
  tmr1L= TMR1L;
  PICRTCC_readDateTime(&d,&t);
   
  }
   
  return;
}



__interrupt(high_priority) void interrupts_highPriority(void)
{
   
   
  if (PIR4bits.CCP5IF == 1)
  {
  PIR4bits.CCP5IF = 0;   
  ccpInterrupt = 1;
   
  }  
   
  if (PIR1bits.TMR1IF == 1)
  {
  PIR1bits.TMR1IF = 0;
  tmrInterrupt = 1;
  }
   
   
}
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
It was the TIOSCEN bit!!!

Here is the corrected code. Thanks for everyone pitching in.

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;
unsigned char tmr1L;


void main(void) {
   
   
  OSCCONbits.IRCF0 = 1;
   OSCCONbits.IRCF1 = 1;   
   OSCCONbits.IRCF2 = 1;   
   
  T1CONbits.TMR1CS =  1;  // 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   
  T1CONbits.T1OSCEN = 1;  //<<<< This was missing
   
  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)
  {   
  tmr1L= TMR1L;   
  }
   
  return;
}



__interrupt(high_priority) void interrupts_highPriority(void)
{
   
   
  if (PIR4bits.CCP5IF == 1)
  {
  PIR4bits.CCP5IF = 0;   
  ccpInterrupt = 1;
   
  }  
   
  if (PIR1bits.TMR1IF == 1)
  {
  PIR1bits.TMR1IF = 0;
  tmrInterrupt = 1;
  }
   
   
}
 

nsaspook

Joined Aug 27, 2009
16,321
It was the TIOSCEN bit!!!

Here is the corrected code. Thanks for everyone pitching in.

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;
unsigned char tmr1L;


void main(void) {
  
  
  OSCCONbits.IRCF0 = 1;
   OSCCONbits.IRCF1 = 1;  
   OSCCONbits.IRCF2 = 1;  
  
  T1CONbits.TMR1CS =  1;  // 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  
  T1CONbits.T1OSCEN = 1;  //<<<< This was missing
  
  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)
  {  
  tmr1L= TMR1L;  
  }
  
  return;
}



__interrupt(high_priority) void interrupts_highPriority(void)
{
  
  
  if (PIR4bits.CCP5IF == 1)
  {
  PIR4bits.CCP5IF = 0;  
  ccpInterrupt = 1;
  
  } 
  
  if (PIR1bits.TMR1IF == 1)
  {
  PIR1bits.TMR1IF = 0;
  tmrInterrupt = 1;
  }
  
  
}
On to the next problem ...
 
Top