The third thought of PLC programming: Process oriented

Source: Internet
Author: User

Today's high-level languages are mostly object-oriented, but PLC programming, like earlier Basic/fortran languages, is process-oriented.

The basic process of PLC logic processing is:

1) write the data entered by the external device to the input image area (I).

2) logic processing, including read I area, write Q area.

3) Export the data from the output image area (Q) to the external device.

Among them, 1) and 3) is the PLC internal processing, all the PLC user program only deal with the 2nd part.

This processing method of PLC brings the following 2 characteristics.

Features 1 : OB1 The calling program does not exist concurrently

We know that the PLC user program operates mainly in 2 places: Interrupts and OB1.

In general, the logic processing that can be done in a scan cycle is usually called in OB1, and the programs in OB1 are processed in strict order of invocation.

For example, the CPU scan cycle is 20ms, then a certain ns,cpu will only handle a specific FC/FB/NW.

For example, the 1-station worker presses a 2 button at the same time, and at the PLC level, the event handling of the 2 buttons is sequential.

Therefore, strictly speaking, the PLC does not exist real concurrency.

By using this feature effectively, you can make programming easier.

For example, 1 lines have 30 stations to make call processing, and each station call processing logic is the same, then we can establish a temporary DB, store any one station all the intermediate variables.

The OB1 is processed in the order of the stations, and when the nth station is executed, the value of the intermediate variable of the nth station is recorded in the variable values of the temporary db. When performing to the next station, the temporary DB is rewritten for use in the next-station business process.

Since the PLC only processes a particular station at any one moment, the value of the temporary DB has a strict correspondence with this position, so we do not need to declare the variable in FC because all the variables are defined in the temporary DB.

This kind of processing can make the program more concise and universal, less variable, can be used FC disguised to achieve the function of FB.

features 2 : Subsequent assignment overrides the previous assignment

The high-level language is output when it meets the conditions, and the PLC only outputs after all logic processing is complete, and outputs only the last value written.

For example, in the same scan cycle, the first execution of the q0.0=0, after the execution of Q0.0=1, because in the process of execution, the data is still stored in the output image area, This 2-step operation equates to a 2 assignment of the Q0.0 image area during the same scan cycle, overwriting the previous assignment with a subsequent assignment, so OB1 eventually assigns a value of Q0.0 to 1 and then outputs this value to the external device.

We use this feature when programming to reduce some of the computational processing of comparisons.

For example, a station press the button 1 is bright yellow light (red light off), press the button 2 is a red light (yellow light off), while pressing the red light (yellow light off).

That is to say, the level of button 2 is higher in terms of business.

Relative, we can first write button 1 processing logic, and then write button 2 processing logic, when 2 buttons are pressed, according to the characteristics of the PLC, the CPU only output button 2 processing results, so we do not need to write a comparison program.

Third thought of PLC programming: process-oriented

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.