Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 23:05 01 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 : uMite Interrupts making me crazy

Author Message
viscomjim
Guru

Joined: 08/01/2014
Location: United States
Posts: 925
Posted: 04:54pm 06 Apr 2016
Copy link to clipboard 
Print this post

I am loosing it or something...

This program works only one time after startup and I can not figure out why. I turn on the interrupts and sit in a loop. When I pull one of the pins low, it will print out which one it is and then won't work again until I power cycle the unit. I do the setpin X, din to disable the interrupts so that it can't be interrupted while doing something in the sub, then I re-enable the interrupts again and it just sits in the main2 loop and can't be interrupted again. WHY????

Thanks for any and all help with this!!!!

Also, the four pins are pulled high with external 10k resistor.

MAIN:
SetPin 2, INTL, TRIGGERED1 'Input from Trigger 1
SetPin 3, INTL, TRIGGERED2 'Input from Trigger 2
SetPin 4, INTL, TRIGGERED3 'Input from Trigger 3
SetPin 5, INTL, TRIGGERED4 'Input from Trigger 4
PRINT "TURNED ON INTERRUPTS"

MAIN2:
GOTO MAIN2

'===================================================================
SUB TRIGGERED1
SETPIN 2, DIN 'TURN OFF INTERRUPT
SETPIN 3, DIN 'TURN OFF INTERRUPT
SETPIN 4, DIN 'TURN OFF INTERRUPT
SETPIN 5, DIN 'TURN OFF INTERRUPT
PRINT "TRIGGER ONE INTERRUPT OCCURED"
GOTO MAIN
END SUB

'===================================================================
SUB TRIGGERED2
SETPIN 2, DIN 'TURN OFF INTERRUPT
SETPIN 3, DIN 'TURN OFF INTERRUPT
SETPIN 4, DIN 'TURN OFF INTERRUPT
SETPIN 5, DIN 'TURN OFF INTERRUPT
PRINT "TRIGGER TWO INTERRUPT OCCURED"
GOTO MAIN
END SUB

'===================================================================
SUB TRIGGERED3
SETPIN 2, DIN 'TURN OFF INTERRUPT
SETPIN 3, DIN 'TURN OFF INTERRUPT
SETPIN 4, DIN 'TURN OFF INTERRUPT
SETPIN 5, DIN 'TURN OFF INTERRUPT
PRINT "TRIGGER THREE INTERRUPT OCCURED"
GOTO MAIN
END SUB

'===================================================================
SUB TRIGGERED4
SETPIN 2, DIN 'TURN OFF INTERRUPT
SetPin 3, DIN 'TURN OFF INTERRUPT
SetPin 4, DIN 'TURN OFF INTERRUPT
SetPin 5, DIN 'TURN OFF INTERRUPT
PRINT "TRIGGER FOUR INTERRUPT OCCURED"
GOTO MAIN
END SUB
Edited by viscomjim 2016-04-08
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6266
Posted: 05:22pm 06 Apr 2016
Copy link to clipboard 
Print this post

You are GOTO'ing out of a SUB instead of a normal END SUB
As well as being a no-no, I think you need to END SUB to turn the interrupts back on.

Try setting a flag in the sub and re-initializing the interrupts when the flag has been set.

Jim
VK7JH
MMedit
 
TassyJim

Guru

Joined: 07/08/2011
Location: Australia
Posts: 6266
Posted: 05:30pm 06 Apr 2016
Copy link to clipboard 
Print this post

Try this:

DIM triggered

MAIN:
SETPIN 2, INTL, TRIGGERED1 'Input from Trigger 1
SETPIN 3, INTL, TRIGGERED2 'Input from Trigger 2
SETPIN 4, INTL, TRIGGERED3 'Input from Trigger 3
SETPIN 5, INTL, TRIGGERED4 'Input from Trigger 4
PRINT "TURNED ON INTERRUPTS"

MAIN2:
IF triggered = 1 THEN
triggered = 0
SETPIN 2, INTL, TRIGGERED1 'Input from Trigger 1
SETPIN 3, INTL, TRIGGERED2 'Input from Trigger 2
SETPIN 4, INTL, TRIGGERED3 'Input from Trigger 3
SETPIN 5, INTL, TRIGGERED4 'Input from Trigger 4
PRINT "TURNED ON INTERRUPTS"
ENDIF
GOTO MAIN2

'===================================================================
SUB TRIGGERED1
SETPIN 2, DIN 'TURN OFF INTERRUPT
SETPIN 3, DIN 'TURN OFF INTERRUPT
SETPIN 4, DIN 'TURN OFF INTERRUPT
SETPIN 5, DIN 'TURN OFF INTERRUPT
PRINT "TRIGGER ONE INTERRUPT OCCURED"
triggered = 1
END SUB

'===================================================================
SUB TRIGGERED2
SETPIN 2, DIN 'TURN OFF INTERRUPT
SETPIN 3, DIN 'TURN OFF INTERRUPT
SETPIN 4, DIN 'TURN OFF INTERRUPT
SETPIN 5, DIN 'TURN OFF INTERRUPT
PRINT "TRIGGER TWO INTERRUPT OCCURED"
triggered = 1
END SUB

'===================================================================
SUB TRIGGERED3
SETPIN 2, DIN 'TURN OFF INTERRUPT
SETPIN 3, DIN 'TURN OFF INTERRUPT
SETPIN 4, DIN 'TURN OFF INTERRUPT
SETPIN 5, DIN 'TURN OFF INTERRUPT
PRINT "TRIGGER THREE INTERRUPT OCCURED"
triggered = 1
END SUB

'===================================================================
SUB TRIGGERED4
SETPIN 2, DIN 'TURN OFF INTERRUPT
SETPIN 3, DIN 'TURN OFF INTERRUPT
SETPIN 4, DIN 'TURN OFF INTERRUPT
SETPIN 5, DIN 'TURN OFF INTERRUPT
PRINT "TRIGGER FOUR INTERRUPT OCCURED"
triggered = 1
END SUB


Jim
VK7JH
MMedit
 
Grogster

Admin Group

Joined: 31/12/2012
Location: New Zealand
Posts: 9585
Posted: 05:47pm 06 Apr 2016
Copy link to clipboard 
Print this post

While you can probably get away with it, my understanding is that you should not be running code of more then a line or two inside an interrupt. The idea being to deal with the interrupt ASAP, and then exit from that interrupt - don't hang around inside one changing things.

I would tend to set some flags in the interrupts, and have the main loop change the SETPIN commands from the main loop based on the flags.

...but that is just me, and if it works for you(with Jim's mods), then.....
Smoke makes things work. When the smoke gets out, it stops!
 
MicroBlocks

Guru

Joined: 12/05/2012
Location: Thailand
Posts: 2209
Posted: 06:58pm 06 Apr 2016
Copy link to clipboard 
Print this post

Does this not work:
[code]
SETPIN 2, INTL, TRIGGERED1 'Input from Trigger 1
SETPIN 3, INTL, TRIGGERED2 'Input from Trigger 2
SETPIN 4, INTL, TRIGGERED3 'Input from Trigger 3
SETPIN 5, INTL, TRIGGERED4 'Input from Trigger 4
PRINT "TURNED ON INTERRUPTS"

DO
LOOP

SUB TRIGGERED1
PRINT "TRIGGER ONE INTERRUPT OCCURED"
END SUB

SUB TRIGGERED2
PRINT "TRIGGER TWO INTERRUPT OCCURED"
END SUB

SUB TRIGGERED3
PRINT "TRIGGER THREE INTERRUPT OCCURED"
END SUB

SUB TRIGGERED4
PRINT "TRIGGER FOUR INTERRUPT OCCURED"
END SUB
Edited by MicroBlocks 2016-04-08
Microblocks. Build with logic.
 
panky

Guru

Joined: 02/10/2012
Location: Australia
Posts: 1114
Posted: 06:59pm 06 Apr 2016
Copy link to clipboard 
Print this post

I think Jim is all over it. By using GoTo's inside the interrupt handler, you never actually exit the interrupt service routine. Worse than that, if another interrupt were to occur and be serviced, you would be recursively calling the interrupt service routine which would eventually run out of memory.

Jim's example code is a great lesson on code layout, particularly the indenting which shows straight away the problem. The experts always say "Try to NOT use goto unless there is a very,VERY good reason to do so." With Geoff's implementation of MMBasic, you can use subroutines and do loops to achieve the same thing but much safer than goto.

Cheers,
Doug.

... almost all of the Maximites, the MicromMites, the MM Extremes, the ArmMites, the PicoMite and loving it!
 
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