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 support@ccsinfo.com

problem with TIMER1 when using internal LP oscillator

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



Joined: 11 Feb 2008
Posts: 13

View user's profile Send private message

problem with TIMER1 when using internal LP oscillator
PostPosted: Mon Feb 11, 2008 1:38 am     Reply with quote

I'm trying to run a simple program on my PICKit 2 44-pin Demo Board
(PIC16F887) that keeps track of the overflows on TIMER1 when it is
clocked by the internal 32kHz crystal (see C code below for the CCS
complier). The problem I'm having is that I only seem to get two
TIMER1 interrupt overflows instead of one every two seconds like I
expect. Code works fine if I set up TIMER1 to run off the main
processor clock (8MHz).

#include <16F887.h>

#use delay(clock=8MHZ)

#FUSES HS,INTRC,NOWDT,NOPUT,NOMCLR,NOPROTECT,NOCPD,NOBROWNOUT,NOIESO,NOFCMEN,NOLVP

int count; //keep track of TIMER1 overflows

#int_TIMER1
void TIMER1_isr(void)
{
count++; //increment count
output_d(count); //display count on LEDs

}

void main()
{
setup_timer_1(T1_EXTERNAL|T1_CLK_OUT); //use low power 32kHz crystal
(i.e. T1CON=0x8F)
enable_interrupts(INT_TIMER1);
enable_interrupts(global);
count=0xFF; // turn on all LEDs to start
output_d(count);
while(1);
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 2:02 am     Reply with quote

Quote:
The problem I'm having is that I only seem to get two TIMER1 interrupt overflows

Can you explain this a little more ? You only get two interrupts, but
during what time period ?
Ttelmah
Guest







PostPosted: Mon Feb 11, 2008 4:10 am     Reply with quote

Ignoring anything else, you cannot have both HS, and INTRC fuses. INTRC, is for the internal RC oscillator, HS, implies an external crystal, or oscillator....

Best Wishes
bmoore



Joined: 11 Feb 2008
Posts: 13

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 11:42 am     Reply with quote

Quote:

Can you explain this a little more ? You only get two interrupts, but
during what time period ?


At intervals of two seconds (as near as I can tell), so within about four seconds from power up.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 11:55 am     Reply with quote

Quote:
when it is clocked by the internal 32kHz crystal

There is no internal 'crystal' in the PIC.

There is a 31 KHz internal oscillator. This is activated with the INTRC
or INTRC_IO fuses. This oscillator can run the entire PIC.

Timer1 has an additional oscillator circuit, just for Timer1. You can
connect an external 32.768 KHz watch crystal to its pins. These are
separate pins than the main crystal oscillator pins for the PIC.
This is a different oscillator than the one activated by the INTRC fuse.


Which one are you doing ?
bmoore



Joined: 11 Feb 2008
Posts: 13

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 12:24 pm     Reply with quote

Quote:

There is no internal 'crystal' in the PIC.

There is a 31 KHz internal oscillator. This is activated with the INTRC
or INTRC_IO fuses. This oscillator can run the entire PIC.

Timer1 has an additional oscillator circuit, just for Timer1. You can
connect an external 32.768 KHz watch crystal to its pins. These are
separate pins than the main crystal oscillator pins for the PIC.
This is a different oscillator than the one activated by the INTRC fuse.


Which one are you doing ?


Then I'm confused. This is from the PIC16F88x data sheet
Quote:

6.4 Timer1 Oscillator
A low-power 32.768 kHz crystal oscillator is built-in
between pins T1OSI (input) and T1OSO (amplifier
output). The oscillator is enabled by setting the
T1OSCEN control bit of the T1CON register. The
oscillator will continue to run during Sleep.
The Timer1 oscillator is identical to the LP oscillator.


Can I use the LP oscillator to clock TIMER1 while the clock the rest of the system at 8MHz or not?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 12:51 pm     Reply with quote

Look at the block diagrams for the main oscillators and for Timer1
in the data sheet.

Timer1 can be clocked by:
1. An external 32.768 KHz watch crystal, using the T1OSC.
2. An external clock input pin, T1CKI.
3. The main instruction cycle clock, Fosc/4.

There is no option to separately run Timer1 from the internal 31 KHz
oscillator, while running the main PIC at 8 MHz. So you can't do it.
bmoore



Joined: 11 Feb 2008
Posts: 13

View user's profile Send private message

PostPosted: Mon Feb 11, 2008 1:12 pm     Reply with quote

PCM programmer wrote:
Look at the block diagrams for the main oscillators and for Timer1
in the data sheet.

Timer1 can be clocked by:
1. An external 32.768 KHz watch crystal, using the T1OSC.
2. An external clock input pin, T1CKI.
3. The main instruction cycle clock, Fosc/4.

There is no option to separately run Timer1 from the internal 31 KHz
oscillator, while running the main PIC at 8 MHz. So you can't do it.


Okay, that makes sense. Thank you for taking the the time to clear that up for me.
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