CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Does wake-up from int clear WDT?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Will Reeve



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

Does wake-up from int clear WDT?
PostPosted: Tue Nov 02, 2004 4:38 am     Reply with quote

Picture the scene. PIC set up with a WDT at 2 seconds. State of the PIC is determined by iState variable. To send to sleep:

While (iState==sSleeping)
Sleep();

The way to wake the PIC up is via a RB interrupt which changes iState to be something else and the rest of the program generates restart_wdt() calls enough to keep everything running OK.

The first line of the RB interrupt is a restart_wdt() call.

My question is I can imagine that the pic can be very very close to generating a WDT wake-up when the RB interrupt happens, if the WDT overflow then happens the PIC will re-set because it’s running? I know the chances of this are small and I’ve not seen it in the design but is it possible? Or does the wake-up by RB interrupt automatically clears the WDT register in hardware to prevent this happening? The datasheet isn’t too clear on this matter.

Will
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 02, 2004 1:25 pm     Reply with quote

Can you post what PIC you're using ? This is a very hardware specific
question, and PICs might act differently in this area.
Will Reeve



Joined: 30 Oct 2003
Posts: 209
Location: Norfolk, England

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Tue Nov 02, 2004 1:29 pm     Reply with quote

It's a PIC18F452.

Keep well,

Will
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Nov 02, 2004 2:47 pm     Reply with quote

Based on my reading of the reference manual, the safest thing to do
would be to place a CLRWDT instruction immediately after the SLEEP
instruction. See section 28.4.1, near the bottom of the page:
http://ww1.microchip.com/downloads/en/DeviceDoc/39528.pdf
That way, as soon as the PIC wakes up from the INT_RB interrupt,
it will execute the CLRWDT instruction and then jump to the interrupt
vector, and then continue on through the CCS interrupt dispatcher.
Example:

sleep();
restart_wdt();


Still, there exists the question of what happens if the WDT fires
just as the PIC is waking up due to the INT_RB or during the
execution of the CLRWDT. I need a detailed timing diagram
which shows what happens at the Q1-Q4 level (ie., Fosc clock).
I can't find one in the Microchip literature, so far.
I have to build a prototype board, so I don't have any more time
to research this today, but it is an interesting question.
Ttelmah
Guest







Re: Does wake-up from int clear WDT?
PostPosted: Tue Nov 02, 2004 3:41 pm     Reply with quote

Will Reeve wrote:
Picture the scene. PIC set up with a WDT at 2 seconds. State of the PIC is determined by iState variable. To send to sleep:

While (iState==sSleeping)
Sleep();

The way to wake the PIC up is via a RB interrupt which changes iState to be something else and the rest of the program generates restart_wdt() calls enough to keep everything running OK.

The first line of the RB interrupt is a restart_wdt() call.

My question is I can imagine that the pic can be very very close to generating a WDT wake-up when the RB interrupt happens, if the WDT overflow then happens the PIC will re-set because it’s running? I know the chances of this are small and I’ve not seen it in the design but is it possible? Or does the wake-up by RB interrupt automatically clears the WDT register in hardware to prevent this happening? The datasheet isn’t too clear on this matter.

Will

For the mid range chips at least, MicroChip covers this in document 31026a.
It says there, that 'If an interrupt occurs, during or after the execution of a sleep instruction, the device will immediately wake-up from sleep. The sleep instruction will be completely executed before the wake-up. Therefore the WDT, and the WDT prescaler will be cleared'.
If you look at the instruction description for 'sleep' on the latter chips, this same logic is retained. The last part of the sleep instruction, clears the WDT (hence if you want to sleep for the entire watchdog time, and be woken by the watchdog, you should clear the watchdog timer on the instruction before the sleep).
So the answer is 'yes'.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group