Testing the CPU reserve of a CX70xx

This example is a test project for testing the CPU reserve of a CX70xx. The included function block FB_Test_CPU_Performance measures the CPU reserve you have with your application. The function block reads the current CPU power and cycle time. The function block then increases the CPU load until the CX7k no longer operates in real time. Then it reduces the load again until a stable real time is reached. The function block then determines the CPU power and the cycle time and offsets them against the time and load taken at the start of the measurement and gives you the delta. Use the function block for test purposes only and not in a real environment.

If the CPU reserve is greater than 20%, you can make the task cycle time faster than the one currently in use. The advantages of a faster task are faster reaction to inputs and, depending on the program content, a faster application. A few milliseconds can add up to increase the output of a machine. A reserve power of 20 % is ideal.

The sources for the sample project can be unpacked here: TC_CX70xx_Test_Performance.zip

Testing the CPU reserve of a CX70xx 1:

Falsified measurement result

If the function block is used in a low-priority task, the result is falsified and the real data cannot be determined. Due to the long measurement, the slow tasks are also taken into account.

  • If possible, always use the function block in the fastest high-priority task.
Testing the CPU reserve of a CX70xx 2:

Loops or program sections not run through during the measurement falsify the measurement

Loops, multiple tasks and thus strongly fluctuating cycle times cause a strongly fluctuating CPU load.

  • Set the TimeOut of the function block to a larger value, because the function block searches for the highest CPU load and then takes longer than with a constant CPU load.
Testing the CPU reserve of a CX70xx 3:

Aborting the measurement

The function block can only be used if there are no real-time violations in your configuration. If the function block reads out real-time violations already at start-up, the function block aborts the measurement.

Information on the function block FB_Test_CPU_Performance:

VAR_INPUT

Name

Type

Description

bExecute

BOOL

A positive edge activates the function block.

tTimeOut

TIME

Time to stop the measurement if exceeded.

VAR_OUTPUT

Name

Type

Description

bBusy

BOOL

The function block is active and working.

bError

BOOL

The function block has an error.

nErrorID

UDINT

ADS error code

nCpuLoadReserve

UDINT

Reserve of CPU in [%]

fCycleTimeReserve

LREAL

Cycle time reserve in [ms]

Development environment

Target platform

PLC libraries to include

TwinCAT v3.1.4024.22

PC or CX (x86, x64, ARM)

Tc2_System (system) >= 3.4.25.0