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 CCS Technical Support

How to reset the program when receive serial interrupt?

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



Joined: 10 Sep 2003
Posts: 60

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger ICQ Number

How to reset the program when receive serial interrupt?
PostPosted: Tue Dec 14, 2004 8:38 am     Reply with quote

Dear all,

I would like to reset my program (start from the first line in the main loop) after receive a character 'g' through rs232. May I know what is the best way for me to do this? I am using PIC16f876. I searched through ccs manual and find this : reset_cpu()? Can this be used for my purpose? However when I insert this line in my program, I got an error.
_________________
Einly
rwyoung



Joined: 12 Nov 2003
Posts: 563
Location: Lawrence, KS USA

View user's profile Send private message Send e-mail

PostPosted: Tue Dec 14, 2004 9:41 am     Reply with quote

reset_cpu() should work for you. What is the error message?
_________________
Rob Young
The Screw-Up Fairy may just visit you but he has crashed on my couch for the last month!
Einly



Joined: 10 Sep 2003
Posts: 60

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger ICQ Number

Undefined Identifier
PostPosted: Fri Dec 17, 2004 1:24 am     Reply with quote

When I compile the program, it is stated "Undefined identifier", and the () in the reset_cpu() is highlighted. Is it caused by my compiler version which is 2.734? Or is it because of some header files that should I put?
_________________
Einly
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

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

PostPosted: Fri Dec 17, 2004 1:28 am     Reply with quote

reset_cpu() is a 18F family instruction.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 17, 2004 2:18 am     Reply with quote

Quote:
reset_cpu() is a 18F family instruction.

It actually works in both compilers, but in the 16-series PICs
it clears PCLATH and then does a GOTO 0.

If the original poster wants to do this with an older version of the
compiler, then see this old post:
http://www.ccsinfo.com/forum/viewtopic.php?t=8377
asmallri



Joined: 12 Aug 2004
Posts: 1634
Location: Perth, Australia

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

PostPosted: Fri Dec 17, 2004 2:24 am     Reply with quote

True - I use this method also but it leaves you with the problem that the stack is not reset and on the 16F family this is a problem. Do you have a work around?

I did think of forcing a reset by enabling the reset on stack overflow fuse and then performing resursive assembler calls until the stack overflowed but considered it a bit ugly.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Dec 17, 2004 12:58 pm     Reply with quote

But on the 16-series, the stack is circular. So it shouldn't matter
where the stack pointer is set when program execution begins at
address 0000.
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

PostPosted: Mon Dec 20, 2004 4:04 pm     Reply with quote

asmallri wrote:
I did think of forcing a reset


in older compilers...
Code:

setup_wdt(WDT_18MS);
while(1)  /* wait for the wdt to shoot me in the head */
  ;


jds-pic
Einly



Joined: 10 Sep 2003
Posts: 60

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger ICQ Number

setup_wdt(WDT_18MS)
PostPosted: Wed Dec 29, 2004 9:19 am     Reply with quote

hi,

Should I include any header file or initialization/declaration to use this command?

setup_wdt(WDT_18MS)

I am using PCM Compiler 2.734.

Or whenever I receive a serial interrupt, I just setup the watchdog timer by writing this:

setup_wdt(WDT_18MS)
while(1);

then after 18ms the program will automatically be reset?
_________________
Einly
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: setup_wdt(WDT_18MS)
PostPosted: Wed Dec 29, 2004 9:58 am     Reply with quote

Einly wrote:
Should I include any header file or initialization/declaration to use this command?


obviously you need the device- or family-specifc definition for WDT_18MS.
for example, one series of PICs (16C65) has definitions that look like:
Code:
#define WDT_18MS        8
#define WDT_36MS        9
#define WDT_72MS       10
#define WDT_144MS      11
#define WDT_288MS      12
#define WDT_576MS      13
#define WDT_1152MS     14
#define WDT_2304MS     15


you must have the correct definitions for the part you are using; typically these are located in the device-specific header file that CCS provides.

Einly wrote:
Or whenever I receive a serial interrupt, I just setup the watchdog timer by writing this:
Code:

setup_wdt(WDT_18MS)
while(1);

you *must* leave the WDT disabled unless you have provisions to reset it before it expires. otherwise you are going to reset the part in places you certainly don't want to reset in.

in general use, you enable the WDT via a directive such as:
setup_counters(WDT_576MS);

Einly wrote:
then after 18ms the program will automatically be reset?

yes, following the above suggestions... if you enable the WDT and then don't ping it in under N ms, a hardware reset is asserted by logic internal to the PIC. this effectively simulates a power on reset condition with the caveat that it is possible to tell upon startup that the device was reset in this manner.

Code:

void main() {
        if ((restart_cause())==NORMAL_POWER_UP)
          wdt_timeout_flag=FALSE;             
        else
          wdt_timeout_flag=TRUE;
...


note that the call to restart_cause() must be the VERY FIRST thing you do, otherwise you will get erroneous data. if any of setup_counters() or setup_timer() or enable_interrupts() are performed, the restart cause register will be cleared. the constants for restart_cause are again defined in the device-specific driver file supplied by CCS:
Code:
#define WDT_FROM_SLEEP  0
#define WDT_TIMEOUT     8
#define MCLR_FROM_SLEEP 16
#define NORMAL_POWER_UP 24


again, you must use the correct definitions for the PIC device you are employing.

jds-pic
Einly



Joined: 10 Sep 2003
Posts: 60

View user's profile Send private message Send e-mail Yahoo Messenger MSN Messenger ICQ Number

Undefined identifier
PostPosted: Wed Dec 29, 2004 9:59 pm     Reply with quote

Dear sir,


I wrote this line setup_wdt(WDT_18MS) and tried to compile. But it has a error of "Undefined identifier". "(W" is being highlighted. May I know is that because of the PCM Compiler Version. Anyway, restart_wdt() is being recognized.
_________________
Einly
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

Look in the Header File
PostPosted: Wed Dec 29, 2004 10:16 pm     Reply with quote

You haven't posted any of your code or said what PIC you are using...

As JDS-PIC said earlier you have to look in the PIC header file (i.e 16F877.h) for the PIC you are using to find out what WDT settings are valid.
jds-pic



Joined: 17 Sep 2003
Posts: 205

View user's profile Send private message

Re: Undefined identifier
PostPosted: Wed Dec 29, 2004 11:24 pm     Reply with quote

Einly wrote:
Dear sir,
I wrote this line setup_wdt(WDT_18MS) and tried to compile. But it has a error of "Undefined identifier". "(W" is being highlighted. May I know is that because of the PCM Compiler Version. Anyway, restart_wdt() is being recognized.


einly,
do you have the manual that comes with the compiler?
do you have the help file that comes with the compiler?

have you looked up the syntax of the setup_wdt() function?
what did it say?
have you looked at any of the example files which have WDT implementations?
what did they do there?

jds-pic
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