CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Timer1 (sort of) double clocking itself with external source

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
icefield



Joined: 09 May 2005
Posts: 20
Location: Canada

View user's profile Send private message

Timer1 (sort of) double clocking itself with external source
PostPosted: Tue May 10, 2005 8:00 am     Reply with quote

I'm trying to use Timer1 on an 18F6720 with an external clock source of 32.768kHz (sourced from a DS1306 RTC) for two purposes: (1) as a general timer and (2) as an external CPU clock for clock-switching (saving power).

For (1), things work nicely. I issue a SETUP_TIMER_1(T1_EXTERNAL | T1_DIV_BY_1), with the external 32kHz signal feeding into T1OSO. I have an ISR executing every second that samples the T1 clock and I get two numbers like 3423 and 62113 alternating. Rock steady. T1 overflows every two seconds, as expected.

(ASIDE: the external signal generating the 1Hz interrupt is derived from the same 32.768kHz signal being fed to T1OSO).

Splendid.

So, we move to (2). Clock switching on the 18F6720 requires that the T1 oscillator be enabled. It is clearly designed for a crystal, not an external clock source. So, with the T1 oscillator enabled via SETUP_TIMER_1(T1_EXTERNAL | T1_CLK_OUT | T1_DIV_BY_1), I can no longer use T1OSO as the external clock input and instead put it on T1OSI (at least, I think this is right - T1OSO appears to be driven by the oscillator's inverter). Since my source is a solid 5V square wave, I run it through a 100k resistor into T1OSI to avoid overdriving the clock circuit.

Clock switching works fine, although it's hard to judge what the true CPU clock speed is.

Now, however, the T1 clock is counting at something like 64000Hz. Quite consistent, but not quite double the frequency. The input to T1OSI is steady at 32kHz, with a bit of rounding of the shoulders. If I short T1OSI to ground, the clock stops counting. If I short or decrease the 100k resistor, there is no change in this "double" clocking.

Unfortunately, the T1OSO pin is now broken off so I cannot see the signal there.

Does anyone have any ideas as to what is happening? Anyone with experience driving T1 with an external source for clock switching purposes?

Cheers,
Erik
icefield



Joined: 09 May 2005
Posts: 20
Location: Canada

View user's profile Send private message

PostPosted: Tue May 10, 2005 8:03 am     Reply with quote

I've been a bit loose with my kHz. The external source is running at 32.768kHz. The "double" clocked T1 counter is running at about 64.0kHz. In other words, there is a significant deviation from running at double speed.

Cheers,
Erik
icefield



Joined: 09 May 2005
Posts: 20
Location: Canada

View user's profile Send private message

PostPosted: Tue May 10, 2005 8:12 am     Reply with quote

More news.

Managed to probe T1OSO. Whatever load the 10x oscilloscope probe put on the pin brought things to normal (i.e., T1 counts at 32.768kHz). The signal looks like a linear ramp up from ground to about 1V for half a period, then sharp drop to ground for other half.

So, this is turning into a hardware problem. Nevertheless, any advice from those who have gone before would be appreciated.

I'm trying to avoid putting a second 32kHz crystal into the circuit.

Cheers,
Erik
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group