PIC18F452 sleep problem

Status
Not open for further replies.

Munib

Advanced Member level 4
Joined
Jun 11, 2004
Messages
114
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Activity points
1,129
c18 sleep

I want to use sleep mode to save power consumption of my mcu PIC18F452

I am using a seperate 32KHz oscillator for timer1.what i am doing is when i want to put my mcu to sleep mode i switch the oscillator to timer1 oscilltor and then put my mcu in sleep mode using sleep(); function

what i expect is that after the overflow of timer1 an interrupt will be generated and the mcu will come out of sleep mode automatically.

But my mcu once entered in sleep mode is not coming out of this state.

what is the problem any suggestion?
is there problem with the function sleep();
I am using Microchips C18 compiler
 

microchip c18 sleep

Hi Munib,

You are probably not setting the TMR1 Flag corectly. You have to set this flags so it will wake up from sleep by timer 1:
So first you have to do this in your code.
Code:
TMR1IF = 0  // Set flag to 0 clear on the first time
TMR1IE = 1; // TMR1 Interup inable
Then before you do the sleep function you have to be sure that TMR1IF = 0 and then run the TMR1ON = 1;

I always comment (// ) the sleep function and uses a break point to see that the timer runs ok and the flag TMR1IF works. If that is fine, i uncomment the sleep and see if it works.
Do not forget to clear the TMR1IF after you wake up from sleep! it wont clear by itself.

Good luck.
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…