Introduction
Organization blocks (OBs) are very important in programming the SIMATIC controllers but most of the engineers don’t use many of them other than OB1. I myself haven’t gone through all of the OBs either which creates a good chance for me to have a closer look at them now.
This article provides an overview of all the OBs available for a S7-1500 controller. It will only cover the most basic understanding of the OBs and I will write further articles to discuss the deep dives if I think it is necessary.
Program Cycle
Program cycle OBs execute cyclically starting from the lowest OB number (OB1) and then the subsequent OBs starting from OB123 upwards. Normally a S7-1500 CPU allows up to 100 OBs. OB1 is the default and also called the MAIN OB.
Startup
The startup OBs will execute once when the PLC goes to RUN mode from STOP mode, power on or commanded STOP-to-RUN.
You can program multiple startup OBs. The OBs will execute in their numbers starting from the lowest number subsequently.
Time Delay Interrupt
The time delay interrupt OB executes after the user program gives the SRT_DINT command and the programmed time delay has elapsed. The time delay interrupt will interrupt the program cycle. Maximum of 4 time delay OBs are allowed.
Cyclic Interrupt
As its name describes, the cyclic interrupt OBs execute over defined intervals. Maximum of 4 cyclic interrupt OBs are allowed.
Hardware Interrupt
Hardware interrupt OBs are quite useful. We can program them to make the CPU response to certain conditions monitored by the PLC’s hardware.
The potential hardware events that can trigger the hardware interrupts are digital input edges (maximum of 16) and high speed counter (HSC) events including CV = PV, direction change and external reset (maximum of 6).
I once used hardware interrupt to measure the duty cycle of a sensor’s PWM output. I will write an article about it in the future.
Time Error Interrupt
The time error interrupt OB is used to handle the CPU executing time issues including scan time exceeding the maximum cycle time and interrupt OBs conflicts.
If the time error interrupt OB doesn’t exist in the CPU, the CPU will crash if any of the interrupt events happens.
This OB is too niche to spend much time on so I won’t dig deep until I encounter trouble with the CPU time stuff.
Diagnostic Event Interrupt
The diagnostic event interrupt OB is triggered when the CPU detects a diagnostic event or some PLC modules with the diagnostic features detect the similar event. The diagnostic events can be power failure, IO overflow, wire break, short circuit, etc. I haven’t encountered modules that are so mission critical that I need to use this OB to monitor and I hope I will never have to use it.
Pull or Plug of Modules
This OB can be triggered if programmed when a hot swapping module in the distributed IO system is pulled out or plugged in. I can see myself using this OB to program some auto configuration features which can make maintenance work extremely easy. Potentially I can use this OB to make my program smart enough to configure the whole system with the configuration control features. For configuration control, I’ll write a separate article to talk about it.
Rack or Station Failure
This OB can be used to respond to communication failure with a distributed IO. Similar to the diagnostic event interrupt, I haven’t seen any mission critical applications that will require this OB. Additionally, there are communication monitoring system functions that can perform the diagnostic features which makes this OB an overkill. I will write an article about the system diagnostic functions in the future.
Programming Error
Programming error OB is used to catch the program errors like array access going out of the boundary. In most of the cases that I have seen, this OB was used to stop the PLC from going to STOP mode by the desperate programmers. I’d not recommend using this OB unless you have some special programming cases.
IO Access Error
The IO access error OB is used to handle the error triggered by an user program driven IO access error. I don’t think this OB is useful in the S7-1500 era as the IO access user program already have good diagnostic features and the user program IO access error will not result in the CPU go to STOP mode.
Time of Day
Time of day OBs execute based on configured clock time conditions. The CPU supports two time of day OBs. The time of day OB can be configured to execute from every minute to yearly. Motion Control OBs I will talk about the motion control OBs in a separate article as they are so interesting and important.
Synchronous Cycle
The synchronous OBs are used to update the process image partition in the isochronous applications. These types of applications are typically high speed and high accuracy applications and are involved with the PROFINET IRT mode. I’ll write a separate article about the IRT communication and maybe some more articles about the related programming things.
Status, Update and Profile OBs
These OBs are for the CPU to respond to PROFIBUS or PROFINET devices’ status changes and are mainly used in the legacy systems. I won’t spend too much time on them.
OB and Event Priorities
Since we’ve talked a lot about interrupts in this article, it is natural to talk about the event priorities and their relationships with the OBs. The below table provides a clear reference to the event(s) and the OB(s) that can response to the events. It is also worth noting again that the SIMATIC controller’s priorities are in ascending order so the higher the priority number, the higher the priority.
Event | Quantity allowed | Priority |
---|---|---|
Program cycle | 1 event, multiple OBs allowed | 1 |
Startup | 1 event, multiple OBs allowed | 1 |
Time delay | Up to 4 events, 1 OB per event | 3-6 |
Cyclic interrupt | Up to 4 events, 1 OB per event | 7-17 |
Hardware interrupt | Up to 50 events, 1 OB per event or 1 OB serves multiple events | 18 |
Time error | 1 event, 1 OB | 22 or 26 |
Diagnostic error | 1 event, 1 OB | 5 |
Pull or plug modules | 1 event, 1 OB | 6 |
Rack or station failure | 1 event, 1 OB | 6 |
Time of day | Up to 2 events | 2 |
Status | 1 event, 1 OB | 4 |
Update | 1 event, 1 OB | 4 |
Profile | 1 event, 1 OB | 4 |
MC-Servo | 1 event, 1 OB | 25 |
MC-Interpolater | 1 event, 1 OB | 24 |