Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

execute a subrotine after an interrupt

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
hamedhamedi

Bascom Member



Joined: 12 Feb 2012
Posts: 70

PostPosted: Fri Dec 05, 2014 2:27 pm    Post subject: execute a subrotine after an interrupt Reply with quote

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
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Fri Dec 05, 2014 5:21 pm    Post subject: just an idea Reply with quote

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
View user's profile Visit poster's website
hamedhamedi

Bascom Member



Joined: 12 Feb 2012
Posts: 70

PostPosted: Fri Dec 05, 2014 5:56 pm    Post subject: Reply with quote

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
View user's profile
bzijlstra

Bascom Ambassador



Joined: 30 Dec 2004
Posts: 1179
Location: Tilburg - Netherlands

netherlands.gif
PostPosted: Fri Dec 05, 2014 7:27 pm    Post subject: two cents.. Reply with quote

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
View user's profile Visit poster's website
glena

Bascom Member



Joined: 25 Jul 2007
Posts: 284
Location: PA near Philly

usa.gif
PostPosted: Fri Dec 05, 2014 10:04 pm    Post subject: Reply with quote

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
View user's profile AIM Address
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 971

poland.gif
PostPosted: Fri Dec 05, 2014 11:17 pm    Post subject: Reply with quote

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
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum