Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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:
• If an interrupt condition (interrupt flag bit and interrupt enable bits are set) occurs before the execution of a SLEEP instruction, the SLEEP instruction will complete as a NOP. Therefore, the WDT and WDT postscaler will not be cleared, the TO bit will not be set and PD bits will not be cleared.
• If the interrupt condition occurs during or after the execution of a SLEEP nstruction, the device will immediately wake-up from SLEEP. The SLEEP instruction will be completely executed before the wake-up. Therefore, the WDT and WDT postscaler will be cleared, the TO bit will be set and the PD bit will be cleared.
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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top