# Timer1 not working with external crystal (PIC16F628A)

I am unable to get the external 32.768kHz crystal (on RB6 and RB7) / timer1 to function (PIC16F628A / Mikro C). The crystal never starts. The same circuit has been reproduced twice (with short crystal connections, correct value capacitors etc) and the issue is the same.

The code I currently have working (running on the internal 4MHz), changing TMR1CS to 1 results in no timer function, no crsytal start.

TMR1L = 0;
TMR1H = 0;

T1CON.T1CKPS0 = 1;        // Set Timer 1 prescaler
T1CON.T1CKPS1 = 1;        // TICKPS0 & TICKPS1 set to 1 (for /8 prescale), not 0
//T1CON.TMR1CS  = 1;
T1CON.TMR1CS  = 0;        //Use internal OSC for testing
T1CON.T1OSCEN = 1;
//T1CON = 0b00001111;

CCP1CON = 0b00001011;            // Timer 1 compare mode, Special Event mode
CCPR1L = (16383 & 0x00FF);       // Preset compare register low/high bytes
CCPR1H = (16383 & 0xFF00)>>8;


This, not working

 TMR1L = 0;
TMR1H = 0x80;

T1CON.T1CKPS0 = 0;        // Set Timer 1 prescaler
T1CON.T1CKPS1 = 0;        // RJ TICKPS0 & TICKPS1 set to 1 (for /8 prescale), not 0
T1CON.TMR1CS  = 1;
//T1CON.TMR1CS  = 0;      //RJ Use internal OSC for testing
T1CON.T1OSCEN = 1;
//T1CON = 0b00001111;

CCP1CON = 0b00001011;            // Timer 1 compare mode, Special Event mode
CCPR1L = (16383 & 0x00FF);       // Preset compare register low/high bytes
CCPR1H = (16383 & 0xFF00)>>8;


Does anyone have a tested / working scenario from which they can provide the precise settings for T1CON and the config bits? I have followed the Microchip timer1 sheet to the letter and this is still not working.

Regards Active

• Did you experiment with a series resistor? Do you have a frequency meter or oscilloscope to confirm the oscillator is running? Also make sure you read the errata sheet. – imqqmi May 20 '17 at 14:54
• Hi imqqmi, yes, series and parallel resistors tried, oscilloscope confirms no oscillation, errata sheet read (10 years plus in electronics). Either this function has never worked in this PIC or there is something missing from one of the datasheets. – Active May 20 '17 at 16:17
• How are your fuses set? – Scott Seidman Jun 14 '17 at 14:58

Ok, I've build the schematic with a PIC16F628 non A, and after several crystals I found a few that worked. Out of 9 I own, only 6 worked. Resistor values tried ranging from 10K to 1M ohm, capacitors from 10p to 47p, didn't make a difference. It either just works or it doesn't. Some crystals are new, some were salvaged. Some new ones didn't work either.

I use xc8 v1.40. I used an external osc of 10MHz. The pickit 3 programmer has a hard time programming the PIC16F628 when an oscillator is connected. I have no problems with more advanced PIC16F1827 and PIC16F1937.

This is the Timer1 configuration I used succesfully:

T1CONbits.T1CKPS = 0;        // Set Timer 1 prescaler

T1CONbits.TMR1CS  = 1;
//T1CON.TMR1CS  = 0;      //RJ Use internal OSC for testing
T1CONbits.T1OSCEN = 1;
T1CONbits.nT1SYNC = 1;
T1CONbits.TMR1ON = 1;


I didn't check if the timer gets incremented, but I assume if the clock signal is visible on the oscilloscope as measured on pin 15, it should work. Let me know if you'd like me to test this. I'll have to hook up a serial port to read out the values though.

I also read in Microchip errata documentation that PIC oscillator circuits can be a bit picky on the crystals. This seems to be my experience as well. I even saw a PIC32 "defeatered" as to supporting secondary 32KHz crystals. It may be more reliable to build your own oscillator circuit and feed in into the Timer1 T1OSI pin.

My advise: buy some more crystals and from different sources, brands and batches.

A PIC has some "Configuration Bits" (i.e., "fuses"), and one of the thing these fuses do is configure the PIC to use the appropriate source for the clock. If you haven't changed these in the switch to the external crystal, then this is likely your problem.

I don't use your compiler, but you should search for how to set these bits with the tools you have.