Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 11:47 13 Jul 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Interrupts

Author Message
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1989
Posted: 11:03pm 24 Mar 2015
Copy link to clipboard 
Print this post

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: Thailand
Posts: 2209
Posted: 11:17pm 24 Mar 2015
Copy link to clipboard 
Print this post

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]
Edited by TZAdvantage 2015-03-26
Microblocks. Build with logic.
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1989
Posted: 11:33pm 24 Mar 2015
Copy link to clipboard 
Print this post

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.Edited by palcal 2015-03-26
"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: Australia
Posts: 1000
Posted: 01:27am 25 Mar 2015
Copy link to clipboard 
Print this post

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: Thailand
Posts: 2209
Posted: 02:19am 25 Mar 2015
Copy link to clipboard 
Print this post

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.


Edited by TZAdvantage 2015-03-26
Microblocks. Build with logic.
 
WhiteWizzard
Guru

Joined: 05/04/2013
Location: United Kingdom
Posts: 2933
Posted: 02:34am 25 Mar 2015
Copy link to clipboard 
Print this post

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: Thailand
Posts: 2209
Posted: 02:43am 25 Mar 2015
Copy link to clipboard 
Print this post

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: Australia
Posts: 3285
Posted: 03:03am 25 Mar 2015
Copy link to clipboard 
Print this post

  TZAdvantage said  It might be good to remove that from the manual and always use defined subroutines for interrupts.

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 Kingdom
Posts: 2933
Posted: 03:09am 25 Mar 2015
Copy link to clipboard 
Print this post

I missed that one - always used 'iReturn'!!

Guess it is time I re-read the manual

 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1989
Posted: 11:23am 25 Mar 2015
Copy link to clipboard 
Print this post

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 Zealand
Posts: 9593
Posted: 01:27pm 25 Mar 2015
Copy link to clipboard 
Print this post

  WhiteWizzard said   I missed that one - always used 'iReturn'!!


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!
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025