Attempting to have an interrupt "active" during part of the code only

mholguin

New Member
Hi all:

I would like to have an Interrupt active , but only during a section of the code, inactive the rest of the time.

Is easy to define it during the execution of the desired code to be "monitored" by the interrupt, and to shut it off at the end of it. It works like a charmed for the first time it occurs, but after that first time, it won´t trigger again.

I would like a overhead explanation, sort of a how to guide -if possible- before having to format the code and explaining what it does... Does it makes sense?

Thanks in advanced for the help...

Marino
 

hippy

Technical Support
Staff member
It sounds like it's the way you are handling the interrupt so it would help if you could post your code or at least the areas which are relevant. This is the overall form your code should be taking ...

Code:
Do
  :                     ' No interrupts allowed here
  :
  SETINT $xx,$yy        ' Enable interrupts
  :
  :                     ' Interrupts allowed here
  :
  SETINT 0,0            ' Disable interrupts
  :
  :                     ' No interrupts allowed here
Loop

Interrupt:
  :                     ' Handle interrupt
  :
  SETINT $xx,$yy        ' Re-enable interrupts
  RETURN                ' Continue with main program
 

kevrus

New Member
You can turn off an 'interrupt' by using the SETINT OFF command If you have part of the program that you do not wish an 'interrupt' to operate, but remember that it will stay off until it is then commanded back on again using SETINT(or the program loops).
Also, when an interrupt has occurred and you have jumped to the 'interrupt' routine, the 'interrupt' is automatically turned off so you will need to initiate the SETINT command in the 'interrupt' routine and the routine must end in a RETURN to re-activate the 'interrupt'

hope that helps
 

mholguin

New Member
Thanks for the quick replies!

Attached is the code. The idea is to control a transfer switch for an emergency backup system. This module will be "signaled" via another circuit which will be monitoring the related power lines (signal will be low voltages).

The interrupt won't work neither on simulation nor on the circuit.

Any ideas?
 

Attachments

hippy

Technical Support
Staff member
Code:
interrupt:
  if pin1= 1 then
    :
  else
    :
    goto wait4grid
  endif
If it's going through that 'goto wait4grid', interrupts won't ever be re-enabled after the first time. An interrupt routine can only be exited via a RETURN.

You have to return back to where the interrupt occur and then handle it from there using variables as flags which can get complicated but in this case you may be able to get away with this ( untested ) ...

Code:
'* Activate Interrupt in case grid goes off during generator shutdown
  [b]b13 = 0[/b]
  setint %00000001,%00000001
  [b]If b13 <> 0 Then wait4grid[/b]
  let genok=0
  [b]If b13 <> 0 Then wait4grid[/b]
  low 1
  [b]If b13 <> 0 Then wait4grid[/b]
  let ongrid=0
  [b]If b13 <> 0 Then wait4grid[/b]
  wait gencool
  [b]If b13 <> 0 Then wait4grid[/b]
  low 0
  [b]If b13 <> 0 Then wait4grid[/b]
'* Deactivate Interrupt, go back to normal
  setint off
Code:
interrupt:
   [b]b13 = 1[/b]
   if pin1= 1 then
    :
  else
    :
    [b]return[/b]
  endif
You may be able to improve that - you know what your program's meant to do better than I do ;-)
 

mholguin

New Member
Woa... looks so obvious now, it hurts!!!

Now that I can see the problem wil tackle it, and will revert with walkaround...


Ouch!
 

mholguin

New Member
Hippy & all:

Once you pointed the mistake, it was an easy matter, just created a"flag" variable to signal whether or not the interrupt had activated and checking for it in the "wait4grid" procedure.


Thanks!!

Here's the modified code

wait4grid: 'once on gen power wait for grid power to return
setint off
if pin0=0 then
let gridok=0
wait gridstable

'* Activate interrupt in case grid fails whilst powering off
setint %00000001,%00000001

'activate relay to transfer to grid
if trans_int = 0 then
let genok=0
low 1
let ongrid=0
endif
if trans_int = 0 then
wait gencool
endif
if trans_int = 0 then
'activate relay to stop gen
low 0
endif

'* deactivate interrupt when going back to normal
setint off
if trans_int = 0 then
goto main
else
let trans_int = 0
goto wait4grid
endif
else
goto wait4grid
endif
return


interrupt:
restart:
if pin1= 1 then 'CHECK IF GENERATOR IS UP IF NOT WAIT 4 IT
high 0
goto restart
else
let genok = 1
high 1
let ongrid=1
low 7
let trans_int = 1
endif
setint %00010000,%00010000
return
 
Last edited:
Top