View previous topic :: View next topic |
Author |
Message |
Einly
Joined: 10 Sep 2003 Posts: 60
|
How to reset the program when receive serial interrupt? |
Posted: Tue Dec 14, 2004 8:38 am |
|
|
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
|
|
Posted: Tue Dec 14, 2004 9:41 am |
|
|
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
|
Undefined Identifier |
Posted: Fri Dec 17, 2004 1:24 am |
|
|
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
|
|
Posted: Fri Dec 17, 2004 1:28 am |
|
|
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
|
|
Posted: Fri Dec 17, 2004 2:18 am |
|
|
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
|
|
Posted: Fri Dec 17, 2004 2:24 am |
|
|
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
|
|
Posted: Fri Dec 17, 2004 12:58 pm |
|
|
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
|
|
Posted: Mon Dec 20, 2004 4:04 pm |
|
|
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
|
setup_wdt(WDT_18MS) |
Posted: Wed Dec 29, 2004 9:19 am |
|
|
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
|
Re: setup_wdt(WDT_18MS) |
Posted: Wed Dec 29, 2004 9:58 am |
|
|
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
|
Undefined identifier |
Posted: Wed Dec 29, 2004 9:59 pm |
|
|
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: 1933 Location: Norman, OK
|
Look in the Header File |
Posted: Wed Dec 29, 2004 10:16 pm |
|
|
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
|
Re: Undefined identifier |
Posted: Wed Dec 29, 2004 11:24 pm |
|
|
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 |
|
|
|