Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Software reset within isr

Status
Not open for further replies.

lipschutz

Member
HI

i need to know some mechanism to reset in software within an interrupt service routine upon detection of a particular condition. For which merely going to the point where the program was before ISR is not allowable but a fresh start is needed i.e RETFIE could not be used.

i tried to figure out from MID RANGE Reference Manual but couldn't get to the point because of too many suggestions.

regards
lipschutz
 
If you move up to the enhanced mid-range devices (which are cheaper and more powerful) then there's a specific command to do this.

With an older device you could use an I/O pin to actually trigger a hardware reset (via a capacitor).
 
Maybe just a "jump" to the beginning of the program. Do you need a software reset or a full hardware reset? What device are you using.. I see that everyone here at ETO always assume it is a PIC.. well you said "RETFIE" so that kind of tells it..
 
Maybe just a "jump" to the beginning of the program. Do you need a software reset or a full hardware reset? What device are you using.. I see that everyone here at ETO always assume it is a PIC.. well you said "RETFIE" so that kind of tells it..

He also said 'mid range' which is also a PIC term :D

However, simply jumping to the beginning of the program is NOT a reset, and will almost certainly lead to the program crashing (as the stack counter, and anything else, isn't reset).
 
He also said 'mid range' which is also a PIC term :D

However, simply jumping to the beginning of the program is NOT a reset, and will almost certainly lead to the program crashing (as the stack counter, and anything else, isn't reset).

True.. you would have to reset the stack counter etc.. One option is to set the watchdog do the reset and just go into an infinite loop and wait for the watchdog do its job.
 
As long as you initialize all the registers and variables that you use then jumping to zero is nearly as good as a hard reset. My suggestion for a soft reset would be,

Disable interrupts. - done in ISR anyway.
Set ports to input.
Turn off any automatic outputs like PWM.
Goto 0

The stack doesn't matter as it is a circular buffer.

Another way is to let the Watch Dog Timer time out.

One thing that will mess you up is external components that don't get reset. Things like I2C devices, LCDs etc.

Mike.
 
True.. you would have to reset the stack counter etc.. One option is to set the watchdog do the reset and just go into an infinite loop and wait for the watchdog do its job.

Like I said, just use an enhanced device:

Code:
7.5 RESET Instruction
A RESET instruction will cause a device Reset. The RI
bit in the PCON register will be set to ‘0’. See Table 7-4
for default conditions after a RESET instruction has
occurred.

Easy as that :D
 
thanks Nigel, it seems there is no other way than using a capacitor.

misterT: yes it is just a jump to the beginning while having the STACK empty but as far as my knowledge goes STACK can not be read or written. specifically i need a software reset.


-lipschutz
 
Like I said, just use an enhanced device:

Code:
7.5 RESET Instruction
A RESET instruction will cause a device Reset. The RI
bit in the PCON register will be set to ‘0’. See Table 7-4
for default conditions after a RESET instruction has
occurred.

Easy as that :D

I'm not sure if changing the device just because you need to "reset" is an easy solution.. I'm wondering now why there is a need to reset the chip.. maybe there is another solution to that.
 
thanks Nigel, it seems there is no other way than using a capacitor.

misterT: yes it is just a jump to the beginning while having the STACK empty but as far as my knowledge goes STACK can not be read or written. specifically i need a software reset.


-lipschutz

Use the watchdog to reset the chip.. Nigel and you are right. The simple "jump to zero" is a poor solution. Could you explain what is this condition that requires a full reset?
..and, I think it is possible to write to any memory location you want.. including the stack pointer, program counter etc.. I think you use C or Basic, so you may not know how to write to these memory locations.. i can tell you if you want.
 
Last edited:
thanks pommie i think your first suggestion could solve my problem right away. i just need to be sure that STACK contents will not create any problem to my application.

misterT: if it was not pic i would have almost certainly mentioned its name. but next time i will mention the name whatever it is and spare everybody from inferring it.

thanks again for your quick responses.
-lipschutz
 
The stack doesn't matter as it is a circular buffer.

Stack is not a circular buffer.. it is.. well, a stack.

lipschutz: use the watchdog to reset the chip. It is the best option. (best option really should be that you would not have to reset the chip)
 
Stack is not a circular buffer.. it is.. well, a stack.
Microchip explain it very well in section 3.3.2 of the 16F628 datasheet,
The stack operates as a circular buffer. This means that
after the stack has been PUSHed eight times, the ninth
push overwrites the value that was stored from the first
push. The tenth push overwrites the second push (and
so on).

And so, the stack can be any value it likes when it starts and it'll work just fine.

Also, there is no way to modify the stack pointer in a 16 series chip. - other than call and return etc.

Mike.
 
Microchip explain it very well in section 3.3.2 of the 16F628 datasheet,

The stack operates as a circular buffer. This means that
after the stack has been PUSHed eight times, the ninth
push overwrites the value that was stored from the first
push. The tenth push overwrites the second push (and
so on).

what!! that is shocking.. why? 8-byte stack.. is that true? Still it is a stack.. very crappy one. Not a circular buffer. Even if a circular buffer is used to implement the stack.
 
Yes, why would you want more? - some lower spec PIC's don't even have 8 bytes of stack :D

No wonder why the C-compilers for PICs are bad.. you can't do a single function call with 8-byte stack. Maybe I should get back to using PICs.. AVRs seem to make me blind because they are too easy to work with.
 
The point is that the stack is irrelevant to the OPs problem. You are correct, it is a very crappy one. I feel especially sorry for the C compiler writers.

BTW, the stack is 8 words of 13 bits [/pedant mode]:D

Mike.
 
The point is that the stack is irrelevant to the OPs problem.

Yes.. the stack is very irrelevant if it just goes around and loses data anyway. Kind of good way to handle stack overflow, but 8 words... that is tight tight tight.
 
The simple "jump to zero" is a poor solution. Could you explain what is this condition that requires a full reset?
.. Basic, so you may not know how to write to these memory locations.. i can tell you if you want.

i knew someone is going to ask that question. the first reason is i know not how to handle it better. the second reason is the main program has a number of check points and adc read and has long delays while the isr is lengthy as well. upon detection of a particular condition within isr dictates that a fresh start is favorable where using retfie would take me to a point in the main program and might miss some crucial check points which lead to poor control i suppose. going to org 000 would not give it a chance.

again by doing so i will be relieved of thinking of not doing so(too many possibilities).
suggest me if you have better techniques to crack it.

lipschutz
 
i knew someone is going to ask that question. the first reason is i know not how to handle it better. the second reason is the main program has a number of check points and adc read and has long delays while the isr is lengthy as well. upon detection of a particular condition within isr dictates that a fresh start is favorable where using retfie would take me to a point in the main program and might miss some crucial check points which lead to poor control i suppose. going to org 000 would not give it a chance.

again by doing so i will be relieved of thinking of not doing so(too many possibilities).
suggest me if you have better techniques to crack it.

You need to be FAR specific about exactly what you're trying to do, but ISR's should be short and fast, and it sounds a REALLY bad idea to want to reset from within one.

I suspect you're probably going about your requirements very poorly?.

Incidentally - to cover myself - the reason I'm familiar with the RESET command in the enhanced mid range series is because I use it to reset a GSM modem based alarm in response to a specific text message command, restoring the device to it's start-up point (which is running at 32KHz in sleep mode, checking every second for being turned ON).
 
Status
Not open for further replies.

Latest threads

Back
Top