Sampling Trace

Sample tracing means that the progression of values for variables is traced over a certain time frame. These values are written in a ring buffer (trace buffer). If the memory is full, then the "oldest" values from the start of the memory will be overwritten.
As a maximum, 20 variables can be traced at the same time. Since the size of the trace buffer in the PLC has a fixed value, in the event of very many or very wide variables (DWORD), fewer values can be traced.
In order to be able to perform a trace, open the object for a Sampling Trace in the Ressources register card in the Object Organizer . After this, you must enter the trace variables to be traced. (See "Extras" "Trace Configuration".)
After you have sent the configuration with "Define Trace" to the PLC and have started the trace in the PLC ("Start Trace"), then the values of the variables will be traced. With "Read Trace", the final traced values will be read out and displayed graphically as curves.

'Extras' 'Trace Configuration'

With this command you will be given the dialog box for entering the variables to be traced, as well as diverse trace parameters for the Sampling Trace.

Sampling Trace 1:

Dialog Box for Trace Configuration

The list of the Variables to be traced is initially empty. In order to append a variable, then the variable must be entered in the field under the list. Following this, you can use the Add button or the <Enter> to append the variable to the list. You can also use the Input Assistant.
A variable is deleted from the list when you select the variable and then press the Delete button.

A Boolean or analogue variable can be entered into the field Trigger Variable. The input assistance can also be used here. The trigger variable describes the termination condition of the trace. In Trigger Level you enter the level of an analogue trigger variable at which the trigger event occurs. When Trigger edge positive is selected the trigger event occurs after an ascending edge of the Boolean trigger variable or when an analogue variable has passed through the trigger level from below to above. Negative causes triggering after a descending edge or when an analogue variable went from above to below. Both causes triggering for both descending and ascending edges or by a positive or negative pass, whereas none does not initiate a triggering event at all.
Trigger Position is used to set the percentage of the measured value which will be recorded before the trigger event occurs. If, for example, you enter 25 here then 25 % of the measured values are shown before the triggering event and 75% afterwards and then the trace is terminated. The field Sample Rate is

With the Time per Scan field, you can specify the time between two scans in milliseconds. The default setting "0" means one scanning procedure per cycle.
Select the mode for recalling the recorded values: With Single the Number of the defined samples are displayed one time. With Continuous the reading of the recording of the defined number of measured values is initiated anew each time. If, for example, you enter the number ‘35’ the first display contains the first measured values 1 to 35 and the recording of the next 35 measured values (36-70) will then be automatically read, etc.. Manual selection is used to read the trace recordings specifically with ’Extras‘ ‘Read trace'.

The recall mode functions independently of whether a trigger variable is set or not. If no trigger variable is set the trace buffer will be filled with the defined number of measured values and the buffer contents will be read and displayed on recall.

The button Save is used to store the trace configuration which has been created in a file. The standard window ”File save as” is opened for this purpose.

Stored trace configurations can be retrieved using the button Load. The standard window ”File open” is opened for this purpose.

Sampling Trace 2:

Please note that Save and Load in the configuration dialog only relates to the configuration, not to the values of a trace recording (in contrast to the menu commands ‘Extras’ ‘Save trace’ and ‘Extras’ ‘Load trace’).
If the field Trigger Variable is empty, the trace recording will run endlessly and can be stopped by 'Extras' 'Stop Trace'.

'Extra' 'Start Trace'

With this command the trace configuration is transferred to the PLC and the trace sampling is started in the PLC.

'Extra' 'Read Trace'

With this command the present trace buffer is read from the PLC, and the values of the selected variables are displayed.

'Extra' 'Auto Read'

With this command the present trace buffer is read automatically from the PLC, and the values are continuously displayed. If the trace buffer is automatically read, then a check is located before the menu item.

'Extra' 'Stop Trace'

This command stops the Sampling Trace in the PLC. Before a new trace, the trace definition must be loaded, and the trace must be run again.

Selection of the Variables to be Displayed

The comboboxes to the right, next to the window for displaying curves trace variables defined in the trace configuration. If a variable is selected from the list, then after the trace buffer has been read the variable will be displayed in the corresponding color (Var 0 green, etc.). Variables can also be selected if curves are already displayed.
A maximum of up to eight variables can be observed simultaneously in the trace window.

Sampling Trace 3:

Sampling Trace of Eight Different Variables without a Trigger

If a trace buffer is loaded, then the values of all variables to be displayed will be read out and displayed. If no scan frequency has been set, then the X axis will be inscribed with the continuous number of the traced value.
The status indicator of the trace window (first line) indicates whether the trace buffer is full and when the trace is completed. If a value for the scan frequency was specified, then the x axis will specify the time of the value. The time is assigned to the "oldest" traced value. In the example, e.g., the values for the last 25 seconds are indicated.
The Y axis is inscribed with integer values. The scaling is laid out in a way that allows the lowest and the highest value to fit in the viewing area. In the example, Var5 has taken on the lowest value of 6, and the highest value of 11: hence the setting of the scale at the left edge.
If the trigger requirement is met, then a vertical dotted line is displayed at the interface between the values before and after the appearance of the trigger requirement.
A memory that has been read will be preserved until you change the project or leave the system

'Extras' 'Cursor Mode'

The easiest way to set a cursor in the monitoring area is to click there with the left mouse button. A cursor appears and can be moved by the mouse. At the top of the monitoring window the current x-position of the cursor is displayed. In the fields next to 'Var 0', 'Var 1', ..., 'Var n' the value of the respective variable is shown.
Another way is the command 'Extras' 'Cursor mode'. With this command two vertical lines will appear in the Sampling Trace. First they are laying one on the other. One of the lines can be moved to the right or to the left by the arrow keys. By pressing <Ctrl>+<left> or <Ctrl>+<right> the speed of the movement can be increased.
If the mouse pointer is located in the graphics window and the left mouse button is pressed, then the cursor will likewise be displayed.

If additionally the <Shift> key is pressed, the second line can be moved, showing the difference to the first one.

'Extras' 'Multi Channel'

With this command you can alternate between single-channel and multi-channel display of the sampling trace. In the event of a multi-channel display, there is a check in front of the menu item. The multi-channel display has been preset. Here the display window is divided into as many as eight display curves. For each curve the maximum and the minimum value are displayed at the edge. In a single-channel display, all curves are displayed with the same scaling factor and are superimposed. This can be useful when displaying curve abnormalities.

'Extras' 'Y Scaling'

With this command you can change the preset Y scaling of a curve in the trace display. In the dialog box specify the number of the desired curve (Channel) and the new maximum (maximum y scale) and the new minimum value (minimum y scale) on the y axis. By doubleclicking on a curve you will also be given the dialog box. The channel and the former value are preset.

Sampling Trace 4:

Dialog Box for Setting the Y Scale

'Extras' 'Stretch'

With this command you can stretch (zoom) the values of the sampling tracethat are shown. The beginning position is set with the horizontal picture adjustment bar. With repeated stretches that follow one-after-another, the trace section displayed in the window will increasingly shrink in size. This command is the counterpart to "Extras" "Compress".

'Extras' 'Compress'

With this command the values shown for the sampling trace are compressed; i.e., after this command you can view the progression of the trace variables within a larger time frame. A multiple execution of the command is possible. This command is the counterpart to "Extras" "Stretch".

'Extras' 'Save Trace'

With this command you can save a sampling trace. The dialog box for saving a file is opened. The file name receives the extension "*.trc". The saved sampling trace can be loaded again with "Extras" "Load Trace".

'Extras' 'Load Trace'

With this command a saved sampling trace can be reloaded. The dialog box is opened for opening a file. Select the desired file with the "*.trc" extension. With "Extras" "Save Trace" you can save a sampling trace.

'Extras' 'Trace in ASCII-file'

With this command you can save a sampling trace in an ASCII-file. The dialog box is opened for saving a file. The file name receives the extension "*.txt". The values are deposited in the file according to the following scheme:
TwinCAT PLC Control Trace
D:\TWINCAT PLC CONTROL\PROJECTS\TRAFFICSIGNAL.PRO
Cycle PLC_PRG.COUNTER PLC_PRG.LIGHT1
0 2 1
1 2 1
2 2 1
.....

If no frequency scan was set in the trace configuration, then the cycle is located in the first column; that means one value per cycle has been re-corded at any given time. In the other respects, the entry here is for the point in time in ms at which the values of the variables have been saved since the sampling trace has been run.
In the subsequent columns, the corresponding values of the trace variables are saved. At any given time the values are separated from one another by a blank space.
The appertaining variable names are displayed next to one another in the third line, according to the sequence (PLC_PRG.COUNTER, PLC_PRG.LIGHT1).