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

Sleep mode and startup...

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








Sleep mode and startup...
PostPosted: Sat Sep 27, 2008 3:14 pm     Reply with quote

Hi

The PIC is a 2455.

I use timer1 as RTC no problem it's running.

When no key is pressed for 1 min. the PIC must go to sleep mode, it's working.

***

The last instruction before Sleep();

Code:

bit_set(OSCCON,0);
bit_clear(OSCCON,1);
bit_set(OSCCON,7);
SleepMode=true;   
Sleep();


Just for you to see what OSCCON is...
Code:
#byte OSCCON = 0xFD3


The only way I can get it out of sleep is a reset_cpu.
Code:

#INT_RB
void PortBChange(void)
{
 if (!input(_sw1) && (SleepMode)) { reset_cpu(); }
}


It's not nice!

The Timer1 my RTC clock must run when PIC is sleeping I think it's working.

Is there another way? Because when resetting all the user data is cleared because the program counter is at powered first time.

[/quote]
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sat Sep 27, 2008 4:54 pm     Reply with quote

Quote:
The Timer1 my RTC clock must run when PIC is sleeping I think it's working.

No. Cause all oscillators are stopped in sleep mode, timer1 is not working. SEC_IDLE rather than SLEEP would be an appropriate mode. In SLEEP, WDT is the only available option for a timed wakeup.

You didn't exactly tell, what you are trying to achieve, but I guess you want to use Timer1 for wakeup.

Regards,
Frank
Guest








PostPosted: Sun Sep 28, 2008 12:13 am     Reply with quote

Hi

Hmmm. Are there any other hints for getting out of the sleep.


Before sleeping I set. This is Timer1 run but main "cpu" does not.
Code:
bit_set(OSCCON,0);
bit_clear(OSCCON,1);
bit_set(OSCCON,7);



After 1 min. get to sleep.
When something change on port B and in sleep reset the cpu.
This is working.


The q is: How to still run Timer1 and wake up the pic at the same point as when it go to sleep??
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Sun Sep 28, 2008 2:17 am     Reply with quote

I didn't realize, that you already set OSCON to SEC_IDLE instead of SLEEP. Thus Timer1 should continue to work and Timer1 or any other enabled interrupt should be wakeup the processor, it's then continuing with the next instruction after sleep. I don't know why your processor is reset, but the reset cause may be checked.
Ttelmah
Guest







PostPosted: Sun Sep 28, 2008 2:28 am     Reply with quote

First, the compiler can set the OSCCON bit for you, without using direct bit accesses. Look at 'setup_oscillator'.
Now, the obvious 'not shown' thing, is the interrupt setup. To wake from sleep, the timer1 interrupt, must be enabled.
Have a look at the thread here a few days ago, about how to wake from sleep on the RDA interrupt. I list in this, the settings that are needed (obviously change to use the tmer interrupt).
It does work, when everything is setup right.

Best Wishes
Guest








PostPosted: Sun Sep 28, 2008 5:05 am     Reply with quote

Sorry, for explaining what I want one more time.

I use Timer1 as RTC clocked as in Datasheet 2455 section 16.6 it’s running fine. And it must be running when in SLEEP mode. Furthermore the Timer1_int must be working.

When there are no action on the keyboard the 2455 is going to SLEEP. Wakeup I use int change on port B. But the running Timer1 int is waking the 2455 every 1 sec.

I don’t understand the function of using RTC together with SLEEP, because the int from Timer1 will wake the 2455 every 1 sec.
Guest








PostPosted: Sun Sep 28, 2008 9:06 am     Reply with quote

Fixed:-)

My sleep mode is SEC_IDLE, the PIC is then cycling on Timer1 therefore my RTC is still working.
The Timer1 int will bring the PIC out from sleep every 1sec. therefore the loop while (SleepMode)... and the global var SleepMode.

But now project is working:-)

Thanks for the help in the forum.


Code:
#INT_RB
void PortBChange(void)
{
 if (!input(_sw1) && (SleepMode)) //only _sw1 down and in sleepmode!
 {
  SleepMode = false;
 }
}



Code:
//mesured 140uA in sleep mode, and 18mA in runningmode...
void Go_To_Sleep(void){
  //set all pin to minimal load:-)
  output_float(_led_r);
  output_float(_led_g);
  output_float(DS18B20_IO);
 
  output_high(nok_cs); //disable the display
  output_float(nok_dc);
  output_float(nok_res);
  output_float(nok_sclk);
  output_float(nok_sda);
 
  delay_ms(10); //just in case
  SleepMode=true;
 
  bit_set(OSCCON,7); //enter SEC_IDLE mode
  bit_clear(OSCCON,1);//-
  bit_set(OSCCON,0);//-
 
  while (SleepMode) //my global var for starting it all up again:-)
  {
    Sleep();
    #asm
     nop
     nop
    #endasm
  }
#asm
 nop
 nop
#endasm
 
 //restore to normal
 setup_oscillator(OSC_8MHZ|OSC_INTRC);
 delay_ms(10);//wait i know it long but...
 //from here we are running in not sleeping mode...
}
Ttelmah
Guest







PostPosted: Sun Sep 28, 2008 9:08 am     Reply with quote

delay_cycles(1); Gives you a nop (you only need one). Generally, if using a compiler, let the compiler do the work. Only use assembler, and direct accesses, if there is a problem with the compiler.

Best Wishes
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