![]() |
Forum Index : Microcontroller and PC projects : Interrupts
Author | Message | ||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1989 |
In MM basic if I have an interrupt eg: SetPin 6, INTH,XXXX Can I execute the interrupt in software with Pin 6=1 Pause 5 Pin 6=0 Would I need a pause. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Just do this: [code] SetPin 6, INTH, MySub .... 'call the sub when needed from software MySub ..... SUB MySub 'Do your stuff here when an interrupt on pin 6 occurs OR when it is called from software. END SUB [/code] Microblocks. Build with logic. |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1989 |
Does not the interrupt have to end with 'Ireturn' or is it OK to branch to a defined sub. Read the manual on interrupts and could not find anything. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 1000 |
Its OK to call a SUB, use END SUB and not IRETURN to end it. The 4.6 Manual details it with the SETPIN command description. (there are two sections for SETPIN one after the other in the command section. Gerry Latest F4 Latest H7 FotS |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
For new programs it would be better to use [code] SUB MySub ... END SUB [/code] instead of the old way [code] MySub: .... return 'or ireturn [/code] The old way is more open to subtle errors as a program can execute code in a subroutine when not all code paths are terminated and obviously your case where a interrupt routine has to be used from code. Microblocks. Build with logic. |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2933 |
I am confused - are we saying it is now possible to terminate an interrupt with 'End Sub'?? WW |
||||
MicroBlocks![]() Guru ![]() Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Yes, that was introduced together with defined functions and subroutines. I think the micromites had that from the beginning, the maximite in later versions. It might be good to remove that from the manual and always use defined subroutines for interrupts. Microblocks. Build with logic. |
||||
Geoffg![]() Guru ![]() Joined: 06/06/2011 Location: AustraliaPosts: 3285 |
Excellent point. The old code (calling a label) can be left in but deprecated. Geoff Geoff Graham - http://geoffg.net |
||||
WhiteWizzard Guru ![]() Joined: 05/04/2013 Location: United KingdomPosts: 2933 |
I missed that one - always used 'iReturn'!! Guess it is time I re-read the manual ![]() |
||||
palcal![]() Guru ![]() Joined: 12/10/2011 Location: AustraliaPosts: 1989 |
Thanks all that's a big help. Paul. "It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all" |
||||
Grogster![]() Admin Group ![]() Joined: 31/12/2012 Location: New ZealandPosts: 9593 |
It DOES depend on what you are doing. If you KNOW FOR A FACT that the code will only EVER be called by an interrupt, then IRETURN is fine, I would think. Having interrupts call a subroutine that ends with END SUB is a nice combination though, if you need to be able to call the same code without it having to be summoned from an interrupt. Only problem I see with calling a sub from an interrupt, is that if the code happens to be in that very same sub, when the interrupt calls it again - would that perhaps not cause some odd and difficult to track bugs in code operation? Smoke makes things work. When the smoke gets out, it stops! |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |