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

PIC12F683 wake up from sleep using Timer1 and INTOSC

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



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

PIC12F683 wake up from sleep using Timer1 and INTOSC
PostPosted: Sat Aug 23, 2008 2:07 pm     Reply with quote

Hello forum,

I would like to be able to wake up my PIC12F683 using Timer1 interrupt. I'm using the internal oscillator. It seems to me that Timer1 will only keep running during sleep if LP oscillator is enabled, and as far as I know, thats when running 31kHz internal osc. The LP will automatically be enabled when Power-Up-Timer is enabled.

The datasheet says the following:

Quote:
6.7 Timer1 Operation During Sleep
Timer1 can only operate during Sleep when setup in
Asynchronous Counter mode. In this mode, an external
crystal or clock source can be used to increment the
counter.

Note the word "can". I'm not sure if this means that Timer1 NEEDS an external oscillator.


This is my code:
Code:
#include <12F683.h>
#device adc=8

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NOCPD                    //No EE protection
#FUSES NOPROTECT                //Code not protected from reading
#FUSES NOMCLR                   //Master Clear pin used for I/O
#FUSES PUT                      //Power Up Timer
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOIESO                   //Internal External Switch Over mode disabled
#FUSES NOFCMEN                  //Fail-safe clock monitor disabled

#int_TIMER1
void  TIMER1_isr(void)
{
   GP2 = !GP2; // Toggle LED
}

void main()
{
   setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
   setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
   setup_oscillator(OSC_31KHZ);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(GLOBAL);

   TRISIO = 0b00000000;    // Configure IO pin directions (all output)
   GPIO   = 0b00000000;    // Set default output pin states

   sleep();
}

The PIC will not blink the LED. It works if I use a "while(1);" instead of the sleep statement so interrupts are working.


What am I missing?


Best regards,
Futterama
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Aug 23, 2008 3:23 pm     Reply with quote

Do you have an external 32.768KHz watch crystal (and capacitors)
connected to the Timer1 oscillator pins ? You need one.
The internal oscillators (LF and HF) don't run during sleep.

This post has sample code which shows how to wake up from sleep
with the Timer1 interrupt:
http://www.ccsinfo.com/forum/viewtopic.php?t=28158&start=8
Futterama



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

PostPosted: Sat Aug 23, 2008 3:46 pm     Reply with quote

No, I don't have a crystal. I'm trying to avoid that and only use the internal oscillator.

Well, I read your thread before posting and I searched a bit, and I found something about using the WDT. I have never used the WDT before, so I'll have to look into that and forget about the timer.

But in the datasheet it says that the WDT uses LFINTOSC so if no internal oscillator is running during sleep, I can't use that either?
Futterama



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

PostPosted: Sat Aug 23, 2008 4:03 pm     Reply with quote

Ahh, the datasheet says:

Quote:
12.7 Power-Down Mode (Sleep)
The Power-down mode is entered by executing a
SLEEP instruction.
If the Watchdog Timer is enabled:
• WDT will be cleared but keeps running.


So it should be possible to use the WDT for interrupting a sleep.

But the datasheet also says the following:

Quote:
...Other peripherals cannot generate interrupts, since
during Sleep, no on-chip clocks are present.

With no on-chip clock, how can the WDT keep running?
Futterama



Joined: 17 Oct 2005
Posts: 98

View user's profile Send private message

PostPosted: Sat Aug 23, 2008 4:27 pm     Reply with quote

Hi,

I got the PIC to wake up using the WDT. I used PIC12F683 feature of enable/disable the WDT in software in my test.
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