Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 18:26 11 Nov 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 : Help needed for INTERRUPT

Author Message
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 979
Posted: 11:46am 30 Jul 2018
Copy link to clipboard 
Print this post

Hi to all,

I have a Micromite mainprogram which calls a SUB with a LOOP and a long PAUSE (25 seconds).
I would like to leave this subroutine prematurely by pressing a key (SetPin nButton_ESC, DIN, INTL, ESCAPE, PULLUP) - how can I do this?

I am grateful for any help...

Frank
 
lizby
Guru

Joined: 17/05/2016
Location: United States
Posts: 3466
Posted: 12:18pm 30 Jul 2018
Copy link to clipboard 
Print this post

Maybe without an interrupt, loop through a bunch of short pauses (e.g., 100ms) and break out upon detecting keypress (or character available in input buffer).Edited by lizby 2018-07-31
PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 2171
Posted: 12:30pm 30 Jul 2018
Copy link to clipboard 
Print this post

just as lizby says.

instead of one long pause of 25 seconds, do several smaller pauses in a loop and check for your exit condition

i.e. don't do this...

Pause 25000


this is better...

do:loop until inkey$="" ' flush the key buffer to stop false exits.

for n=1 to 250
if inkey$<>"" then exit for
pause 100
next


with this approach, you might need to balance the loop because your processing will take some time so on a long pause, you might find you need to loop for 245 instead of 250. Remember also that any other stuff that happens while you are in this loop will add to the pause time - i.e. an interrupt every second taking 100ms will add another 2.5 secs to your pause! If accuracy/time is reasonably important, consider doing something like this as your timing loop.

this is better still...

t=timer
do
pause 100
loop while (timer-t)<25000 and inkey$=""


this way it doesn't really matter how long your processing takes (or what other interrupts occur while you are waiting), as soon as you have been in it for 25secs (plus a little bit) you drop out - or if a key arrives in the console.

hth
Edited by CaptainBoing 2018-07-31
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 01:50pm 30 Jul 2018
Copy link to clipboard 
Print this post

It is also best to have no pauses in subroutines at all.
You do that in main.
Without knowing what the rest of the program does it is difficult to give an example.

I often use 'state machine' logic that is very suited if you need stuff to keep on running while waiting for other stuff to happen (like a key press).

Do a search for 'discrete time state machine' to get some theory and examples.

Once you get this way of programming, live gets a lot easier as often we have to program something monitoring multiple inputs, check timings and generate the correct outputs.
Microblocks. Build with logic.
 
Frank N. Furter
Guru

Joined: 28/05/2012
Location: Germany
Posts: 979
Posted: 02:31pm 30 Jul 2018
Copy link to clipboard 
Print this post

Thank you for your ideas!

I thought it would be better with an interrupt solution than polling the key...
A motor is moved in one direction for 25 seconds and then in the other direction for 25 seconds for an endurance test. The SUB includes only this test. To exit this test manually, I would need this function with the ESC key...

Frank
 
Tinine
Guru

Joined: 30/03/2016
Location: United Kingdom
Posts: 1646
Posted: 02:06pm 31 Jul 2018
Copy link to clipboard 
Print this post

  MicroBlocks said  
I often use 'state machine' logic that is very suited if you need stuff to keep on running while waiting for other stuff to happen (like a key press).


I couldn't agree more. It's a great way to pseudo multitask.
My programs are never held-up with delays.
 
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