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

Use Timer1 to wake up from sleep

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



Joined: 05 Oct 2007
Posts: 8

View user's profile Send private message Visit poster's website

Use Timer1 to wake up from sleep
PostPosted: Wed Jan 30, 2008 10:39 pm     Reply with quote

I would like to go to sleep and then wake up via Timer1 on a 16F887:

6.4Timer1 Oscillator

A low-power 32.768kHz 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.
The user must provide a software time delay to ensure
Timer1 gate source is software configurable to be the
proper oscillator start-up.

TRISC0 and TRISC1 bits are set when the Timer1
oscillator is enabled. RC0 and RC1 bits read as ‘0’ and
TRISC0 and TRISC1 bits read as ‘1’.

6.8Timer1 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. To set up the timer to wake the device:

• TMR1ON bit of the T1CON register must be set
• TMR1IE bit of the PIE1 register must be set
• PEIE bit of the INTCON register must be set

The device will wake-up on an overflow and execute
the next instruction. If the GIE bit of the INTCON
register is set, the device will call the Interrupt Service

From what I understand is that Timer1 can cause a wake up from sleep when using an external oscillator. I'm using an internal oscillator, but it seems you can use the 32kHz in sleep mode?

This is what I have:

Code:
   Value = 0;
   while (TRUE) {
      fprintf(PC,"Hello!\n\r");
      Value++;
      if (Value == 5) {
        bit_set(PIE1,0);
        bit_set(IntCon,6);
        T1CON = 0b00111111;
        clear_interrupt(INT_TIMER1);
        enable_interrupts(INT_TIMER1);
        fprintf(PC,"Goodbye!\n\r");
        sleep();
        delay_cycles(1);
        Value = 0;
     }
     delay_ms(250);
   }


It prints 4 times Hello! and one Goodbye! but it never returns from sleep... what am I missing?

Thanks in advance,

D2.
Dutch2



Joined: 05 Oct 2007
Posts: 8

View user's profile Send private message Visit poster's website

PostPosted: Wed Jan 30, 2008 10:42 pm     Reply with quote

Forgot this part:

#byte PIE1 = 0x8C
#byte T1CON = 0x10
#byte IntCon = 0x0B

D2.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 30, 2008 11:24 pm     Reply with quote

Quote:

I would like to go to sleep and then wake up via Timer1 on a 16F887.

See this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=28158&start=8
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