"SLEEP" Mode repetition

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hi All!

  I have a PIC16f877a. I want to work with the device mainly in sleep,
wake on RB change, do some stuff (say led blink) and go back to sleep.

This code works fine if i put the blink code in the ISR. How do i use
this code in the main program in C? I tried :-
main()
{
// initialization of interrupts etc...

s1 :asm("SLEEP");
asm("NOP");
RE0=0x1;
delay(); a fn. for 1s delay
RE0=0;
goto s1;
}

The code works one the first run. Then the device doesnt go back to
sleep i.e it keeps blinkin LED after 1st interrupt (it should blink
just once right?)

Devyn

Re: "SLEEP" Mode repetition

Quoted text here. Click to load it

I think you need to cancel the RB change interrupt by reading PORT B
in response to the interrupt.


-Robert Scott
 Ypsilanti, Michigan
(Reply through this forum, not by direct e-mail to me, as automatic reply
address is fake.)

Re: "SLEEP" Mode repetition
Are you sure that your PIC is not resetting? It looks like if you have
your watchdog enabled, you don't refresh it in that loop. Then you'll
see what looks like a blink, but you're actually resetting each time.

And why do you need to go to sleep? is it a battery powered
application? It looks like you'll be burning some cpu cycles, and thus
battery life, in your software delay loop. You might want to set up
for a timer interrupt and wake up after a timer interrupt to update
your LED. (THis might not work, since i haven't done PIC sleeps for a
few years.



snipped-for-privacy@yahoo.com (Devyn) wrote in message
Quoted text here. Click to load it

Re: "SLEEP" Mode repetition
snipped-for-privacy@yahoo.com (Mike V.) wrote in message
Quoted text here. Click to load it

 I have disabled WDT in the configuration

Quoted text here. Click to load it

 Yes, my app. is battery powered. Actually, its a lot more complicated
than the LED blink. That was just a test code i'd written to present
the problem. In reallity, on wake up fro sleep, the app updates a
count, does some ADC stuff and some port stuff. I'm not enclosing
details, for even the simple LED doesnt blink..

In the ISR, the code is

if(RB4==1)
 {
   GIE=1;
   RBIF=0;
 }

Maybe the device is resetting. Even if it is, shouldnt it go back to
sleep, when it encounters the SLEEP instrn.?

Devyn

Re: "SLEEP" Mode repetition


Quoted text here. Click to load it

Did you read Robert Scott's suggestion?  How about section 5.2 of the
datasheet?  To end the mismatch condition, you have to read the whole
port, otherwise it wake right back up due to the previous change.

One more thing: enabling GIE in the ISR is likely to cause you major
problems unless your ISR is reentrant, especially since the RBIF flag is
still set when you enable GIE.  RETFIE is the way to set the GIE bit.


Site Timeline