News:

Let's find out together what makes a PIC Tick!

Main Menu

Resetting PIC

Started by ricardourio, Jun 28, 2023, 02:17 PM

Previous topic - Next topic

ricardourio

Hello,

    Is there some command to force PIC to reset ?

Ricardo Urio

Maxi

Just write "reset"  ;D

trastikata

Quote from: ricardourio on Jun 28, 2023, 02:17 PMIs there some command to force PIC to reset ?

Depends on what do you expect from the reset to do?

Parmin

MCLR pin can be used to reset I think.

Stephen Moss

#4
As trastikata said it depends on what you want to do, i.e. you could...

  • Immediate Forced reset: As Parmin indicated with the MCLR pin connected to both a Pull up resistor to Vcc and a Capacitor to ground you could use an I/O pin connected to the MCRL pin to pull the MCRL pin low and force an immediate reset by changing the pin from an Input to an Output and setting it Low.
    On Reset the pin will normal reset to an input thereby releasing the low state on the MCLR pin as the Capacitor re-charges through the resistor.
  • Delayed Forced Reset: If you don't mind a slight delay you could use the the Watchdog Timer (WDT) providing the device you are using as software On/Off control for the WDT. Set the WDT to its minimum time, then simply Enable it when you want a reset.
    The reset will generally disable the WDT for for you, thereby preventing further resets until you once again enable the WDT in software.
  • Automatic Reset on program failure: Again use the WDT, this is what it is really for. Set the appropriate length of delay and Enable the WDT using the configuration fuse (not software enable), then somewhere in you main code loop (and anywhere else you need it) add the ClrWdt command. Provided the ClrWdt command is executed before the WDT times out it will prevent the WDT from overflowing and generating a reset.
    However, if the code crashes/hangs then the ClrWdt command will not be executed and as a result the WDT will overflow, automatically resetting the PIC.

tumbleweed

If you're using a pic18, pic24, or pic33 then the 'reset' statement will generate a reset instruction, which is the same as a hardware MCLR reset.

If it's a pic12 or pic16 then 'reset' generates a 'goto 0' which will restart the program but isn't the same as a reset.

trastikata

#6
What I meant is software (MCLR) reset will simply return the program counter to address 0 and will reset some registers but not all but won't clear the RAM nor reinitialize the peripherals like a POR.

Here's an excellent document from Microchip:

http://ww1.microchip.com/downloads/en/devicedoc/reset.pdf

RESET.jpg

tumbleweed

The software RESET instruction will initialize almost all peripheral registers to the same state as a PON or MCLR.

There are a few bits that are not effected, but most of those are so that you can detect what the source of the reset was. The datasheet points out which bits are not changed, but there aren't many.

Nothing clears ram at PON or any form of reset.

ricardourio

Hello,

   Probably the "reset" command will do what I need. I was just in doubt because I didn't find it in the Proton Manual.

Thanks

Ricardo Urio

trastikata

Quote from: tumbleweed on Jun 29, 2023, 04:33 PMThe software RESET instruction will initialize almost all peripheral registers to the same state as a PON or MCLR.

There are a few bits that are not effected, but most of those are so that you can detect what the source of the reset was. The datasheet points out which bits are not changed, but there aren't many.

Nothing clears ram at PON or any form of reset.


Regarding the RAM - that's what I said - if it is expected to clear the RAM -it won't, RAM after POR is undetermined.

For the rest I disagree or at least the 18F devices I know of about the Reset (4550, 53, 26J50, 46J...) because of the USB bootloader I made,about half of the registers are not affected and several peripherals that I know of are not touched by Reset. Even the datasheet says so ...

It might be different in other devices, but if you take look at those I mention, you'd see that half of the registers stay unchanged after reset.

RESET2.jpg
RESET1.jpg
 

tumbleweed

#10
I don't know what their definition of "most registers" is, but if you look at the initialization table for a 4550 table 4.4 you find that most registers are set the same regardless of the reset cause, but they are changed.

I agree... some registers are not initialized no matter what, so you should always set them as appropriate.

added:
For example, the 4550 datasheet table 4.4 calls out 136 SFR's
Out of those 136, only 26 are marked as 'unchanged' by  a software RESET instruction or MCLR reset... the same ones marked as 'unknown' at PON reset.
I'm not sure how that qualifies as "most registers are unaffected by a reset".

Fanie

Depending on the regulator you use, you can switch the power off with a pin.
That will give you a complete reset...
Or switch a transistor before the regulator.