5 Tips on How to Reduce Scan Time Using Ladder Logic - Part 2
In part 2 on how to reduce scan using Ladder Logic, we will examine the remaining three of our five general tips on how to minimize PLC scan cycle time with ladder logic programming. We will provide examples of each case as we did for the first two tips we discussed in Part 1 of this blog. These last three tips will are often considered to have the most significant impact on scan cycle times.
To review, in part 1 we identified the following 5 Tips for reducing scan time and began examining examples of each:
1. Place instructions/conditions that are most likely to be false at the start of a rung.
2. Avoid duplicating unique tag/instruction combinations when creating ladder logic programs whenever possible.
In Part 2 we review a simple example for each of these last three tips:
3. Program flow control can be key to significant reductions in scan time. Use the JMP and LBL instructions to reduce the active segments of a running program.
4. Compartmentalizing tasks (making modular processes) and organizing them can have significant impact on scan time. Passing variables can allow for program segments (subroutines) to be used in multiple instances.
5. Avoid floating point arithmetic and try to use integers wherever possible. If you need better than integer precision, consider multiplying all your floats by 10, 100, or 1000 to get integers.
Examples of the remaining scan cycle time reduction tips:
3. Use the JMP and LBL instructions to reduce the volume of program code being executed during each scan cycle.
Program flow is an area in which significant reduction in scan time is possible.
In the example below, the motor 2 and motor 3 rungs are skipped over when the “Enable_Jump” contact is closed on rung 1. At that time, the JMP instruction is encountered and program execution jumps to the “Label_1” LBL instruction location on rung 4 skipping over rungs 2 and 3. This concept can be used to jump over large portions of a program that are not being used at any given time in a production cycle. This has the potential to greatly reduce the number of rungs being scanned and subsequently can significantly reduce an applications scan cycle time.
The ability to skip over rungs is not the only way that the JMP and LBL instructions can be utilized to reduce scan cycle time. Suppose you are monitoring a series of inputs for specific changes in state, and that the nature of these state changes will determine what series of actions will consequently occur. In a situation such as this, creating a program loop to execute only the rungs needed to monitor the inputs will ensure that scan cycle time is not a deterrent to providing rapid responses to any input state changes.
This is often accomplished by creating a “zone” that is defined by the location of the JMP and LBL instructions in your program. This zone is scanned from top to bottom and then program execution loops back to the start of the defined zone again. This will continue until an exit condition allows program execution to resume outside the loop. It is obvious that these techniques can have significant impact on the scan cycle and that program flow management using the JMP and LBL instructions can be a powerful tool providing a degree of control over scan cycle times.
4. Compartmentalizing tasks using subroutines to allow for program segments to be used in multiple instances.
In keeping with the concept that scanning less rungs will reduce overall scan cycle time, the use of the JSR, SBR and RET program flow instructions and their impact on scan cycle times always merits consideration. Creating reusable atomic program segments for functions that get repeated at different times in a process allows these program segments to get called only as needed and will significantly reduce the number of rungs being scanned as this avoids needless duplication. As a simple example, consider a routine that requires the average of two values in several calculations being made. Creating a subroutine that can be called in more than one circumstance avoids the need to duplicate any of the instructions needed to find an average value. Values are passed into the routine and a result is passed out as shown below:
The JMP and LBL instructions allow you to focus on a segment or skip over segments. The JSR and RET subroutine instructions allow program segments to be used multiple times instead of creating multiple instances of them. The program flow instructions are great tools for managing scan cycle times.
5. Avoid floating point arithmetic and try to use integers wherever possible.
This general practice shortens scan cycle time as the instructions that use the REAL data type take up more memory, use more resources to function and require more cycles than the INT data type variables. As an example, suppose we have an analog input signal ranging from 0 to 10 volts and the sensor is providing 2 decimal places of accuracy. A value such as 8.34 V would be an example of the type of input coming to the analog input channel. Multiplying the value by 100 will remove the decimal portion of the value and create a whole number that can be used with the INT data type. It can be said that in general it is beneficial to work with INT or DINT data types when doing math operations by scaling values at the input of output point of a process. An analog output control signal should be generated using INT or DINT data types and converted to a REAL value, within output range, just prior to being sent out when at all possible.
This program segment takes an analog input value between 0.00 and 10.00 and converts it to a whole number value ranging from 0 to 100. This scaled value can be operated on using DINT data type variables at that point. The value is being scaled back to the 0 to 10 range before being sent to an output module location.
Scan cycle time is an application parameter that can have varying significance to a process. In instances where scan time is critical, knowing ways to reduce its impact on an application can be extremely helpful. Following these 5 tips on reducing scan cycle time and they will help you to manage this parameter in cases where it may be critical to normal operation.
We hope that this has been helpful as a student or practicing PLC technician. If you have any questions regarding the PLC Technician program, feel free to get in touch with us at [email protected] or give us a call at 1-888-553-5333 to speak with a Program Consultant.