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

My 16f676 is sleepy

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



Joined: 26 Jan 2004
Posts: 15
Location: Kiruna, Sweden

View user's profile Send private message

My 16f676 is sleepy
PostPosted: Wed Mar 03, 2004 4:51 pm     Reply with quote

I am trying to get my pic to wake up from sleep by using overflow interrupt on timer1.
The interrupt works. Without the sleep command it works as it should, but if sleep is introduced it will not wake up. I have even moved into the dangerous field of assembler to be sure that the right bits in the concerned registers is set (the c code for each assambler part is also included but not compiled), but the pic is still sleepy.
Please, teach me how to do this right…
There must be a simple answer to this one (it usually is Rolling Eyes ).

Code:

#include <16F676.h>
#device adc=8
#use delay(clock=32000)
#fuses LP, NOWDT, BROWNOUT, PUT

int snooze=0, goon=0;

/************************/
#INT_TIMER1
timer1_isr()
{
   disable_interrupts(INT_TIMER1);
   snooze++;
   if(snooze==2)         //Set number of Snooze times
      {
         goon=1;
         snooze=0;
   output_high(PIN_C3);
   delay_ms(100);
   output_low(PIN_C3);
      }
     // enable_interrupts(INT_TIMER1);
      #asm
      MOVLW 0x81
      MOVWF 0x8c
      #endasm

   return goon;
}
/************************/
main()
{
/**** setup_timer_1(T1_INTERNAL | T1_DIV_BY_8); ****/
   #asm
   MOVLW 0x05
   MOVWF 0x10
   #endasm

/****      enable_interrupts(INT_TIMER1); ****/
         #asm
         MOVLW 0x81
         MOVWF 0x8c     //PIR1 REG.
         #endasm
/****      enable_interrupts(global); ****/
         #asm
         MOVLW 0xf0
         MOVWF 0x0b     //INTCON REG.
         #endasm

while(TRUE)
{
         set_timer1(0);
         while(goon==0)             //Nap period
         {
//            sleep();
         }
}
/************************************/


//Thanks


Last edited by Sandman on Fri Mar 05, 2004 8:08 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 03, 2004 7:15 pm     Reply with quote

What is the clock for Timer1 ? Is it the internal instruction
clock that is derived from the main crystal oscillator ?
If so, that clock is stopped during Sleep mode.
Sandman



Joined: 26 Jan 2004
Posts: 15
Location: Kiruna, Sweden

View user's profile Send private message

Can still not wake up the pic
PostPosted: Fri Mar 05, 2004 3:05 am     Reply with quote

I can still not get the pic (16f676) to wake up from sleep by using interrupt from timer1.
I use this code as "setup_timer1":

Code:

   #asm
   MOVLW 0x4F        //Value in T1CON
   MOVWF 0x10        //T1CON REG.
   #endasm


Timer is enabled, T1CON <0>
It is suppose to set timer1 to run on an external oscillator (using a 32768 Hz external crystal),T1CON<1>.
The counter is in asynchronous mode, T1CON<2>,
T10SCEN, T1CON<3> is set.
1 Prescale, T1CKS1:T1CKS0, T1CON<5:4>
The TMR1GE bit, T1CON<6> does not do any change as far as I have noticed.
What is wrong?!?!
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Fri Mar 05, 2004 8:13 am     Reply with quote

I seem to remember that you need some instructions after a sleep command before the end of the loop if the wakeup is done by interrupt. Whether this is compiler or chip related or I'm just wrong I don't know but try this:


while(TRUE)
{
set_timer1(0);
while(goon==0) //Nap period
{
sleep();
delay_cycles(2); // <--- may fix the problem
}
}

I think the same thing happened to me and this fixed it.

- SteveS
Sandman



Joined: 26 Jan 2004
Posts: 15
Location: Kiruna, Sweden

View user's profile Send private message

PostPosted: Fri Mar 05, 2004 12:12 pm     Reply with quote

Thanks for the advice, but it is hard to try since I cannot get timer1 to work at all if I set the T1CON<1>, ("TMR1CS") bit to use an external crystal oscillator. And I cannot use the internal during sleep. I believe this is the main problem, but I’ll keep your advice in mind when I get the timer woking.
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