View previous topic :: View next topic |
Author |
Message |
Tom-H-PIC
Joined: 08 Sep 2003 Posts: 105 Location: New Castle, DE
|
Program execution and how to trace? |
Posted: Wed Sep 13, 2017 7:11 pm |
|
|
I'm working with the dsPIC33EP512GP506 using compiler 5.072.
I'm having issues with my code either getting lost or it is stuck in some loop that I'm not see and the WDT is resetting.
So I would like a way to trace the execution and retrieve it after reset.
I know that trace execution will be difficult and in some case not feasible at all.
But I was searching the forum and found 2 post that Ttelmah tells how to preserve a RAM locations after reset.
In this post he talks about how to accomplish this.
http://www.ccsinfo.com/forum/viewtopic.php?t=55813&highlight=trace
So my question is Ttelmah do you or anyone have a small example of code with this type of trace setup?
Thanks |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19497
|
|
Posted: Thu Sep 14, 2017 12:50 am |
|
|
It's very simple....
Code: |
//processor define
//fuses & clock
int16 fred;
void main(void)
{
//At this point 'fred' will contain a unknown value on first boot
//but will still contain what it had in it on a subsequent boot
int8 why;
why=restart_cause();
if (why==RESTART_POWER_UP)
{
fred=0; //Initialise fred on power on
}
//Now 'fred' will contain '0' on the first power up and whatever
//the code leaves in it on other restarts
printf ("Fred is %d\n"); //either display it or put a break here
while (TRUE)
{
fred=1;
//now do what you want and set fred to different values
//when the code restarts, fred will contain what it last had
}
}
|
The key point is that a global variable always sits iin the same RAM location. Provided you do not tell the compiler to initialise it, nothing is done at boot (one exception - you must not use #ZERO_RAM), so it retains what it last contained. |
|
|
Tom-H-PIC
Joined: 08 Sep 2003 Posts: 105 Location: New Castle, DE
|
|
Posted: Mon Sep 18, 2017 6:50 am |
|
|
Thank you Ttelmah
I will give it a go! |
|
|
Tom-H-PIC
Joined: 08 Sep 2003 Posts: 105 Location: New Castle, DE
|
|
Posted: Tue Sep 19, 2017 9:16 am |
|
|
So the problem that I having now is if I'm not using “#ZERO_RAM” the program will not start and it gets hung-up.
So I'm using the CCS ICD-U64 and I only use it for programing and that is all.
After reprogramming the chip the code will get stuck in a loop and not enter the run loop also the reset button will not get it out of this. But if I do a power reset it start and runs fine. Also at that point I can do a reset using the reset button and it still starts and runs.
But all the variables in that location pointed to by the trace have been initialized to zero.
So are there things left in the registers or something I don’t know about?
Tom |
|
|
|