Motion Control Quick Start Knowledge keeps moving.
Before, we had learned:
quick start (1) -- firmware update
quick start (2) -- ZBasic program development
quick start (3) -- ZPLC program development
quick start (4) -- Communicate with HMI
quick start (5) -- IO Input & Output
quick start (6) -- Data Storage
quick start (7) -- ZCAN Expansion Module
quick start (8) -- EtherCAT Expansion Module
quick start (9) -- Oscilloscope
quick start (10)--Multiple Task Operation
Hi, everyone, nice to meet you.
As we all know, when emergency occurs in running motion, one thing can slove it and return to original program for keeping running, that is "Interrupt". And today let's learn knowledge about interrupt application on Zmotion motion controllers.
1. Material Preparation
--Materials--
(1) One computer with ZDevelop3.01 or above installed.
(2) One controller.
(3) One 24V DC power supply
(4) Several bus drive + motor (or stepper drive + motor).
(5) A number of controller wiring terminals.
(6) Several network cables.
(7) A number of connecting wires.
(8) Several expansion modules of different types.
--Wiring Reference--
2. Interrupt Introduction
(1) what is interrupt?
"Interrupt" means CPU must pause current tasks while executing program to process occurred emergency, then after the emergency is processed, return to the position that was interrupted just now.
And there are 3 stages when in processing motion:
A. Interrupt Respond: turn on the interrupt main switch, send interrupt request.
B: Interrupt Processing: protect interrupt point and site, execute interrupt program, specifically, convert into the enter of interrupt program after responded interrupt request, then execute the interrupt program.
C: Interrupt Return: when all interrupt programs are processed, end interrupt, waiting for next interrupt trigger,
(2) 3 kinds of interrupt
There are 3 types of interrupts, power failure interrupt, external interrupt and timer interrupt.
And main switch of interrupt must be turned on before using interrupt, in this way, entering interrupt when program has initialized well. Please note the interrupt switch is in "OFF" state by default when controller powers on.
In addition, they all can use Basic programming and PLC programming.
Now, let's learn one by one.
A. power failure interrupt
It must be a global SUB function . And the controller has only one power failure interrupt. The feature of this interrupt is the execution time of power failure is very limited, so only a few of commands can be written, then store them in VR.
Relative functions: INT_ENABLE, ONPOWEROFF.
B. external interrupt
Rising edge trigger or falling edge trigger can be set, also it must be a global SUB function.The difference is currently only interrupt IN0-31 can be used, and only the firmware that supports PLC function can be used.
Relative functions: rising edge interrupt IN_ONn, falling edge interrupt INT_OFFn.
C. timer interrupt
The function to be executed after reaching the set time must be a global SUB function. And the number of timers is determined by the controller models. Use ?*max to print and view.
Relative function: ONTIMERn.
(3) interrupt functions
--interrupt functions related to Basic--
INT_ENABLE: interrupt main switch, 1-ON, 0-OFF
ONPOWEROFF: power failure interrupt
INT_ONn: external input interrupt, rising edge is valid, n-input No.
INT_OFFn: external input interrupt, falling edge is valid, n-input No.
ONTIMERn: timer interrupt, n-timer No.
GLOBAL SUB: define interrupt function
END SUB: interrupte ends, return main interrupt
--interrupt functions related to PLC--
EI: interrupt is allowed, the same as BASIC, INT_ENABLE=1 is on
DI: interrupt is forbidden, the same as BASIC, INT_ENABLE=0 is on
ONPOWEROFF: power failure interrupt
INT_ONn: external input interrupt, rising edge is valid, n-input No.
INT_OFFn : external input interrupt, falling edge is valid, n-input No.
ONTIMERn: timer interrupt, n-timer No.
LBL: define interrupt function
IRET: interrupte ends, return main interrupt
(4) how to use interrupts?
--In Basic--
When 3 kinds of interrupts are running, interrupt program occupies one task No, independently.
A: For power failure interrupt:
It only supports one, and the interrupt program will be triggered to execute at the moment of power off. The execution time is very short, a few of commands can be written.
Example:
'Main program
INT_ENABLE =1
DPOS(0)=VR(0) 'read saved valued when power-on, resume coordinates
DPOS(1)=VR(1)
DPOS(2)=VR(2)
END 'main program ends
GLOBAL SUB ONPOWEROFF () 'power-off interrupt
VR(0) = DPOS(0) 'save coordinates to VR
VR(1) = DPOS(1)
VR(2) = DPOS(2)
END SUB
B: For external interrupt (rising edge or falling edge):
This kind of interrupt is used only by the controller is with PLC function, and it must be global SUB process. INT_ONn() is triggered by rising edge, INT_OFFn() is triggered by falling edge, n means IN input No., IN0-31 can be selected.
Example:
INT_ENABLE=1 'open interrupt
END 'main program ends
GLOBAL SUB INT_ON0 () 'external rising edge interrupt program
PRINT "IN0 rising edge trigger"
END SUB
GLOBAL SUB INT_OFF0 () 'external falling edge interrupt program
PRINT "IN0 falling edge trigger"
END SUB
C: For timer interrupt:
It supports openning multiple interrupts at the same time, the number is determined by the numebr of timers. And also it must be global SUB process. n in ONTIMERn() means timer No.
The timer is turned on: TIMER_START (timer No., timing time ms)
End of timer: TIMER_STOP (timer No.)
Timer status: value = TIMER_IFEND (timer No.), read-only parameter, return value: 0 - timing is in progress, 1 - timing is completed.
Example:
INT_ENABLE=1 'open interrupt
TIMER_START(0,100) 'timer 0 opens, execute once after 100ms
END
GLOBAL SUB ONTIMER0() 'interrupt program
PRINT "ontimer0 enter"
'TIMER_START(0,100) 'hope execute the interrupt periodically, open timer again in SUB
END SUB
--In PLC--
In PLC programming, use LBL instruction to define the interrupt function that is to be called, and the interrupt function is general used with Basic.
Following shows simple examples in ladder diagram:
While using external interrupt, please note X Number is , such as, the trigger condition of external interrupt defined by LBL @INT_ON8 is the rising edge of X10, the actual wiring use IN8.
And when interrupt program is running, one task is occupied, and the task No. is allocated automatically, no need to set manually.
Below shows the task status when running timer interrupt.
Precautions of interruption usage
→ There is no priority among these interruptions. Interrupt nesting is supported, and multiple interrupts can be executed at the same time, but too many interrupt functions should not be processed at the same time.
→ External interrupt is only valid in firmware that supports PLC function.
→ Interrupt function editing is global SUB process.
There is only one task inside the controller that processes all interrupt signal responses, and there is a fixed interrupt task No. If interrupt handles too many functions and the code of the interrupt handled is too long, all interrupt responds will be slowed down, or even interrupts are blocked, affecting execution of other interrupts.
Solutions:
→ Decrease the number of interrupts in a way, actually many applications can be achieved through cyclic scan.
→ If the interrupt processes an extremely long function, it is recommended to call one independent task to handle the complex task in interrupt, then other interrupt responses won't be blocked.
The running routine of starting the task in the interrupt is as follows. The large section of code of timer interrupt 0 runs as task 3. At this time, both timer interrupt 0 and timer interrupt 1 can be triggered normally, and there is no interrupt blocking.
3. Interrupt Routine
(1) Basic
(2) PLC
--in ladder diagram form--
--in instruction list form-
//Main program X0 is timed to interrupt 0, X1 timed to interrupt 1, X2-rising edge/falling edge interrupt, X3-OFF all interrupts
LBL @MAIN
ld m8002
ei
exe @ PRINT "VR(0)",VR(0)
ld x0
tmr t0 k2000
ld t0
OUT Y0
ld x1
ANIY1
tmr t1 k3000
ld t1
OUT Y1
ld x3
di
fend
//External interrupt, controlled by the input port on the controller
lbl @INT_ON2
ld m8000
exe @ PRINT "external interrupt 2 rising edge"
iret
lbl @INT_OFF2
ld m8000
exe @ PRINT "external interrupt 2 falling edge"
iret
//Timer 0 is interrupted, and the timer reaches the preset value to enable the interrupt
lbl @ONTIMER0
ld m8000
exe @ PRINT "timer interrupt 0"
iret
//Timer 1 is interrupted, and the timer reaches the preset value to enable the interrupt
lbl @ONTIMER1
ld m8000
exe @ PRINT "timer interrupt 1"
iret
//Power-off interrupt, the controller is powered off to execute this interrupt
lbl @ONPOWEROFF
ld m8000
mov k12345 d0
exe @ VR(0)=MODBUS_REG(0)
iret
end
ABOUT ZMOTION
That's all, thank you for your reading -- Motion Control Quick Start (11) | Interrupt Application on Zmotion Motion Controller
For more information, please pay close attention to "Support" and "Download" , and there are other platforms about Zmotion - Youtube & LinkedIn & Twitter & Tiktok & Facebook, including technical information (development environment, routine code), product showing, company development, etc.
Hope to meet you, talk with you and be friends with you. Welcome!
This article is edited by ZMOTION, here, share with you, let's learn together.
ZMOTION: DO THE BEST TO USE MOTION CONTROL.
Note: Copyright belongs to Zmotion Technology, if there is reproduction, please indicate article source. Thank you.
Zmotion Technology focuses on development of motion control technology and general motion control products, it is a national high and new technology enterprise. Due to its concentration and hard work in motion control technology, ZMOTION already become one of the fastest growing industrial motion control companies in China, and is also the rare company who has managed core technologies of motion control and real time industrial control software completely. Here, Zmotion provides motion controller, motion control card, vision motion controller, expansion module and HMI. In addition, there is one program software developed by Zmotion -- ZDevelop. It is a good choice for you to program and compile. And program through upper computer, there is PC manual.
Zmotion Technology provides motion control card, motion controller, vision motion controller, expansion module and HMI. ( more keywords for Zmotion: EtherCAT motion control card, EtherCAT motion controller, motion control system, vision controller, motion control PLC, robot controller, vision positioning...)
Have a good day, best wishes, see you next time.