I have been working on using the INPUT interrupts that are tied to end limit switches for a stepper based motion system. I have gotten them to work, but am a little confused about the timing.
This is the code for one of the ISRs:
' Ch1LoLmtISR - Interrupt handler for Ch1LmtSwLo
'
' This code aborts the CH1_Y stepper system when the interrupt condition is met
'
StepStop CH1_Y ' Abort Stepper Motion
IntrOff Ch1LmtSwLo_Int ' Disable interrupts for this Input
SetIO Ch1Intr ' Set ISR event RELAY
I am aware that while an ISR is active, following the execution of IntrDef, that the INPUT pin status is NOT latched at the end of the ladder logic scan. When the ISR for an input is disabled, the INPUT status is "visible" to ladder logic. So my "initial fix" was to re-sych the Ch1Intr RELAY at the end of the ladder logic to control a 2nd RELAY, Ch1IntrDly, with something that looks like this:
Ch1Intr
----||-----------------------------------------(Ch1IntrDly)
My assumption is that if the ISR set CH1Intr then waiting one scan time the delayed version of CH1IntrDLY in ladder logic, that the physical INPUT would be visible to the ladder logic.
Sometimes this works and sometimes it does not. So I added more logic to delay the CH1Intr by a 2nd scan and this worked a bit better, but sometimes failed.
Ch1IntrDly
----||-----------------------------------------(Ch1IntrDly2)
Ch1Intr
----||-----------------------------------------(Ch1IntrDly)
My "ultimate" fix was to make Ch1IntrDly a TIMER and not a RELAY. This will result in multiple scan times before the TIMER goes off. Now everything is visible to the ladder logic.
Do you have any suggestions on a better approach to "know" when the INPUTs are working after turning off an INPUT interrupt?
Is there some other timing issue that I am missing?
Does the SetStop take a lot of time to execute? If so should I have rearranged the order of the lines of code in the ISR?
Does the IntrOFF statement take effect immediately, or is it delayed to some point in time that is tied to the ladder logic scanner?
Beat regards,
Gary Dickinson