Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Sleep / Wake Commands

Status
Not open for further replies.

Waterboy550

New Member
I'm using a PIC18F1320 and have programmed it to communicate with some sonar devices. Basically the PIC opens and closes ports to communicate with the different devices. I would like to put the PIC "to sleep" with a line of code from my computer to stop it from making the sensors take readings 24/7. I would then like to "wake up" the PIC with a line of code and have it perform its duties. Is this at all possible?
 
SLEEP will put the PIC to sleep, it will not execute instructions (halt) but can be woken up by peripherals like the WDT. So set the WDT for the longest delay possible, wakeup, add to some sort of software counter and go back to sleep till a few hours go by.
 
The max sleep time for my PIC is 2 minutes. So could I write some program that looks something like this.

main {
int timesSlept = 0;

while(1) {

if (timesSlept <= 60) {
timesSlept += 1;
Sleep(2 minutes); //or whatever the code would be
}

else {
DoStuff(); //Code to execute every 2 hours
timesSlept = 0;
}

}
}
 
i am trying to do something similar but am a newbi myself.

However my suggestion to you would be to add a serial interrupt which wakes up the PIC and if the serial data is read as "WAKE UP", the PIC wakes up. Now as said earlier, i dont know if this logic would work or not since the PIC would be asleep when the serial interrupt occurs and do not know if it would process the serial data.

In theory it should work. In practical, i have to try it my self.

I read somewhere that a PIC can be redeemed from sleep by Interrupts.

This way your PIC would become asynchronous which i my opinion would be better than WDT
 
Haxan, your suggestion would be the best in my situation as well. I'll try some things later this week and post my results here. Also if you find something that works for yourself, let me know. Thanks a lot to everyone trying to help solve this problem.
 
The PIC can be woken up by the watchdog timer, OR by enabled interrupts. It could be an External Interrupt pin, an I2C word, or a serial word, etc.

Code cannot Wake a processor at all, because it's not executing code; that being the point.

When the period you need to sleep exceeds the max WDT period, you just allow it to Wake, increment a counter, check that nothing needs to be done, and put it to Sleep again. 10 counts of the counter of a 2 min period is 20 min. This is very fast and in general the energy used is inconsequential.

Be aware the WDT period is not exactly precision, varies with lot and temp. It cannot be used as an accurate clock.

There are sometimes issues with Sleep mode. For example, the clock is not immediately stable so it often can't read a serial UART word properly.
 
Thank you Oznog, The WDT based wake up and checking has one problem (in my opinion), its synchronous. From what waterboy550 is looking for (to me) seems like an asynchronous call from computer. That is why i suggested serial interrupt based wake up.

Will it be possible to first send some start dummy bits and after like 10ms, send the actually WAKE UP serial command from computer (in order for the PIC to get stable from sleep)?
 
Status
Not open for further replies.

Latest threads

Back
Top