All About Circuits Forum  

Go Back   All About Circuits Forum > Software, Microcomputing, and Communications Forums > Embedded Systems and Microcontrollers

Notices

Embedded Systems and Microcontrollers Discussion forum for projects and working with embedded systems and microcontrollers (FPGAs, PICs, AVRs). Get help with hardware issues and embedded programming.

Reply   Post New Thread
 
Thread Tools Display Modes
  #1  
Old 05-15-2012, 03:46 PM
ecka333 ecka333 is offline
Member
 
Join Date: Oct 2009
Posts: 74
Default Interrupt+Sleep

I am using PIC18F452 microcontroller. I wrote program, which basically looks like this:

void interrupt()
{
A-time counting...
if(Blackout==1){asm sleep; asm nop;}
B-some other commands
}

void main{....}

There A and B are command lines. So, i am using Timer1 module, which owerflows every 0,25seconds. Then program counter goes to interrupt routine. Here time counting routines are executed (A commands). Next program checks if mains voltage is present. If voltage is present, B commands are executed. After this main() routine is executed. But if blackout is occured, system goes to sleep after A line execution. After 0,25sec timer1 gives interrupt, microcontroller is waked-up.
So my question is: after wake-up interrupt routine will be executed from the begining (A command line) or B line will be executed?
Reply With Quote
  #2  
Old 05-19-2012, 09:24 AM
ecka333 ecka333 is offline
Member
 
Join Date: Oct 2009
Posts: 74
Default

Nobody knows the answer?
Reply With Quote
  #3  
Old 05-19-2012, 10:26 AM
ErnieM's Avatar
ErnieM ErnieM is online now
Senior Member
 
Join Date: Apr 2011
Location: Lon Guyland, Noo Yawk
Posts: 5,315
Default

Wow, you waited almost a whole 6 hours to bump your thread. Your question could not be any more obfuscated.

Look at your program.

Find the line where you perform SLEEP.

Note the code line that is immediately following the SLEEP line.

There, that is what is executed after your uP wakes.
__________________
“Freedom is never more than one generation away from extinction. We didn’t pass it to our children in the bloodstream. It must be fought for, protected, and handed on for them to do the same, or one day we will spend our sunset years telling our children and our children’s children what it was once like in the United States where men were free.”
Reply With Quote
  #4  
Old 05-19-2012, 11:02 AM
Markd77's Avatar
Markd77 Markd77 is offline
Senior Member
 
Join Date: Sep 2009
Location: Birmingham
Posts: 2,790
Blog Entries: 1
Default

It depends if interrupts are enabled or not. Read section 19.3 of the datasheet. It will execute the instruction after sleep, but will then jump to the interrupt if enabled, otherwise it will just continue.
I don't imagine that putting the sleep command inside the interrupt is a good idea. Interrupts are disabled within the interrupt.
Unless you have a crystal or external clock connected to the timer1 pins, it will not be running so it will not wake from sleep.
Reply With Quote
  #5  
Old 05-22-2012, 07:59 PM
ecka333 ecka333 is offline
Member
 
Join Date: Oct 2009
Posts: 74
Default

I am using Timer1 interrupts to wake-up uController from the sleep, because this module continues to function even during sleep. My goal is to reduce number of code strokes which microcontroller will execute when it is not sleeping. Code after sleep instruction is not very important, it is better not to execute it if blackout occured. So when microcontroller will wake up from the sleep, timer1 flag interrupt flag will be set. According to the datasheet microcontroller must execute code after sleep instruction. But if interrupt flag will be set, maybe microcontroller will start execute interrupt() routine frof the begining?
Reply With Quote
  #6  
Old 05-22-2012, 08:25 PM
Markd77's Avatar
Markd77 Markd77 is offline
Senior Member
 
Join Date: Sep 2009
Location: Birmingham
Posts: 2,790
Blog Entries: 1
Default

Quote:
Originally Posted by ecka333 View Post
I am using Timer1 interrupts to wake-up uController from the sleep, because this module continues to function even during sleep. My goal is to reduce number of code strokes which microcontroller will execute when it is not sleeping. Code after sleep instruction is not very important, it is better not to execute it if blackout occured. So when microcontroller will wake up from the sleep, timer1 flag interrupt flag will be set. According to the datasheet microcontroller must execute code after sleep instruction. But if interrupt flag will be set, maybe microcontroller will start execute interrupt() routine frof the begining?
I think you will find Timer1 will stop along with the main instruction clock in sleep unless Timer1 uses an external clock or crystal.
What will happen if it ever wakes up is that the Timer1 interrupt flag will be set, but all interrupts are turned off within the interrupt. It will execute all remaining instructions in interrupt(), then immediately re-enter at the start of the interrupt because the Timer1 interrupt flag is set.
It's a much better idea to exit the interrupt before going to sleep.
Reply With Quote
  #7  
Old 05-22-2012, 09:02 PM
ecka333 ecka333 is offline
Member
 
Join Date: Oct 2009
Posts: 74
Default

Markd77, my project has external 32768kHz oscilator and everything works fine, system wakes-up from the sleep now in two minutes intervals (with prescaler set to 1). Now i just want to inprove my code and to make it more efficient. Anyway, thank you for the answer.
Reply With Quote
Reply   Post New Thread

Tags
,


Related Site Pages
Section Title
Worksheet Microprocessor programming
Video Lecture Representative System (Part 1) - Microprocessors


Similar Threads
Thread Thread Starter Forum Replies Last Post
PIC24H Interrupt Latency Diagram Help blah2222 Embedded Systems and Microcontrollers 5 03-06-2012 12:10 AM
Help Me With MiKroC Code kirayamato_143 Embedded Systems and Microcontrollers 10 11-09-2011 10:00 AM
PIC18F Error [1205] [1131] pmanalex Embedded Systems and Microcontrollers 4 04-21-2011 06:57 PM
Pic microcontroller SLEEP mode ecka333 Embedded Systems and Microcontrollers 3 12-24-2010 12:13 AM

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 02:22 AM.


User-posted content, unless source quoted, is licensed under a Creative Commons Public Domain License.
Powered by vBulletin
Copyright ©2000 - 2014, vBulletin Solutions, Inc.