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

MCLR from sleep...?

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



Joined: 17 Dec 2005
Posts: 58

View user's profile Send private message

MCLR from sleep...?
PostPosted: Thu Nov 22, 2007 9:01 pm     Reply with quote

I am using a PIC18LF8722, once the PIC has started up I put it immediately to sleep. I have a push button which can wake up the PIC to execute the code following the sleep(); command. ( I can post code if need be).

Anyways upon coming out of sleep, the PIC resets and the reset cause is MCLR from sleep.

Any idea what could be causing this?

thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 22, 2007 9:09 pm     Reply with quote

Quote:

I have a push button which can wake up the PIC to execute the code
following the sleep() command. Upon coming out of sleep, the PIC
resets and the reset cause is MCLR from sleep.

What pin on the PIC is the pushbutton connected to ?
ktallevi



Joined: 17 Dec 2005
Posts: 58

View user's profile Send private message

PostPosted: Thu Nov 22, 2007 10:31 pm     Reply with quote

the push button (which is hardware debounced) is connected to RB0/INT0.

I have used push button interrupts in previous projects with no issues, with this particular one I am getting those odd MCLR from sleep resets.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Nov 22, 2007 10:50 pm     Reply with quote

Post a short test program that demonstrates the problem. Be sure to
post all #include, #fuses, and #use statements. The program should be
compilable. Also post your compiler version.
Ttelmah
Guest







PostPosted: Fri Nov 23, 2007 6:08 am     Reply with quote

It is worth looking at the data sheet.
MCLR from sleep (CCS definition), is code '11'.
Now, the corresponds to a watchdog timeout, _not_ occurring, a Power on reset _not_ occurring, and a brownout reset _not_ occuring. There is no actual detection bit for 'MCLR'. So what it suggests, is that you are arriving at the start of the code, for no normal reason.
The obvious thought, is that you have got the GIE bit set, and no interrupt handler present for this, which could give this sort of odd behaviour.
To use an interrupt to 'wake up', but not cause an interrupt handler to be called, you need to have the interrupt itself enabled, but the GIE (global interrupt enable) disabled. The sequence is:

disable_interrupts(GLOBAL); //If other interrupts are being used
clear_interrupts(INT_EXT); //To ensure any _past_ triggers are ignored
enable_interupts(INT_EXT);
sleep();
delay_cycles(1);
disable_interrupts(INT_EXT); //disable this _before_ re-enabling the GIE
enable_interrupts(GLOBAL); //Re-enable is other interrupts are being used

The 'delay', is optional, but often worth having. The instruction _after_ the sleep, is 'prefetched', when the sleep executes, and in some cases, this can give unexpected results (if this is a test for example). Hence a single 'NOP' (which iswhat a single cycle delay generates), avoids 'oddities' from this.

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