Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 6th April 2008, 11:35 PM   (permalink)
Experienced Member
mabauti is on a distinguished road
Default Interrupt & going back to the same label

I want to going back to the same label after an interruption service ALWAYS

letīs say I have this program
Code:
...
decisions:

blablabla
yadayadayada
...

routine1:
dothat
dothis
goto routine1

routine2:
dothat
dothis
goto routine2

...

routine9001:
dothat
dothis
goto routine9001

end
How do I make an interruption service in order to go back ALWAYS to the label decisions?
mabauti is offline   Reply With Quote
Old 7th April 2008, 12:28 AM   (permalink)
Experienced Member
 
Papabravo is a glorious beacon of lightPapabravo is a glorious beacon of lightPapabravo is a glorious beacon of lightPapabravo is a glorious beacon of light
Default

You put the address of the label you want to return to on the stack. When you execute the return from interrupt you'll get where you want to go. I don't recommend this approach for two reasons.
  1. It is completely unnecessary
  2. You'll never remember what you did and why when you come bact to it in 6 months
__________________
We never have time to do it right; but we always have time to do it over.
Papabravo is online now   Reply With Quote
Old 7th April 2008, 12:42 AM   (permalink)
Experienced Member
kchriste is a glorious beacon of lightkchriste is a glorious beacon of lightkchriste is a glorious beacon of lightkchriste is a glorious beacon of lightkchriste is a glorious beacon of light
Default

It can also lead to really nasty bugs. Image if you have a 32bit add routine on an 8bit processor and it is half way through dumping the answer, 8bits at a time, into a 32bit variable and your interrupt routine calls it away never to return.
Use flags to do this.
__________________
--- The days of the digital watch are numbered. ---
kchriste is offline   Reply With Quote
Old 7th April 2008, 05:49 AM   (permalink)
Experienced Member
 
donniedj has a spectacular aura about
Default

In the case of no 32-bit add routine I guess its ok. Not a morality or legality thread.

I have code in products that after a certain criteria is meet in the interrupt, I must always vector to a know location period. This was not true for every time the interrupt was called but after being called a set number of times. If its need then do it, block interrupts during 32-bit routines or whenever necessary.

And whats the method of remember anything in code?
Code:
;Vector to Sub "Decision"
;Reasons follow below:
;1....
;2....
__________________
I can still log in! Delete my account and all my post now.
donniedj is offline   Reply With Quote
Old 7th April 2008, 08:05 AM   (permalink)
Experienced Member
 
eblc1388 is just really niceeblc1388 is just really niceeblc1388 is just really nice
Default

Quote:
Originally Posted by mabauti
How do I make an interruption service in order to go back ALWAYS to the label decisions?
This is not a debate of why you would need to do it but how to do it.

With AVR, this is easily done as one can modify the stackpointer or push/pop values from the stack.

With 16F PIC, it is a bit more involved. You need to place(sometimes more than one) check bit instructions inside every routine and jump to "decisions" every time the bit is found set. Inside the ISR, you set that bit and return.

On start executing the "decisions" code, you reset the bit to false.
__________________
L.Chung
eblc1388 is offline   Reply With Quote
Old 7th April 2008, 08:24 AM   (permalink)
Super Moderator
 
Nigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to beholdNigel Goodwin is a splendid one to behold
Default

Quote:
Originally Posted by eblc1388
This is not a debate of why you would need to do it but how to do it.
I would disagree, if he's wanting to do such completely wrong things he needs telling NOW, not after he's created loads of really badly written and unreliable code. I don't see as there's any reason to ever want to do something so potentially dangerous?.
__________________
PIC programmer software, and PIC Tutorials at:
http://www.winpicprog.co.uk
Nigel Goodwin is offline   Reply With Quote
Old 7th April 2008, 09:00 AM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

Back in the 80s it was quite normal to have you ISR jump to the start of your main loop. Your main loop processed all the critical game stuff before updating the screen. By placing things like updating the score and radars etc near the bottom of the main loop they would get "dropped" if things got too busy. No one ever noticed if the score/radar got updated because at this point they were too busy trying to stay alive. One classic that used this technique was Defender from Williams.

Anyway, on a 16 series pic you could simply do,

Code:
        org   4
        goto RequiredCode
The code at the destination would have to clear the interrupt flag and re enable the global interrupts. The stack is circular and so doesn't matter. I must however add, I can't think of many applications that would benefit from this technique. Edit, if the OP's different routines were LED flash sequences (or something similar) and the IRQ was to change sequence then I guess this would work.

Mike.

Last edited by Pommie; 7th April 2008 at 09:04 AM.
Pommie is offline   Reply With Quote
Old 7th April 2008, 10:19 AM   (permalink)
3v0
Moderator
 
Blog Entries: 3
3v0 is a splendid one to behold3v0 is a splendid one to behold3v0 is a splendid one to behold3v0 is a splendid one to behold3v0 is a splendid one to behold3v0 is a splendid one to behold3v0 is a splendid one to behold
Default

A more common method is to have the ISR set a flag and handle the branch back to decisions handled in the main code.

This mimics the action of a break within a loop.

Code:
decisions:
     startOver = false
     blablabla
     yadayadayada
     ...
     
     if (startOver is true) 
     then goto decisions

     call routine1
     if (startOver is true) 
     then goto decisions
     
     call routine2
     goto decisions
end

You could shorten up the code with a macro or define.
3v0 is online now   Reply With Quote
Old 7th April 2008, 12:43 PM   (permalink)
Experienced Member
 
Papabravo is a glorious beacon of lightPapabravo is a glorious beacon of lightPapabravo is a glorious beacon of lightPapabravo is a glorious beacon of light
Default

Quote:
Originally Posted by eblc1388
This is not a debate of why you would need to do it but how to do it.

With AVR, this is easily done as one can modify the stackpointer or push/pop values from the stack.

With 16F PIC, it is a bit more involved. You need to place(sometimes more than one) check bit instructions inside every routine and jump to "decisions" every time the bit is found set. Inside the ISR, you set that bit and return.

On start executing the "decisions" code, you reset the bit to false.
And in that spirit I gave him the answer he was seeking along with the admonition. I feel that we have a responsibility to warn people to think about what they are doing. They can still do whatever they want -- that is the essence of freedom.
__________________
We never have time to do it right; but we always have time to do it over.
Papabravo is online now   Reply With Quote
Old 8th April 2008, 01:34 AM   (permalink)
Experienced Member
mabauti is on a distinguished road
Default

Ok then.

Thank you for your comments gentlemen
mabauti is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
PIC16F628a Problem generating a RCIE interrupt Norlin Micro Controllers 3 16th January 2008 01:43 AM
Priority Interrupt Controller Stellarcore Datasheet/Parts Requests 14 13th September 2007 04:13 PM
Question about Interrupt tinhnho Micro Controllers 3 11th February 2007 07:07 PM
how to give 120degree phase shift i've written a code esconele Micro Controllers 18 16th February 2006 12:49 PM
Work ID reader Track 2 problems with pic code. Need help! egg0900 Micro Controllers 2 19th April 2004 06:57 AM



All times are GMT. The time now is 05:50 AM.


Electronic Circuits  |  Radio Controlled
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.