At the end of this article, there are 55 practical case materials.
Introduction: In the previous article, we completed the “manual control” program of the program framework. In this article, we will continue to write another part of the framework, which is the “alarm program”. We will take the loading and unloading equipment with 3 workstations as an example. The alarm program is mainly divided into two parts: one part is the alarm for the cylinders, and the other part is the alarm for the stepper motors. The alarm can be set to stop the machine based on process requirements. So how do we write this alarm program?

To avoid confusion for those who haven’t read the previous article, let’s introduce the basic framework of the project program, which mainly includes the following aspects:
1.Initialization Program:This is mainly used for the device to return to the initial position, such as cylinders, stepper motors, or servo motors, and to reset some data and flags.
2.Manual-Automatic Switching Program: This is mainly for switching the device between manual, semi-automatic, single-cycle, and fully automatic modes.
3.Manual Control Program: This is mainly for manually controlling cylinders, stepper motors, servos, etc.
4.Automatic Control Program: This mainly controls the operation of the program based on semi-automatic, single-cycle, and fully automatic modes.
5.Alarm Program: Design of alarm programs for cylinders, stepper motors, servos, etc.
6.Product Statistics Program: Used for statistical data of products.
Program Writing
1.Create a new DB data block to store data.

2.Create a new FB2 program block and write the program. Since there are6cylinders, the writing method is the same. We use parameterizedFBblocks, which makes it more efficient.
(1)Define interface variables.

(2)Program segment1is to convert the time set on the touch screen fromREALdata type toDINTdata type for timer usage.
Program segment2is when the cylinder is not in motion, if the origin sensor on the cylinder does not detect a signal within the set time, it will trigger an alarm.
Program segment3is when the cylinder is in motion, if the moving point sensor on the cylinder does not detect a signal within the set time, it will trigger an alarm.


(3)Create a new FB1 program block and write the program.
(1)Program segment1is for the loading gripper cylinder. Since the gripper cylinder does not have an origin sensor, only a moving point sensor is present, it is directly connected to the “cylinder origin” pin, thus masking the origin sensor alarm. The moving point sensor is assigned theI0.0address, outputting2alarm bits, which are the0and1bits of the “cylinder alarm word”.
Program segments2and3are for the forward cylinder and the up-down cylinder, respectively, with parameters assigned accordingly.
Program segment4works on the same principle as program segment1.




Program segment5checks if any cylinder has an alarm, and if so, outputs the alarm flag, which can be used for stopping the machine.

Program segment6checks the angle value of the loading stepper motor. If it is less than-2or greater than185degrees, it is considered to have exceeded the stroke, and the alarm bit is activated.
Program segment7indicates that the loading and turntable stepper motors are returning to the origin with an alarm prompt.
Program segment8checks if there are any alarms from the stepper motors, which can be used as a stop flag.
Recently, many friends have requested case books, saying that reading articles on mobile phones is not very convenient. I have taken the time to organize all 55 practical cases, which are quite typical, including cylinder control programs, alarm programs, program frameworks, motion control program encapsulation, analog control of frequency converters, communication, and other practical cases.If you need them, you can add me on WeChat: biao467524527. If you can’t add me, you can send me a private message.


Previous Recommendations
Quickly bookmark: Siemens full series software and manuals (including touch screens, PLCs, frequency converters, drives, etc.)
Simple filtering program for analog quantities, easy to learn!
To learn 1200 PLC programming, you must know these 12 questions!!
Classic industrial control case: Two programming thoughts on motor sequential start and stop collision!!
PLC analog temperature measurement program is surprisingly simple? Learn it in 3 minutes!
What are the differences between the 3 loop statements in SCL language?
5 examples to help you thoroughly master the IF statement in SCL language.
How to measure the execution time of a PLC program.
Using UDT data programming, efficiency increases by 3 times!!
Learn Modbus TCP communication program writing with just one case.
Learn how to communicate between PLC and G120 frequency converter via Profinet in one go.
90% of PLC engineers do not understand the indirect addressing technique of PLC, this article clarifies it!
Understand the usage of PLC subroutine programming in one article.
How to write programs for timed start and stop of devices in PLC?
How to change the function of PLC input and output points on the touch screen.
PLC addressing that confuses 80% of beginners is actually very simple!
How to display the status of 100 IO points on one touch screen page.
Usage and techniques of PLC recipe functions.
What is a structure in PLC? How to use it?
Data types that electrical engineers are using!!!