View previous topic :: View next topic |
Author |
Message |
sang
Joined: 29 Nov 2005 Posts: 4
|
PIC Reset on Sleep |
Posted: Tue Nov 29, 2005 7:58 pm |
|
|
Hi All,
I am using PIC18F67J10 to develop a project. I need to put the PIC to sleep but it seems that the MCU resets everytime I put it to sleep. The specs states
"The power-managed Sleep mode is identical to the legacy
Sleep mode offered in all other PICmicro devices.
It is entered by clearing the IDLEN bit (the default state
on device Reset) and executing the SLEEP instruction."
Using any of the IDLE mode works perfectly. restart_cause() shows normal powerup.
I wrote a small demo code below. The printf statement was printing non stop.
#byte OSCCON = 0x0FD3
#bit IDLEN = OSCCON.7
Code: | printf("Start Init\r\n");
//SET MCU TO SLEEP
IDLEN = 0;
while(1)
{
sleep();
}
|
The settings are
#fuses HS,NOWDT
#use delay(clock=32000000)
#use RS232 (BAUD=19200, XMIT=PIN_C6, RCV=PIN_C7, ERRORS)
Thanks,
SA |
|
|
Guest
|
|
Posted: Wed Nov 30, 2005 9:35 am |
|
|
Try just putting it in a loop, and see if the same happens. It is worth 'ruling out' something like noise on the reset line.
Though it should not cause this, add a 'nop' (delay_cycles(1)) after the sleep, since the instruction following the sleep is 'pre-fetched', and in a more complex enviroment, this can cause a problem.
The fact that you are seeing normal 'power up' indication from the restart_cause function, suggests that you may be seeing a problem in the hardware.
I'd try setting 'NOFCMEN' in the fuses.
Best Wishes |
|
|
sang
Joined: 29 Nov 2005 Posts: 4
|
|
Posted: Wed Nov 30, 2005 7:06 pm |
|
|
Thanks for the suggestion. I've tried them out but the problem remain unsolve. setting NOFCMEN in the fuses and adding NOP doesn't solve the problem.
What do you mean by "adding it in a loop"? the sleep() instruction is already in a while loop. I will be checking the hardware again but it seems strange that this only happen when IDLEN bit is set to 0. Setting it to 1 do not produce the same effect.
Regrds,
SA |
|
|
Ttelmah Guest
|
|
Posted: Thu Dec 01, 2005 3:48 am |
|
|
I mean, don't put the processor to sleep, and see what happens. So just use:
Code: |
while(true) {
delay_cycles(1);
}
|
If it still keeps printing, you have proved that the problem is not with the sleep, but with the hardware.
Best Wishes |
|
|
sang
Joined: 29 Nov 2005 Posts: 4
|
|
Posted: Thu Dec 01, 2005 3:56 am |
|
|
Without the sleep instruction, it doestn't loop. Everything works fine. In fact sleep work fine if IDLEN = 1. I guess I will just settle with sleeping in idle mode.
Thanks.
SA |
|
|
|