News:

;) This forum is the property of Proton software developers

Main Menu

STOP

Started by joesaliba, Aug 16, 2022, 07:57 AM

Previous topic - Next topic

joesaliba

I am using PIC18F26K22. I was doing some debugging and was using the stop at certain points of the code.

I have an ISR through Timer 1 @ 100Hz.

I noticed that if the STOP is used after the ISR is enabled, the ISR keeps going.

Is this normal?

Regards

Joe

top204

QuoteIs this normal?

Yes. The Stop command simply places a never ending loop at that position. i.e.

internal_label:
    bra internal_label


Or if the watchdog is enabled, it places:

internal_label:
    clrwdt
    bra internal_label


It does not disable any peripherals, it just stops the program at that point.




joesaliba

Thanks Les.

keytapper

Quote from: top204 on Aug 16, 2022, 08:06 AMOr if the watchdog is enabled, it place
What then would trigger the reset?
I mean that to have an intentional reset, there should be something like looping forever and the watchdog will take away. Perhaps it should be a explicit loop without a clrwdt.
Ignorance comes with a cost

tumbleweed

QuoteI mean that to have an intentional reset
How about a SLEEP instruction?

top204

#5
QuotePerhaps it should be a explicit loop without a clrwdt.

No..... The Stop command is "purely" for use when testing programs and is not used, or needed, in real programs. Or at least I cannot see any use for it in a real program because what purpose would it be to stop a real program in its tracks altogether?

The compiler places a hidden stop mechanism just before the procedures are placed in the underlying code, so the main body of code will not flow into them if it does not have a loop mechanism. But "all" main body codes in real programs are a loop of some sort, otherwise, the program would do one thing then nothing else at all... Ever! :-)

So in a test program, removing the Clrwdt mnemonic would cause the program to reset when it is supposed to stop! I can imagine all the questions of "Why is this happening?" Because a lot of users of microcontrollers do not know about the finer points of them, especially what a watchdog timer is! And when I place a Stop command in any program, I expect the test program's flow to stop, and not restart until the microcontroller is reset or re-powered, not keep resetting itself!

As stated above, for a mechanism that can be restarted by an interrupt, use the Sleep command with no parameter, but make sure the watchdog is disabled if it is required to stay asleep until something external wakes it up, otherwise, the watchdog timer will continuously wake the device up from sleep when it overflows and reset the microcontroller.

In the newer devices that have more control over the watchdog timer's ratio, it is actually a good method of putting the microcontroller into a low-power sleep mode, and it automatically waking up every minute or so, or even longer with some of the newer devices. Then waking up fully if a button is pressed or a signal is detected on a peripheral etc... For this type of mechanism, place a Clrwdt mnemonic just before the Sleep command, and the very first instruction after the Sleep command is Clrwdt, to stop the watchdog resetting the microcontroller on the next few clock cycles.

joesaliba

In fact, I used STOP for debugging only.

In another thread I spotted an anomaly and while checking for the culprit I used the STOP as I did not wanted that the bit I was checking will be set somewhere else.

Again thanks Les for your detailed information.

Regards

Joe

keytapper

Yeah, I liked very much the details :)
Ignorance comes with a cost