28If a “Return” or “Return To” command is used when the stack is empty, a “StackUnderflow” error will be asserted and execution of the program will halt. It is theresponsibility of the user to ensure that stack underflows do not occur.There are two ways in which a subroutine can be called; the simplest is the “GotoSub” command. A “Goto Sub” command is used to call a subroutine from withinthe program, usually to complete a sequence of commands which is usedrepeatedly in the program. The address stored on the stack when a “Goto Sub”command is used is the address immediately after the “Goto Sub”.The second way to call a subroutine is through interrupts. Interrupts can occur atany time, and are explained in the interrupts section, page 27. When asubroutine is called by an interrupt, the address stored in the stack is the addressof the command which would have next been executed. If the interrupt istriggered during a “Wait” or “Wait For Move” command, the address of the “Wait”or “Wait For Move” command is stored, and if the subroutine is completed by the“Return” command, the wait is resumed until it’s completion. Note: If a “Wait”command is interrupted, the time spent executing the interrupt or interruptscounts toward the “Wait” command’s delay time.InterruptsThe IDEA drive has three different types of interrupts, input triggered, positiontriggered and encoder triggered. All three operate in the same fashion, thedifference being only how they are triggered.When an interrupt is triggered, it branches to a subroutine with a specific priority.All interrupts need two parameters, the label of the subroutine to be run whentriggered and the priority. For more information on subroutines, see Subroutines,page 28.