Software reset PIC

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
MJU
Posts: 502
Joined: Wed Nov 07, 2007 6:51 pm
Location: Antwerp Belgium
Has thanked: 121 times
Been thanked: 108 times
Contact:

Software reset PIC

Post 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!

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Software reset PIC

Post 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
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: Software reset PIC

Post 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");
1 in 10 people understand binary, the other one doesn't !

MJU
Posts: 502
Joined: Wed Nov 07, 2007 6:51 pm
Location: Antwerp Belgium
Has thanked: 121 times
Been thanked: 108 times
Contact:

Re: Software reset PIC

Post 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?

dazz
Posts: 1314
Joined: Sun Jan 15, 2012 3:15 pm
Has thanked: 474 times
Been thanked: 458 times
Contact:

Re: Software reset PIC

Post 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
To sign up to the V5 forum follow this link http://www.matrixmultimedia.com/forum_upgrades.php

kersing
Valued Contributor
Valued Contributor
Posts: 2045
Joined: Wed Aug 27, 2008 10:31 pm
Location: Netherlands
Has thanked: 553 times
Been thanked: 1081 times
Contact:

Re: Software reset PIC

Post 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.
“Integrity is doing the right thing, even when no one is watching.”

― C.S. Lewis

Post Reply