View previous topic :: View next topic |
Author |
Message |
hamedhamedi
Joined: 12 Feb 2012 Posts: 70
|
Posted: Fri Dec 05, 2014 2:27 pm Post subject: execute a subrotine after an interrupt |
|
|
Hi
i want to execute a subrotine after an interrupt,what shoul i do?
it means i want to come out of interrupt,and then execute subrotine,not within code of interrupt ,because i want to never lose any interrupt.
thanks
(BASCOM-AVR version : 2.0.7.7 ) |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Fri Dec 05, 2014 5:21 pm Post subject: just an idea |
|
|
Perhaps a main Do Loop. And an Interrupt service routine that only puts a variabele on 1 and returns. In the Do Loop a check if this variabele is 1 to do the jump to the subroutine. At the end of the subroutine put the variabele to 0, return to the Do Loop.
Have fun
Ben Zijlstra |
|
Back to top |
|
|
hamedhamedi
Joined: 12 Feb 2012 Posts: 70
|
Posted: Fri Dec 05, 2014 5:56 pm Post subject: |
|
|
ok,thanks
i did it,my main program is consist of a do loop that have so many code. when come back to main do loop, it take a time to check status bit that set in interrupt.
i want to execute subrotine immediately interrupt done! |
|
Back to top |
|
|
bzijlstra
Joined: 30 Dec 2004 Posts: 1179 Location: Tilburg - Netherlands
|
Posted: Fri Dec 05, 2014 7:27 pm Post subject: two cents.. |
|
|
Just my two cents...
You can check the interrupt variabele on several locations in the main Do Loop.
Perhaps somebody else has an idea.
Have fun
Ben Zijlstra |
|
Back to top |
|
|
glena
Joined: 25 Jul 2007 Posts: 284 Location: PA near Philly
|
Posted: Fri Dec 05, 2014 10:04 pm Post subject: |
|
|
It sounds to me like timing here is critical and you are unable or its problematic to place this other sub code at the end of the isr that you are talking about.
One idea that might work, would be to have the main isr trigger another irq so that the second isr gets called just after the main isr returns and in the second isr turn back on irqs right away. This means you can have nested IRQs . Note though that this can also lead to other issues if the main irq gets triggered to fast.
And yes this is possible to have nested IRQs this way. I did this for a wav file player where I have a high priority irq for pushing single samples and a lower priority irq for refilling buffers... If interested see here: http://bahbots.com/forum/viewtopic.php?f=2&t=2
My main thinking her would be to try to not do too much processing out side of the main loop. Try to break all tasks down to smaller work loads and call each task from the main loop according to priority. This way you just use irqs to set flags and do all the work as small peaces called from the main loop.
All this is very dependent on what it is your trying to do...
-Glen _________________ http://bahbots.com |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
Posted: Fri Dec 05, 2014 11:17 pm Post subject: |
|
|
If this is a positioning for something then maybe You can count steps and move motor when value is checked x times counted
You don`t loose any step. This is idea. Not tested solution.
Code: | $regfile = "m8def.dat"
Dim Move_motor_x_steps As Byte
On Int1 Encoder_isr
Do
'a lot stuff to do
While Move_motor_x_steps > 0
'MOVE MOTOR ONE STEP
Decr Move_motor_x_steps
Wend
Loop
End
Encoder_isr:
Incr Move_motor_x_steps 'count steps if uC BUSY
Return |
|
|
Back to top |
|
|
|