Can't get T1 to run on external clock source

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
I don't recall ever using an external clock source for T1. I guess I am trying it for the first time and can't seem to get it to work. My chip is the pic18445k22.

I have everything hooked up as in the schematic below. It should be noted that I am in the bread board phase and that the crystal and caps are on a small board which I have designed and connected by jumpers to the breadboard. I don't expect an accurate clock, I just want it to work.

I am using the internal RC oscillator for my main oscillator. I assume the T1 oscillator will still work in this configuration?

I am configuring the timer as follows:

#define TMR1HVAL 0x80
#define TMR1LVAL 0x00

// Timer 1
TMR1H = TMR1HVAL; // Set Timer 1 Overflow Hi
TMR1L = TMR1LVAL; // Set Timer 1 Overflow Lo
T1CON = 0x3; // Set external osc and enable Timer 1
PIR1bits.TMR1IF = 0; // Clear Timer 1 interrupt flag
PIE1bits.TMR1IE = 1; // Enable Time 1 interrupt

Am I missing anything else? Is there a configuration bit I need to set? I checked the datasheet and it does not seem to mention anything else.

My interrupt routine never gets called but if I change to internal clock cycle for T1 then the interrupt routine gets called as expected.

How can I diagnose that the oscillator is running? If I place my scope on pin 2, I see no transitions. If I place it on pin 2, I see transitions while the chip is being programmed which I find kind of strange since that pin is not MCLR, PGC or PGD.
upload_2017-1-29_17-9-47.png
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Here is a schematic of the crystal breakout board I am using.
upload_2017-1-29_17-42-56.png
Both caps are 27pf. I plan to change out Y1 but before I do, I want to make sure I am missing nothing else.
 

AlbertHall

Joined Jun 4, 2014
12,343
What frequency crystal do you have on T1?
How long are the connections between the PIC and the crystal and between the capacitors and ground?
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Frequency good, wire length very bad. Get that down to 1 inch or less.
How does my code look for configuring the timer?

Will those distances cause it to not work at all? All I care is t works right now. Don't care about accuracy.

Do I even need load caps to get it to work? If not I can reduce my distance to a fraction of an inch.


What about the ground distance in board design? In my board design (yet to be built) the runs are a few inches for the ground to where the caps and crystal is fractions of an inch from the chip.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
I dramatically reduced the distance from the crystal to the pins. Now less than an inch. My ground for the caps is now only about two inches to mcu ground pin. It is still not working.

And that brings up a question. What ground distance should be short? It it just to cap to the chip's ground or the supply ground? If chip's ground I think I might be good on my board design.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
and I just dropped my two remaining crystals looking at the bag. Wonderful. They are so tiny. Tt is like trying to find a contact lens. :mad:
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Found one at least.

I also tried a 2mhz resonator I have on hand. Leads are very short. Clock is still not running. It has to be something in my configuration.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
I configured my code to run on the external resonator and it is running so I know the resonator is good and my connections are good but the timer is still not running.
 

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
I would still like to know what the transitions are on RA4 when I program the chip. That could be very dangerous if this is an output. I see nothing in the datasheet mentioning this.

Other than to write a program to have an interrupt change the output of one of my pins, is there any other way to accurately measure my T1 clock / timer?
 

RichardO

Joined May 4, 2013
2,270
Watch crystals are made to run at very low power. You may be damaging your crystals. You _must_ have a high value resistor between the output of the oscillator and the crystal/cap. This resistor is typically 300k to 1meg ohm.

The old RCA data book I have attached shows has how to calculate the correct value. See page 57 in the data book for crystal oscillators.
 

Attachments

Thread Starter

spinnaker

Joined Oct 29, 2009
7,830
Are you not using the 32Khz Xtal to clock T1?
Are you using it with a T1 capture for the photo detector?
Max.

I am using is as a time base for T1. I am not using CCP. Seemed easier to me to count the interrupts per second.

Crystal connected or not I still see transitions on RA4.

And I still want to know how to test the actual speed of my timer.
 
Top