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

reset & WDT

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







reset & WDT
PostPosted: Tue Nov 09, 2004 5:43 am     Reply with quote

hiii everybody

I would like to ask about the fuction of reset_cpu command.

If I use reset_cpu command anywhere in the code, Where will the program go?

I mean, CPU starts whether at the beginning of my code (including variable definations) or at the beginning of the main?

Is there any difference, if CPU resets due to the WDT ?

what sort of code (WDT routine) should I write to run in case of overflow of WDT only?

Is there any bit to be tested?

thanks any guy who helps so much.

poorly
Ttelmah
Guest







Re: reset & WDT
PostPosted: Tue Nov 09, 2004 6:07 am     Reply with quote

poorly wrote:
hiii everybody

I would like to ask about the fuction of reset_cpu command.

If I use reset_cpu command anywhere in the code, Where will the program go?

I mean, CPU starts whether at the beginning of my code (including variable definations) or at the beginning of the main?

Is there any difference, if CPU resets due to the WDT ?

what sort of code (WDT routine) should I write to run in case of overflow of WDT only?

Is there any bit to be tested?

thanks any guy who helps so much.

poorly

The answer to this, is in the manual, and the device data sheet.
The reset_cpu command, triggers the instruction 'RESET' (on the 18 chips). This has the same effect as a MCLR reset on the processor. So the machine starts just as if this line has been pulled low. The 'restart_cause' command will reflect this. On 16 chips, the command is only a 'simulation', and causes a jump to address 0. As such, the registers are not reset to their 'power on' state, but in both cases, all 'initialisation' in the code will occur.

Best Wishes
poorly
Guest







PostPosted: Tue Nov 09, 2004 7:00 am     Reply with quote

Dear Ttelmah

In addition,

what sort of code (WDT routine) should I write to run in case of overflow of WDT only?

Is there any bit to be tested to run a different routine for WDT time out?

thanks a lot

poorly
Ttelmah
Guest







PostPosted: Tue Nov 09, 2004 9:33 am     Reply with quote

poorly wrote:
Dear Ttelmah

In addition,

what sort of code (WDT routine) should I write to run in case of overflow of WDT only?

Is there any bit to be tested to run a different routine for WDT time out?

thanks a lot

poorly

Classic example, would be to declare all your variables as uninitialised (and not have #zero_ram). Then have an 'init' function, that sets them to default values, and sets all the chip I/O up (so all the timer initialisation etc.). Then test 'restart_cause', for the watchdog (or other cases), and don't re-initialise on the watchdog.
Code:

void init() {
     if (restart_cause()==NORMAL_POWER_UP || restart_flag>1) {
        restart_flag=0;
        //Here do all the port setup, and register setup
     }
     else {
        ++restart_flag;
     }
}

In your main code, at a point where you are sure everything is working OK, clear 'restart_flag'.
This forces a full reset, if the watchdog timeout (or other reset cause), repeats, without getting to the fully 'running' condition.
You also need to declare variables, which you want to use 'over' the reset (such as restart_flag), by locating them yourself in a RAM area (so they are not automatically initialised).

Best Wishes
poorly
Guest







WDT
PostPosted: Thu Nov 11, 2004 5:53 am     Reply with quote

OK

thanks
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