PDA

View Full Version : Program crash - how to trace the cause



longpole001
- 3rd April 2014, 09:53
Hello all ,

I am working on program that on occasions is crashing and resetting the chip , can someone advise the methods to try and find out what may be causing the reset .

The code is getting big , and compiles to about 60k so far and although the problem is showing up now , i am unsure if it was being hidden elsewhere prior.

Regards

Sheldon

longpole001
- 3rd April 2014, 10:58
what is the depth that you can have for while , wend loops

It seems the problem may be that from my routines for key stroke checking

I use a while <> KEY , wend loop to test for an " exit to the loop

but as options go down into sub menu's , each need to be exited and the above menu's are looking for thier exit

is this the best method for multilevel menu structure ?

is it likly this structure is causing my issues ?

cheers

Sheldon

HenrikOlsson
- 3rd April 2014, 11:18
Hi,
Examining the RCON register may give some clue to why the device resets, if it's the watchdog for example. The manual doesn't say anything about a limitation on the number of nested WHILE-WEND loops.
You need to figure out where in the code "you are" when it crashes and/or if it has anything to do with the "depth" of the menu structure or if it's completely "random". Double and tripplecheck that you always end up at a RETURN when you've GOSUBed to some place.

If you have a serial connection then adding a boatload of HSEROUT statements is another way to keep track of what's happening. Entering menu, level 2, level 3, setting 2, level 2 etc. If you're using MPLAB and have a PICKit3 or other device programmer/debugger then you might give source level debugging a shot. Unfortunately it's not supported in the MicroCodeStudio IDE.

/Henrik.

richard
- 3rd April 2014, 12:16
the manual says you can nest subs 27 levels deep on a pic18 , but that number includes any use of the stack by interrupts also.
and that "The only PBP commands that are cause for concern when nesting are GOSUB and CALL. All other PBP commands may be nested with no stack concerns and no practical limit "

edit
that's pbp3

longpole001
- 3rd April 2014, 14:17
each key event has a sub containing the menu and its key events sub , found just by changing menu pages i am trigering the crash, it takes 25 key presses of showing each page back n forth to trigger the reset

even though the menu is not got 27 levels deep it does gosub to the next page to display and then run the keys sub for that next page

ill try another way for testing , but its structure change of the entire menu system as it stands

longpole001
- 3rd April 2014, 23:50
well that seems to be why , thanks richard , the subs were growing in depth as each page was shown , this eventually crashed the chip.

the answer is simple but a pain, use goto"s and routines label instead of gosub , for menus that have multi pages per sub section , where only one page is needed and not going deep then gosub can be used
because i have number of structures that have while , wend loops nested gosub helped ensure the location of the return , with out me having to do it directly

but a better monitor system for errors like this caused , i need to look into , able to monitor the stack usage depth is one tool that be nice

cheers

sheldon