Page 1 of 1

Software reset PIC

Posted: Sun Apr 28, 2013 9:35 pm
by MJU
Hello,

I'm using a PIC16F819 in a small project and I need to reset the PIC via the software.

I will explain:
I use the EEprom of the PIC and I a special case I need to clear the EEprom and make the PIC start the whole program from start (so all variables may be cleared).
At this point I "kinda" clear the EEprom by writing 255 via a loop from address 0 to 255. This looks good.
But after this the PIC should start from scratch at the point where it starts after a reset (or after the a power up).

I found two software resets:

asm("reset");

and

GOTO 0x000

Is there a better way of doing this?
It's not a problem that all variables are cleared, and even no problem if the whole EEprom gets wiped.

All help is welcome!

Re: Software reset PIC

Posted: Sun Apr 28, 2013 9:47 pm
by dazz
Hi
you could use the watchdog timer , if enabled you have to regularly check it, so you would let it time out where you wanted a reset to occur (search the forum as there are some good posts on using it, another way would be to use a sparepin and use it to drive the mclr pin when a reset is required

Regards
Dazz

Re: Software reset PIC

Posted: Sun Apr 28, 2013 9:56 pm
by JohnCrow
Hi
Ive used a C command to restart the device in the past.
Just put a C Box into the flowchart at the point you need to restart and enter the command reset( );

Though I expect its similar to asm("reset");

Re: Software reset PIC

Posted: Sun Apr 28, 2013 10:12 pm
by MJU
Thank you both for your quick response

I've put the reset in a C block, this seems to do the trick, but on an other forum I read that there could be a problem if the reset is called from in a macro?
Something to do with a stack overflow?

I'm not that deep into PIC programming to understand if this way of resetting is harmful for the way the PIC works..

Could this way of resetting the PIC cause harm?

Re: Software reset PIC

Posted: Mon Apr 29, 2013 6:46 am
by dazz
Hi Mju
Have a look at the datasheet for your device as theres a fair bit in there about the different types of reset

Regards
Dazz

Re: Software reset PIC

Posted: Mon Apr 29, 2013 9:17 am
by kersing
MJU wrote: I've put the reset in a C block, this seems to do the trick, but on an other forum I read that there could be a problem if the reset is called from in a macro?
Something to do with a stack overflow?
Reset will never create stack overflows. After a reset the program execution will start with an empty stack and variables will be either set to their default values (if specified in your code) or uninitialized. What happens to peripherals and registers can be found in the data sheet of your specific micro controller.