Description This entry describes a small sample program for extracting the places before and after the decimal point. For example, "87" is filtered out as number before the decimal point from the real value 87.125 and provided for further processing.
Fig. 01
The "Decimal_place_filter" block (FC2) contains the "Real value" input and the two output parameters "Before decimal point" of the data type "Dint" and the "After decimal point" of the data type "Real".
Fig. 02
Fig. 02 shows the program for filtering the place before and after the decimal point in the "Decimal_place_filter" block (FC2).
The value of the "Real_Value" variable is buffered in the temporary variable "Xc" with the "MOVE" instruction.
With the "TRUNC" conversion the real value is converted into the Dint data type. The number 87.125 then becomes Xint = 87.
The value from Xint is transferred to the output variable of the data type DInt and output as number before the decimal point.
The next converter "CONV" converts the data type back to Real. The number 87 then becomes Xreal = 87.0.
The subsequent subtraction differentiates the decimal places from the input variable.
Decimal places = Real value - Xreal = 87.125 - 87.0 = 0.125.
Note
For other applications also note the calculation accuracy of the real values: For further details, go to Entry ID: 14844391.
Creation environment The screens in this FAQ response were created with STEP 7 (TIA Portal) V11+SP2.
Additional Keywords
Decimal point portion
How do you calculate the linear values for the y-coordinate of point P in STEP 7 (TIA Portal) V11?
Description With the coordinates (x0,y0) and (x1,y1) you determine the characteristic of a line and with the x parameter you specify a value on the x-axis. The output value for y is an integer in the range of -27648 to +27648. The function FC42 "Linear" calculates the relevant y-coordinate value on this line.
Fig. 01
The y-coordinate of point P is calculated according to the following formula:
y1 - y0
y =
-----
-----
*
(x - x0)
+ y0
x1 - x0
The "Linear" function is called and parameterized in OB1 "Main". Table 01 below includes an overview of the input and output variables and their functions:
Parameter
Interface
Data type
Description
X0
Input
Real
x-coordinate point P0
Y0
Input
Real
y-coordinate point P0
X1
Input
Real
x-coordinate point P1
Y1
Input
Real
y-coordinate point P1
X
Input
Real
x-coordinate of random point P
Y
Output
Int
y-coordinate of random point P
Table 01
Download
The attached download "STEP7_V11_Linear" contains a STEP 7 project with the blocks described above including the German and English comments. Copy the "STEP7_V11_Linear.zip" file into a separate directory and then start the file with a double-click. The STEP 7 project is now unpacked automatically with all the associated subdirectories. You can then use STEP 7 V11 to open and process the extracted project.
Description The STEP 7 (TIA Portal) V11 program "STEP7_V11_Totalizer" includes the "Totalizer" function block which you can use to add up values measured within a time unit to a total value. For example, for using units of measurement for linear velocity or for volumetric magnitudes. You can use distances or volumes as physical magnitudes and milliseconds, seconds, minutes, hours or days as units of time measurement.
Fig. 01
Table 01 below includes a list of the input and output variables of the "Totalizer" function.
Parameter
Variable
Data type
Description
Input
Value
Real
Measured value in a time interval
Input
Interval
Time
Time interval of the measurement
Input
Cycle
Time
Sampling time
Input
Reset
Bool
Reset of the "Total" output
Output
Total
Real
Accumulated total output value
Table 01
In a cycle
The values of the input variables "Interval" and "Cycle" of the data type Time are converted into the data type Real.
The converted values are then transferred to the temporary variables "Interval_real" and "Cycle_real".
The input value of the variable "VALUE" is multiplied by the value of the temporary variable "Cycle_real" and then divided by the value of the temporary variable "Interval_real".
The result is then stored in the buffer of the static variable "Accum".
Thus after each cycle the interim result in the "Accum" buffer is incremented by this value, which is also transferred to the output variable "Total". If the "Reset" variable has the value "True", the output value of the "Total" variable is reset to zero.
Example:
In the example as in Fig. 01 the "Value" variable has the value 60.0 and the time value of the "Interval" variable is one minute.
The output variable "Total" is then added up to the values 1 to 60 within the interval, that is to say within one minute.
The cycle time of 100ms reflects the scan time in which the FB "Totalizer" is processed.
When the FB is called in the "Cyclic interrupt", the program is processed in a time interval of 100ms and is independent of OB1 (main).
The associated physical units of the measured value "Value" can be, for example, meters per second, cubic meters per minute or kilograms per hour. For the input variable "Interval" you must enter the interval time for the physical unit, for example,
Meters per second: T#1s
Cubic meters per minute: T#1M
Kilograms per hour: T#1h
Fig. 02
The attached download "STEP7_V11_Totalizer.zip" contains a STEP 7 project with the blocks described above (FB "Totalizer" with instance DB and call in the "Cyclic interrupt" OB). The program contains German and English comments.
Copy the "STEP7_V11_Totalizer.zip" file into a separate directory and then start the file with a double-click. The STEP 7 project is now unpacked automatically with all the associated subdirectories. You can then use STEP 7 V11 to open and process the extracted project.
Description Differentiation in mathematics is the processing of a real function and the increase in tangents in the graphs. However, there is often no mathematical correlation in practice, but rather a value which varies over time, for example.
The present STEP 7 (TIA Portal) V11 program provides the present lead (first derivative) from the actual function value and the previous function value. Following the same principle, the present second derivative is calculated from the current value and the previous value of the first derivative ("lead of the lead").
Example
From a shaft, a signal for each revolution (signal status from "0" to "1") is transferred to a counter "CTU" (counting forward). The duration set in the "Cyclic interrupt" OB is used to calculate the present first and second derivatives of the number of signal after the time. Using the circumference of the shaft in meters you can calculate the present velocity and acceleration of the shaft. Fig. 01 shows the call of the function block in the "Cyclic interrupt" OB.
Fig. 01
The input and in/out parameters of the "Differentiator" FB are listed in the table below.
Input parameter
Data type
Description
Start
Boolean
Start calculation
Time_ms
Int
Cycle time in milliseconds
Count_new
Int
New count value
In/out parameter
Data type
Description
d
Real
1. Derivative of count value after time
dd
Real
2. Derivative of count value after time
Table 01
The "Differentiator" function block is started with the "Start_Reset" variable. If the "Start_Reset" variable receives the "False" signal, the values of the first and second derivatives and the counter are reset to zero. If the last value has to continue to be available after recording, the "EN" input of the "Differentiator" FB must be disabled in OB1. The data is retained in the instance data block and can be used again.
Download The attached download "STEP7_V11_Differenzierer" contains the STEP 7 V11 project with the blocks described above. Copy the "STEP7_V11_Differenzierer.zip" file into a separate directory and then start the file with a double-click. The STEP 7 project is now unpacked automatically with all the associated subdirectories. You can then use STEP 7 to open and process the extracted project.
Description In STEP 7 (TIA Portal), you can use the conversion functions from the "Instructions" and "Advanced Instructions" palettes to convert the contents of the variables to selected data types for the S7-1200/1500. Fig. 01 gives you an overview of the most used conversions.
Fig. 01
Conversion of data types INT, DINT, REAL and BCD numbers
STEP 7 (TIA Portal) provides the operation "CONV" (convert) to convert the data types INT, DINT, REAL and BCD numbers. Proceed as described in the table below to insert and parameterize this operation in your block editor.
No.
Procedure
1
In the block editor, open the "Instructions" palette and open the "Converters" folder. Then use drag-and-drop to insert the "CONVERT" instruction into your network.
2
After inserting the instruction box, the instruction data types are still not defined and under "CONV" you still see the wildcard characters "??? to ???". When you move the cursor over the left triangle of the first three question marks, an arrow key is displayed.
3
Click the left arrow key and from the drop-down menu that opens you select the desired data type for the input parameter "IN" (INT, for example).
4
Repeat the procedure for the output parameter "OUT" and from the drop-down menu on the right you select the data type to which you wish to convert the number value (REAL, for example). In this example you can convert a number value of the data type INT into the data type REAL ("Int to Real").
Note
If you parameterize the input and output parameters directly with the variables, the instruction is defined automatically with the associated data types and Steps 2 to 4 above are not necessary.
5
Parameterize the inputs and outputs of the converter with the variables of your choice. After parameterizing the inputs and outputs you can convert the number values below, for example.
From INT to INT, DINT, REAL, BCD16, USINT, UINT, UDINT, SINT, LREAL and CHAR.
From DINT to INT, DINT, REAL, BCD32, USINT, UINT, UDINT, SINT, LREAL and CHAR.
From REAL to INT, DINT, REAL, USINT, UINT, UDINT, SINT and LREAL.
From UINT to INT, DINT, REAL, USINT, UINT, UDINT, SINT, LREAL and CHAR.
From UINT to INT, DINT, REAL, USINT, UINT, UDINT, SINT, LREAL and CHAR.
From UDINT to INT, DINT, REAL, USINT, UINT, UDINT, SINT, LREAL and CHAR.
From UINT to INT, DINT, REAL, USINT, UINT, UDINT, SINT, LREAL and CHAR.
From LREAL to INT, DINT, REAL, USINT, UINT, UDINT, SINT and LREAL.
From CHAR to INT, DINT, USINT, UINT, UDINT, SINT and CHAR.
From BCD16 (16-bit) to INT.
From BCD32 (32-bit) to DINT.
Note
A number value in the BCD format must first be converted into the data type INT or DINT before you can convert it into the data type REAL, for example.
Fig. 02
Table 01
Rounding of REAL numbers
The instructions below are available for you to round a number value of the data type REAL to a whole number (INT or DINT). These instructions are in the "Converters" folder as described above.
"CEIL": rounding up to the next whole number
"FLOOR": rounding down to the next whole number
"ROUND": rounding to the next whole number
"TRUNC": no rounding.
Conversion of STRING data types
The table below contains three advanced instructions from STEP 7 (TIA Portal) for converting the STRING data type into a numerical value and vice versa. The procedure for programming this is identical to that described in Table 01.
Advanced Instructions
Description
S_CONV
A digit string (STRING) is converted into a number value or a number value is converted into a digit string (STRING).
Convert the STRING data type to USINT, SINT, UINT, INT, UDINT, DINT, CHAR, LREAL and REAL.
Convert the USINT, SINT, UINT, INT, UDINT, DINT, CHAR, LREAL and REAL data types to STRING.
Copy a character string (STRING to STRING).
STRG_VAL
Convert a digit string into the relevant whole number or floating point display.
VAL_STRG
Convert a whole number value with or without sign or a floating point value into the relevant digit string display.
Table 02
Conversion into the TIME data format Using the advanced instruction "T_CONV" you convert a numerical value of the DINT data type into a time stamp (TIME) and vice versa. You must convert all other data types (INT, REAL, BCD, ...) into the DINT data type before you can convert them into the TIME data type. The "T_CONV" instruction is located in the block editor in the "Advanced Instructions >Date and Time"" palette. Fig. 03 shows an sample conversion of INT and REAL number values into the TIME data format.
Fig. 03
Further Information
More information on programming and parameterizing the instructions mentioned above is available in the STEP 7 (TIA Portal) Online Help. To obtain the Online Help you mark the instruction and press the "F1" key.
Creation environment
The screens in this FAQ response were created with STEP 7 V11.0+SP2.
How can you convert a hexadecimal number into ASCII characters with STEP 7 (TIA Portal) V11?
Description The STEP 7 (TIA Portal) V11 program "STEP7_V11_Hex_ASCII" converts a hexadecimal number into ASCII characters. The two functions "DataCalc" and "HexAscII" store the separate characters in ASCII format in data block DB1. These variables of the data type "Char" have a length of one byte.
The "DataCalc" converts the data byte for byte from the hexadecimal format into the ASCII format.
The "HexAscII" function is for the byte-for-byte preparation for data type conversion with the FC "DataCalc" and for saving the data in DB1.
The FC "DataCalc" is called once in the FC "HexAscII" for each conversion to the character type "CHAR".
Fig. 01
Fig. 01 shows an example of how the control value "ABC1 23DE" (hexadecimal format) and the individual characters in ASCII format are stored in DB1. The attached download contains an archived STEP 7 V11 project with the STEP 7 program described above including the German and English comments.
Copy the "STEP7_V11_Hex_ASCII.zip" file into a separate directory and then start the file with a double-click. The STEP 7 project is now unpacked automatically with all the associated subdirectories. You can then use STEP 7 V11 to open and process the extracted project.
Description The STEP 7 (TIA Portal) V11 program "STEP7_V11_Bit_Field_Pos" includes two functions that you can use to determine the bit position of an active bit in a marker word and monitor a 32-bit field for incoming and outgoing events.
Evaluation of the bit position of the active bit in a marker word The "Bit_Pos" function calculates the active bit in a marker word. If, for example, you program a sequence control in a marker word for a sequential process, then in this marker step word only one bit is ever active corresponding to the currently active step of the sequencer. Using the bit count you can visualize the active step as plaintext via symbol lists in a visualization system, for example. For visualization it is better to receive the bit position and thus the currently active step as an integer value.
Fig. 01
When just one bit is always set, this yields the following correlation:
2X = Y
X = lnY / ln2
Here X is the bit position and Y is the value of the marker word. For the bit position you must increment X by 1. In addition, the "Bit_Pos" function takes into account the two special cases where the value Y must not be zero or negative (sign).
Monitoring of a 32-bit field
In order to monitor a 32-bit field for incoming and outgoing events, you can use the "Monitor_Bit" function to query the bits to be monitored for positive and negative edges. However, just as in the example described above, a double-word is defined here as DINT and the set bit is calculated.
Programming in the "Monitor_Bit" function is implemented as follows:
In order to filter out from any number of bits set the bit that has changed its status in this cycle you use an EXCLUSIVE OR DOUBLE WORD operation between the value of the last cycle and that of the current cycle. An EXCLUSIVE OR yields only that bit which occurs exclusively for one of the two values.
Using another AND query you determine whether that bit is an incoming or outgoing signal.
If only one bit is set for this double integer, then the definition described above applies for the DI value Y. You obtain the X value from this conversion: X = lnY / ln2 and the bit position is yielded with the increment: X + 1.
Note
You can determine the incoming and outgoing events for Bits 1 to 31 arbitrarily, which applies for the value range of 0 to +2147483647. Bit 32 is valid for the sign. If Bit 32 receives the signal status 1, the number for the set Bit 32 is output ("Bit" output) and the bit for the "Event_Come" output (for incoming event) is set. However, if you continue to use the function and want to determine more incoming and outgoing events, you must reset Bit 32 to zero beforehand.
Fig. 02
In the example in Fig. 02 the signal status at Bit 16 has changed from 0 to 1. The determined bit no. 16 is output at the "Bit" output and the "Event_Come" output receives the True signal (for an incoming event).
Copy the "STEP7_V11_Bit_Field_Pos.zip" file into a separate directory and then start the file with a double-click. The STEP 7 project is now unpacked automatically with all the associated subdirectories. You can then use STEP 7 V11 to open and process the extracted project. The two functions include German and English comments.
Creation environment
The screens and download in this FAQ response were created with STEP 7 (TIA Portal) V11. The following table lists the components that have been used to create this entry and verify the functions described.
Test environment
Version
PC platform
Intel(R) Core(TM)2 Duo CPU P8700 2.53 GHz
PC operating system
MS Windows XP SP3
STEP 7 (TIA Portal)
V11 + SP2
CPU 1214C (6ES7214-1AE30-0XB0)
Firmware V2.0
How can you delay the output signal in relation to the input signal in STEP 7 (TIA Portal) V11?
Description The table below shows two sample programs for delaying the output signals in relation to the input signals in STEP 7 (TIA Portal) V11.
No.
Applications and sample programs
1
The "STEP7_TIA_Portal_V11_DeadTime" download contains function block "DeadTime" (FB22) that outputs an input signal delayed at its output. You must parameterize the input and output variables below for the application of this function.
Input variables
INV: Real data type for the input signal
N_SMP: data type Int for the multiplicator
COM_RST: data type Bool for the Reset
Output variable
OUTV: Real data type for the output signal
In order to have the program processed in a time interval, you have the "DeadTime" function block called in a "Cyclic interrupt" OB (OB200). In each such a time interval the input signal is buffered in the static variable "STORE" of the data type "ARRAY[1..20] of REAL". With the "N_SMP" parameter you define the number of data memories of the ARRAY variable so that at each time interval the signal is transferred from one data memory to the next. Once the last defined data memory is reached the signal is then copied to the output variable "OUTV". You can define up to 20 data memories. The separate time intervals between transfer into the data memories is a measure for the time delay.
Fig. 01
Example
The signal of the input variable "INV" should be delayed one second in the function block before it appears at the output parameter "OUTV". The default value for the time base with the "Cyclic interrupt" OB is 100ms. The multiplicator at the input variable "N_SMP" must therefore have the value 10.
Download
The attached download "STEP7_TIA_Portal_V11_DeadTime" contains a STEP 7 (TIA Portal) V11 project with the blocks described above including the German and English comments. Copy the "STEP7_TIA_Portal_V11_DeadTime.zip" file into a separate directory and then start the file with a double-click. The STEP 7 project is now unpacked automatically with all the associated subdirectories. You can then use STEP 7 V11 to open and process the extracted project.
With the "StepZero" function you define the zero step in which the input signal is transferred once delayed to the output at a specific point in time. The input and output variables below are contained in the "StepZero" function.
Input variables
Tzero: Data type DTL for input of the zero step time
INV: Real data type for the input signal
Output variable
OUTV: Real data type for the output signal
The CPU time is read out by way of the advanced instruction "RD_SYS_T" of STEP 7 V11 and compared with the zero step time at the "Tzero" parameter. The determined time of day of the CPU is transferred to the DB variable "DBStore1.DateTimeCPU" and the input of the zero step time is via the DB variable "DBStore1.DateTimeSet". The runtime for the zero step (output without signal) is calculated and the output is controlled delayed according to the conditions below.
DBStore1.DateTimeCPU < Tzero: OUTV = 0.0
DBStore1.DateTimeCPU = Tzero: OUTV = INF
DBStore1.DateTimeCPU > Tzero: OUTV = INF
Example
The time "T#2010-12-1-11:10" has been chosen for the end of the zero time step at the "Tzero" parameter. The output signal of the "OUTV" variable is zero until the value of the DB variable "DBStore1.DateTimeCPU" reaches the time 11:10 hours on 1.12.2010. As of that time the output signal is identical to the input signal.
Fig. 02
Download
The attached download contains the functions described above with the German and English comments. Open and copy the "STEP7_TIA_Portal_V11_StepZero.zip" file into a separate directory. The STEP 7 project is now unpacked automatically with all the associated subdirectories. You can then use STEP 7 V11 to open and process the extracted project.
Instructions You can use the SCALE_ X "Scale" and NORM_X "Normalize" converters to scale analog values. These blocks are located in STEP 7 V11 in the "Statements" palette under "Converters". A detailed description of the function and parameterization is available in the STEP 7 V11 Online Help. To obtain the Online Help for a block, mark the block concerned (SCALE_X, for example) and press the "F1" key.
In the following examples it is assumed that the measuring ranges are unipolar. The integer input value is then between 0 and 27648.
Example 1
The integer value 27648 corresponds to a current value of 20 mA and the integer value 0 corresponds to a current value of 0 mA. The upper and lower limits are MAX=27648 and MIN=0 for normalization and MAX=20 and Min=0 for scaling. Since the input values are of the Integer data type and the output values are scaled as Real data type, the NORM_X function converts the data type from Integer to Real.
Fig. 01
The connection of the two blocks as in Fig. 01 results in the following definition between the input value of the NORM_X block and the output value of the SCALE_X block:
NORM_X_VALUE - NORM_X_MIN
SCALE_X_OUT - SCALE_X_MIN
-------------------------------------------
=
-----------------------------------------
NORM_X_MAX - NORM_X_MIN
SCALE_X_MAX - SCALE_X_MIN
If the "VALUE" input of the NORM_X block has the value 10500 and the limit values as in Fig. 01, then the "OUT" output of the SCALE_X block has the value:
10500 - 0
SCALE_X_OUT - 0
-------------
=
-----------------------
27648 - 0
20 - 0
SCALE_X_OUT = 7.5955 (which means 7,5955 mA)
Example 2 - Current measurements
The analog values of 4-20 mA are to be displayed with integer values. Since the input values are of the Real data type and the output values are scaled as Integer data type, the SCALE_X function converts the data type from Real to Integer. The integer value 27648 corresponds to 20 mA (upper limit) and the integer value 5530 corresponds to 4 mA (lower limit). For example, the integer value 10500 is scaled for an analog value of 7.5955 (mA).
Fig. 02
Note
To change the data type conversion for the blocks, mark the block concerned and click on the yellow arrow. You can then select the required data type conversion from the drop-down list that opens. You must then change the parameters, because the data types of the parameters have changed.
Fig. 03
Additional Keywords
Voltage, temperature and resistance measuring, Pressure sensor
How do you copy memory areas in STEP 7 (TIA Portal) V11?
Description Instead of the ANY pointer and the "Block move" function (in STEP 7 V5.x) you can use the "MOVE_BLK" (copy area) instruction in STEP 7 (TIA Portal) V11. It is not possible to use the ANY pointers in STEP 7 V11. If you want to copy the contents of one data block (source area) to another data block (target area), you must create the data blocks with variables of the "ARRAY" data type. Using the ARRAY variables and the "MOVE_BLK" instruction, you can copy parts or the complete memory area from the data block. Unlike with the ANY pointer as in STEP 7 V5.x, you use the "COUNT" parameter to define the number of elements from which you wish to copy data from the source area into the target area.
Note
More information on the topic of "Pointer Addressing" is available in Entry ID: 42603286.
Fig. 01
Figures 01 and 02 show an example of data transfer from DB1 to DB2 between the two variables of data type "Array [1 ... 16] of Byte".
With the index specification [5] of the array variables ("Data_block_1".Array_DB1[5]) at the "IN" parameter, the 5th byte is marked in the source area of DB1.
With the index specification [10] of the array variables ("Data_block_2".Array_DB2[10]) at the "OUT" parameter, the 10th byte is marked in the source area of DB2.
If the "Count_01" variable at the "COUNT" parameter has the value "5",
The contents of the memory areas from Byte 5 to Byte 9 are copied from DB1
into the memory areas from Byte 10 to Byte 14 in DB2.
Fig. 02
The "MOVE_BLK" command is located in the block folder in the "Instructions" palette:
Either in the "Instructions > Move" folder or
You drag-and-drop the "Empty box" from the "Instructions > General" folder into your network. Move the cursor on the yellow triangle in the empty box until the symbol for opening the drop-down list appears and from the drop-down list you select the "MOVE_BLK" command.
More information is available in the STEP 7 (TIA Portal) Online Help under "MOVE_BLK: Copy area".
Creation environment The screens in this FAQ were created with STEP 7 (TIA Portal) V11.
How in STEP 7 V11 can you access the unstructured data types bit-by-bit, byte-by-byte or word-by-word and symbolically?
Description In the case of S7-1200 modules (as from firmware V2.0) you have the option of accessing bit-by-bit the tags of the Byte, Word and DWord data types. For this you need STEP 7 V11+SP1+Update 2 (or higher). The partitioning of a memory area (Byte or Word, for example) into a smaller memory area (Bool, for example) is also called memory slicing. Fig. 01 shows the symbolic bit, byte and word access to operands.
Fig. 01
Using slice access provides you with greater programming efficiency and there is no need for additional definition in the variable declaration.
The example below shows bit-by-bit symbolic slice access. The "x" stand for bit-by-bit access in the word or byte concerned and the number that follows specifies the offset of the bit concerned.
Fig. 02
Fig. 03 shows a sample byte-by-byte slice access. Here, the "b" stands for byte-by-byte access and the number that follows specifies the offset of the byte concerned.
Fig. 03
A "w" stands for word-by-word slice access and the number that follows specifies the offset of the word concerned.
Fig. 04
Keywords
Slice access
How do you program the overlapping of tags with the keyword "AT" in the TIA Portal V11?
Description With the "AT" keyword you can overlap a declared tag with another declaration if, for example, you want to access the separate bits of a tag of the Word data type with an Array of Bool. The processing time of this configuration is significantly shorter than with the data type conversion in earlier versions of STEP 7. Note also the following restrictions in this case:
The tags can be overlapped in S7-1200 if the modules of the S7-1200 have firmware version V2.0 (or higher).
With the modules of S7-300/400 it is only possible to overlap tags in S7-SCL.
You need at least STEP 7 V11.0+SP1+Update 2 (or higher).
It is only possible to overlap tags in the interface of code blocks with standard access.
It is no longer possible to change the "Optimized block access" attribute after creating a new block.
It is possible to overlap tags from all types of code block and all declaration segments (Input, Output, InOut, Static, Temp).
Overlapping tags must be equal or less than the overlapped tag and may be used in the block like any other tag.
You cannot overlap tags of the VARIANT data type.
Fig. 01
You program overlapping of tags in the block interface of a function or function block. Proceed as described in the table below to declare the tags.
No.
Procedure
1
In the Temp area of the declaration table you enter first the tag that you wish to overlap with a new data type.
For example: Name: "t_word", data type: "Word".
2
Mark the line with the tag to be overlapped and right-click.
3
In the pop-up menu that opens you select "Add Line". You must declare the overlapping tag in the line directly under the tag to be overlapped.
4
Enter the name of the tag in the added line.
For example: "t_bool".
5
In the "Data type" column you enter first just the letter "A" and wait until the window opens with the data types you can select.
6
In the drop-down menu you select the keyword "AT" and then click in the "Name" column. In addition to the name of the tag ("t_bool", for example) the keyword with the tag to be overlapped is also displayed in the same field.
In this example: AT "t_word".
7
Click again in the "Data type" field and enter the declaration for the array.
For example: "Array[0..15] of Bool".
Now the overlapping of the tags is completely declared and you can enter your program in the editor.
Fig. 02
With some applications, it might be necessary in STEP 7 to group multiple signals in one control word or extract separate signals from a control word. The "STEP7_V11_AT_KeyWord.zip" download attached includes a STEP 7 V11 program with which you can group signals (tags of the "Bool" data type) in a tag of the "Word" data type and extract them again. The following blocks are contained in the STEP 7 program:
Description of the "FC_Bool_to_Word_AT" function
You can use the "FC_Bool_to_Word_AT" function to group up to 16 bits in a word. The separate input tags of the Bool data type are assigned to the temporary "t_bool" array tag and overlapped with the keyword "AT" of the "t_word" tag. Then the content of the temporary "t_word" tag is transferred to the "SaveWord" output tag.
Fig. 03
Description of the "FC_Word_to_Bool_AT" function
Using the "FC_Word_to_Bool_AT" function you can extract up to 16 signals (tags of the "Bool" data type) from a tag of the "Word" data type. The content of the "I_Word" input tag is transferred to the temporary "t_word" tag and overlapped with the keyword "AT" of the declared "t_bool" tag. Then the separate bits of the "t_bool" array tag are assigned to the output tags of the Bool data type.
Fig. 04
These two functions are called and parameterized in OB1 "Main".
Download
Copy the "STEP7_V11_AT_KeyWord.zip" file into a separate directory and then start the file with a double-click. The STEP 7 TIA Portal V11 project is now unpacked automatically with all the associated subdirectories. You can then use STEP 7 TIA Portal V11 to open and process the extracted project.
Alternative 1
You can simply program a pulse encoder using the IEC times of STEP 7 (TIA Portal). Fig. 01 shows the interconnection of the two "TON" instructions (generate switch-on delay) in order to receive a periodic output signal at output A0.1.
Fig. 01
The "Generate switch-on delay" instructions delay the setting of outputs Q by the programmed time PT. The table below explains the function of the pulse encoder.
No.
Function of the pulse encoder
1
The input E0.0 "Release" triggers the pulse encoder.
2
To begin with the marker M0.1 "Out" has the "False" signal so that the time period of the switch-on delay of the lower "TON" instruction is started.
3
When the switch-on delay expires the marker M0.0 "Trig" is set and
the output A0.1 "Trig_Out" receives the "True" signal.
4
The "True" signal at marker M0.0 triggers the time period of the switch-on delay of the upper "TON" instruction.
5
When the second switch-on delay expires the marker M0.1 "Out" is set.
6
The "True" signal at marker M0.1 opens the opener and interrupts the lower "TON" instruction which resets the marker "M0.0".
The output A0.1 "Trig_Out" receives the "False" signal.
7
The "False" signal at marker M0.0 interrupts the upper "TON" instruction and the marker M0.1 is reset.
8
The "False" signal at marker M0.1 retriggers the lower "TON" instruction and the process starts from the beginning again.
Table 01
Fig 02 shows the pulse diagram of the pulse encoder.
Fig. 02
More information about the IEC timer instructions is available in the STEP 7 (TIA Portal) Online Help. For this you mark the instruction and press the "F1" key.
Alternative 2 You can periodically change the binary statuses in the pulse-pause ratio of 1:1 by configuring clock markers.
No.
Procedure
1
Open the device configuration in your STEP 7 project and double-click the S7 CPU module in the Device View.
2
Select the "Properties" tab and click "System and clock memory" in the area navigation.
3
Enable the "Enable the use of clock memory byte" option and enter an address for the clock marker byte; for example, "100" for MB100. This assigns a frequency to each bit of this clock marker byte.
Fig. 03
4
Save and compile the hardware configuration. Then load your program onto the CPU.
5
The frequency of 10Hz is assigned to the marker M100.0 and thus its binary status changes every 0.1 seconds. Fig. 04 shows an example of periodic increment of the value for the operand MD110 at the "IN/OUT" parameter. The link of the comparator with the MOVE instruction limits the value for the operand to 99 and then resets it to 0.
Fig. 04
Table 02
Advantages of Alternative 1
The times for the pulse lengths of the True and False signal can be variable.
In this way you can also program the pulse-pause ratio flexibly.
Advantages of Alternative 2
Little effort required for configuration.
You do not need the IEC timer instructions.
Notes on using clock markers
A clock marker is a marker that changes its binary status periodically in the pulse-pause ratio of 1:1. Since the marker cycle runs asynchronously to the CPU cycle, in long cycles the status of the clock marker can change several times, which leads to distorted perception.
Example:
A clock marker has a period time of 100ms.
The cycle time of the program is 100ms and fluctuates by between plus to minus 10ms.
If the clock marker has the status 1 after several periods, you might get the impression when monitoring that its status does not change around 300ms.
Fig. 05
1) Clock marker changes every 100ms
2) Cycle time: 110ms
3) Cycle time: 90ms
4) Online monitoring of the clock marker
Download The download includes a STEP 7 (TIA Portal) program for the S7-1200 modules, which you can use to generate pulses from the clock marker byte. The edge bits are formed initially byte by byte and then assigned to the outputs bit for bit. You need the following for bit-for-bit and symbolic access to tags of the Byte, Word or DWord data types:
STEP 7 V11+SP1+Update 2 (or higher)
and for the S7-1200 modules the firmware version V2.0 (or higher).
Copy the "STEP7_V11_Slice_Takt.zip" file into a separate directory and then start the file with a double-click. The STEP 7 TIA Portal project is now unpacked automatically with all the associated subdirectories. You can then use STEP 7 TIA Portal to open and process the extracted project.
Description
Using the shift and rotate statements, you can shift or rotate the bits 0 to 32 of an input value by a specific number of bits to the left or right. The table below gives an overview of the shift and rotate statements in STEP 7 V5.5 and V11:
Shit and rotate statements
STEP 7 V5.5
STEP 7 V11
SHR_I
Shift integer (16-bit) to the right
SHR*
Shift to the right
SHL_DI
Shift integer (32-bit) to the left
SHL*
Shift left
SHL_W
Shift 16 bits to the left
*
Shift left
SHR_W
Shift 16 bits to the right
*
Shift to the right
SHL_DW
Shift 32 bits to the left
*
Shift left
SHR_DW
Shift 32 bits to the right
*
Shift to the right
ROL_DW
Rotate 32 bits to the left
ROL*
Rotate left
ROR_DW
Rotate 32 bits to the right
ROR*
Rotate right
* In STEP 7 V11 the statement boxes have a drop-down list box from which you can select the data type (USint, UInt, Word, DWord, Byte, UDint, SInt, Int and DInt) for the statement. Click the statement in the LAD/FDB editor and move the mouse pointer over the field with the three question marks until the "▼" symbol appears. Click the "▼" symbol to open the drop-down list box.
Sample programming with the right shift registers in STEP 7 V5.5 and V11
The two right shift registers in STEP 7 V5.5 and V11 shown below are activated by the positive edge at marker M0.0. The marker word MW40 is shifted by 1 bit to the right and the result is stored in the marker word MW50.
Fig. 01 - "SHR_W": Shift 16 bits to the right in STEP 7 V5.5
Fig. 02 - "SHR": Shift right in STEP 7 V11
Note
More information about shift registers is available in the STEP 7 Online Help. Mark the statement box and press the "F1" key.
What properties do you have to watch out for in STEP 7 V11 when you are inserting characters into a string with the "INSERT" statement?
Description You use the "INSERT" statement to insert characters or character strings at input parameter "IN2" into the character string at input parameter "IN1". The results character string is displayed at the "OUT" output parameter in string format. You have to specify a value at parameter "P" to indicate the position of the character in the string from which you wish to insert the characters.
Fig. 01
You must watch out for the following conditions during the parameterization of the "INSERT" statement.
If the value at parameter "P" is greater than the character string at input parameter "IN1", the characters of input parameter "IN2" are appended after the last character of the character string of input parameter "IN1".
Fig. 02
If the value at parameter "P" is zero, the characters of the input parameter "IN2" are placed before the first character of the input parameter "IN1".
Fig. 03
If there is a negative value at parameter "P", a blank character string is also displayed at the "OUT" output parameter.
Fig. 04
If the results string is longer than the length of the string variable defined at the "OUT" output parameter, the string is limited to the available length.
Fig. 05
Example
You can also use the "INSERT" statement to copy string variables. Fig. 06 illustrates an example for transferring a five-character string in which one of the characters changes ("abcde" => "abxde").
Adapt the length of the string variable precisely to the length of the character string which you wish to transfer (for example, String[5]).
The character string at parameter "IN2" must be identical to the character string at parameter "IN1".
Delete the first character in the string at parameter "IN2" and
Change the character that you wish to exchange for the character string to be transferred (for example, "x").
Fig. 06
With the definition "P=1", the character string at parameter "IN2" is inserted behind the first character of the string at parameter "IN1", which would give the string the pattern "abxdebcde". However, as the string at the "OUT" parameter is defined as five characters in length, the string is limited to "abxde".
Fig. 07
Note
You can enter the character strings in the SIMATIC S7-1200 directly at the inputs "IN1" and "IN2" of the "INSERT" function. In the SIMATIC S7-300, you must parameterize the inputs with DB variables of the String data type.