
中断是指在满足一些触发条件的时候,中断正在执行的程序,优先执行中断程序,完成后再返回原来的程序的过程;这里就有一个优先级的问题,1500PLC 支持26个优先级,这里要注意,优先级和OB编号不要搞混了。1最低,26最高,高优先级的OB可以中断低优先级的中断。比如最常用的程序循环OB(默认OB1),优先级是1,就很可能被其他级别的中断组织块打断正常的执行顺序;
以下内容适用于启动和处理 OB,具体取决于各自的优先级等级:
l 启动优先级等级低于 15 的 OB 时,启动可能会因通信而延迟并在处理时中断。
l 启动优先级等级为 15 的 OB 时,启动可能会因通信而延迟但不会在执行时中断。
启动优先级等级高于 15 的 OB 时,启动不可能因通信而延迟且无法在执行时中断。
Program cycle: 程序循环OB, 循环执行的程序块,比如最常见的OB1 作为程序的起始点;
Start Up: 启动OB 将在PLC工作模式从STOP 切换到RUN时执行一次;
Time delay interrupt: 指定的延时时间到达后,将开始中断程序执行,延时时间在扩展指令SRT_DINT 的输入参数中指定;
Cyclic interrupt: 可通过循环中断 OB 以相同时间间隔启动程序部分。
循环中断 OB 的启动时间根据其时间间隔和相位偏移来通过以下公式确定:
启动时间 = n * 时间间隔 + 相位偏移 (n = 0, 1, 2 ...
时间间隔即为两次调用之间的时间段, 是 1 μs 基本时钟周期的整数倍。
相位偏移是以时间间隔为倍数,从启动时间进行偏移的时间间隔。
使用多个循环中断 OB 时可使用相位偏移。 例如,当它们的时间间隔具有公倍数时,可使用相位偏移来防止同时启动。
使用相位偏移的示例
在用户程序中插入 2 个循环中断 OB: 一个 OB 的时间间隔为 20 ms,另一个的时间间隔为 100 ms。使用相位偏移来确保不在 100 ms 的整数倍时同时调用这两个 OB。
调用与循环中断 OB 相关的错误 OB
循环中断 OB 的运行时间必须远小于其时间间隔。 否则,会在循环中断时间间隔结束后仍在处理相应循环中断 OB。 此时,操作系统会生成时间错误(调用 OB 80)。 稍后将执行导致错误的循环中断或将其放弃。 但是,对于每个优先级稍后只能执行一个循环中断 OB。
Hardware interrupt:可使用硬件中断 OB 响应这些具有硬件中断能力的模块事件,这些事件可触发硬件中断。通过组态定义具体的事件。如果可能,仅通过硬件中断对具有硬件中断功能的模块的偶发事件进行响应。
使用硬件中断响应常发事件毫无意义,而且可能会导致 CPU 在不利条件下超时。
Time error interrupt: 超出最大循环时间后,OB 将中断程序的循环执行;据我测试1500大概是6 sec;
如果发生以下事件之一,S7-1500 CPU 操作系统将调用时间错误 OB:
在一个循环内第一次违反循环时间。
如果在同一循环内第二次违反循环时间,CPU 就转至 STOP 模式。通过在适当情况下调用指令 "RE_TRIGR",可防止这种情况。
已请求但未完全处理的 OB 编号请求已到达组态的报警限制。(对于移植后的程序,此警告限制设置为 1。)
警告限制设置为 1 意味着:如果循环中断 OB 之类的启动事件在同一 OB 的上一次处理尚未完成之前发生,操作系统将调用 OB 80。
这适用于其相关 OB 可导致时间错误的所有事件。
例如,在 CPU 处于 HOLD 模式后重新进入 RUN 而超时的时间中断
由于时间调快了超过 20 秒而跳过的时间中断(在从标准时间切换到夏令时期间也会发生)
Diagnostic error interrupt: 诊断中断具有诊断功能的 S7-1500 模块检测到其诊断状态发生变化并向 CPU 发送诊断中断请求。
Pull or plug of modules: 移走和插入一个已组态模块时,将调用这种OB;
Rack or station failure: 在分布式 I/O 中机架或站出错时,将调用机架故障处理 OB。
Programming error: 如果在程序执行期间出错且设置过全局错误处理,那么将调用程序错误处理 OB。要允许 S7-1500 CPU 调用编程错误 OB,必须设置全局错误处理。
I/0 access error: I/O 访问错误,要允许 S7-1500 CPU 调用 I/O 访问错误 OB,必须设置全局错误处理。
如果在执行用户程序指令期间直接访问 I/O 数据时出错,S7-1500-CPU 操作系统将调用 I/O 访问错误 OB。例如,在直接访问输入模块数据时发生读取错误时便会出现这种情况。I/O 访问错误 OB 会根据为其指定的优先级进行处理。比如用PIW,POW等;
Time of day: 时间中断OB, 在指定时间可以启动OB 一次或定期启动;
Synchronous Cycle: 使用等时同步模式中断时,可以启动与 DP 周期或 PN 发送时钟同步的子程序。通过在等时同步模式中断 OB 中调用 SYNC_PI 和 SYNC_PO 指令,来更新输入的相关过程映像分区和输出的相关过程映像分区。
直接访问时,避免访问指定了具有等时同步模式中断 OB 的过程映像分区的 I/O 区域。
Status: 操作系统在接收到一个状态中断时将调用状态中断 OB。
Update:更新中断;收到更新中断时,S7-1500 CPU 的操作系统将调用更新中断 OB。用户更改了从站或设备的插槽参数时,可能会执行以上操作。
Profile:制造商或配置文件特定的中断,操作系统收到一个制造商特定中断或配置文件特定中断时,将调用制造商特定的 OB 中断或配置文件特定的 OB 中断。
运动控制块的中断:
MC-Interpolator: When you create a technology object for S7?1500 Motion Control, the organization block MC?Interpolator [OB92] for processing the technology objects is created automatically. The Motion Control functionality of the technology objects creates its own execution level and is called in the SIMATIC S7?1500 execution system according to the MC?Servo [OB91] application cycle.
The MC?Interpolator [OB92] is write-protected. The contents cannot be changed.
MC-Servo: When you create a technology object for S7-1500 Motion Control, the organization block MC?Servo [OB91] for processing the technology objects is created automatically. The Motion Control functionality of the technology objects creates its own execution level and is called in the SIMATIC S7?1500 execution system according to the application cycle.
The MC?Servo [OB91] is write-protected. The contents cannot be changed.
The position control algorithms of all technology objects configured for Motion Control on the CPU are calculated within the MC?Servo [OB91].
You can set the application cycle and the priority of the organization block in accordance with your requirements for control quality and system load.
MC-Pre Servo: The organization block MC?PreServo [OB67] can be programmed and is called in the application cycle configured at the MC?Servo [OB91]. The MC?PreServo [OB67] is called directly before the MC?Servo [OB91].
Via the organization block, you can read out the configured application cycle (information in μs).
MC-Post Servo: The organization block MC?PostServo [OB95] can be programmed and is called in the application cycle configured at the MC?Servo [OB91]. The MC?PostServo [OB95] is called directly after the MC?Servo [OB91].
MC-Pre Interpolator: The organization block MC?PreInterpolator [OB68] can be programmed and is called in the application cycle configured at the MC?Interpolator [OB92]. The MC?PreInterpolator [OB68] is called directly before the MC?Interpolator [OB92].
额外的,下面是一篇专门介绍OB的文章,介绍的原理比较清楚。
OB1 – Main Cyclic Organization Block in TIA Portal