TSL Automation Solutions Logo

Section 15.4.5 · Chapter 15: Using Macros

Calculation

■ MAX

Format P1 = MAX(P2,P3) Data Type U/S/UD/SD/F
Function Sets P1 to the larger value of P2 and P3.
P1 (I/E) The location to save the result.
P2,P3(I/E/C) The operands.
Example 1 $U100 = MAX(100, 200) /* Set $U100 to 200 */

■ MIN

Format P1 = MIN(P2,P3) Data Type U/S/UD/SD/F
Function Sets P1 to the smaller value of P2 and P3.
P1 (I/E) The location to save the result.
P2,P3(I/E/C) The operands.
Example 1 $U100 = MIN(100, 200) /* Set $U100 to 100 */

■ BMAX

Format P1 = BMAX(P2,P3) Data Type U/S/UD/SD/F
Function Finds the maximum in an array starting from P2 with P3 elements and saves the result in P1.
P1 (I) The location to save the result.
P2 (I) The starting location of the array.
P3 (I/C) The size of the array.
Example 1 $U100 = BMAX($U200, 16) (F) /* Find the maximum among 16 floating point numbers starting from $U200 and save the result in $U100 */

■ BMIN

Format P1 = BMIN(P2,P3) Data Type U/S/UD/SD/F
Function Finds the minimum in an array starting from P2 with P3 elements and saves the result in P1.
P1 (I) The location to save the result.
P2 (I) The starting location of the array.
P3 (I/C) The size of the array.
Example 1 $U100 = BMIN($U200, 60) (F) /* Find the minimum among 60 floating point numbers starting from $U200 and save the result in $U100 */

■ SUM

Format P1 = SUM(P2,P3) Data Type U/S/UD/SD/F
Function Calculates the sum of the value in an array starting from P2 with P3 elements and saves the result in P1.
P1 (I) The location to save the result.
P2 (I) The starting location of the array.
P3 (I/C) The size of the array.
Example 1 $U100 = SUM($U200, 16) (F) /* Calculate the sum of 16 floating point numbers starting from $U200 and save the result in $U100 */

■ XSUM

Format P1 = XSUM(P2,P3) Data Type U/UD
Function Calculates one element XOR (Bitwise Exclusive OR) sum of all the P3 elements in an array starting from P2 and saves the result in P1.
P1 (I) The location to save the result.
P2 (I) The starting location of the array.
P3 (I/C) The size of the array.
Example 1 $U100 = XSUM($U200, 5) (UD) /* Perform XOR sum of 5 32-bit unsigned numbers starting from $U200 and save the result in $U100. Another expression of XOR sum is $U100 = $U200 ^ $U202 ^ $U204 ^ $U206 ^ $U208 (UD) */

$U100 = 1001B
$U101 = 1100B
$U102 = 0110B
$U120 = XSUM($U100,3) /* $U120=0011B */

■ SWAP

Format SWAP(P1,P2) Data Type U
Function Swaps the low byte and high byte of every word in a word array starting from P1 with P2 words.
P1 (I) The starting location of the array.
P2 (I/C) The size of the array.
Example 1 $U120=1111111100000000B
$U121=1000000100000000B
SWAP($U120, 2) /* The value of $U120 will be 0000000011111111B, The value of $U121 will be 000000010000001B */

■ INIT_CRC

Format INIT_CRC(P1) Data Type U
Function This command initializes the cyclical redundant check (CRC) calculations for CRC8 and CRC16 macro commands.
P1 (I) The word block that contains the data to initialize CRC calculations. The following table describes the data arrangement in the word block.
Word No. Parameter
0 CRC checksum size.
Value Size
8 8-bit checksum.
16 16-bit checksum.
1 Attributes of data.
Bit Attribute
0 The data transmission order.
0: MSB-first
1: LSB-first
1-15 Reserved bits.
Must be 0.
2 Low word of CRC polynomial representation
Value (For MSB-first code) Value (For LSB-first code) Polynomial Name
0x07 0xE0 x8 + x2 + x + 1 CRC-8-CCITT
0x31 0x8C x8 + x5 + x4 + 1 CRC-8-Dallas/Maxim
0xD5 0xAB x8 + x7 + x6 + x4 + x2 + 1 CRC-8
0x1D 0xB8 x8 + x4 + x3 + x2 + 1 CRC-8-SAE-J1850
0x9B 0xD9 x8 + x7 + x4 + x3 + x + 1 CRC-8-WCDMA
0x8005 0xA001 x16 + x15 + x2 + 1 CRC-16
0x1021 0x8408 x16 + x12 + x5 + 1 CRC-16-CCITT
0x8BB7 0xEDD1 x16 + x15 + x11 + x9 + x8 + x7 + x5 + x4 + x2 + x + 1 CRC-16-T10-DIF
0x3D65 0xA8BC x16 + x13 + x12 + x11 + x10 + x8 + x6 + x5 + x2 + 1 CRC-16-DNP
0xD589 0x91A0 x16 + x10 + x8 + x7 + x3 + 1 CRC-16-DECT
3 High word of CRC polynomial representation; This word is reserved for CRC-32.
4 Low word of initial CRC value
5 High word of initial CRC value; This word is reserved for CRC-32.
6 Low word of final XOR value
7 High word of final XOR value; This word is reserved for CRC-32.
Example 1 $U100 = 16 /* CRC-16 */
$U101 = 1 /* LSB-first code */
$U102 = 0xA001 /* CRC-16-ANSI*/
$U104 = 0xFFFF /* Initial CRC value */
$U106 = 0 /* No final XOR value */
INIT_CRC($U100) /* Initialize the CRC calculation for Modbus */

■ CRC8

Format P1 = CRC8(P2,P3) Data Type U
Function Calculates the 8-bit CRC checksum of the data stored in P2 with a size of P3 and saves the result in P1.
P1 (I) The word to save the result. The high byte of the word will be zero.

The calculation should be initialized by the command INIT_CRC before or the result is meaningless. No need to re-initialize the calculation if the same CRC method is still in use.
P2 (I) The word block that contains the data of which the checksum is to be calculated. Note that the calculation takes only the low bytes of the words in the block. The high bytes are ignored.
P3 (I/C) The size of the word block in the unit of word. It also specifies the number of bytes involved in the checksum calculation.
Example 1 $U100 = “ABCDEEFGH”
$U110 = B2W($U100, 9) /* Convert byte array to word array */
$U120 = CRC8($U100, 9) /* Store the 8-bit CRC checksum of the string “ABCDEFGH” in $U120 */

■ CRC16

Format P1 = CRC16(P2,P3) Data Type U
Function Calculates the 16-bit CRC checksum of the data stored in P2 with a size of P3 and saves the result in P1.
P1 (I) The word block to save the result.
Word No. Description
0 The low byte of the checksum will be saved in the low byte of this word. The high byte of this word will be 0.
1 The high byte of the checksum will be saved in the low byte of this word. The high byte of this word will be 0.
The calculation should be initialized by the command INIT_CRC before or the result is meaningless. No need to re-initialize the calculation if the same CRC method is still in use.
P2 (I) The word block that contains the data of which the checksum is to be calculated. Note that the calculation takes only the low bytes of the words in the block. The high bytes are ignored.
P3 (I/C) The size of the word block in the unit of word. It also specifies the number of bytes involved in the calculation.
Example 1 $U100 = “ABCDEEFGH”
$U110 = B2W($U100, 9) /* Convert byte array to word array */
$U120 = CRC16($U100, 9) /* Store the 16-bit CRC checksum of the string “ABCDEFGH” in $U120 and $U121 */

Need PM Designer itself?

V4 for current PK, PT, ITV and PM panels, V2 for older models. Free, sent by email.

Source.Section 15.4.5 of the PM Designer Software User Manual, Edition 2.0, © Cermate Technologies Inc. (www.cermate.com, service@cermate.com). Reproduced online, with the manual's own figures, by TSL Automation Solutions, authorised Cermate distributor, for users of Cermate HMI panels. PM Designer and PanelMaster are trademarks of Cermate Technologies Inc.

Text and figures are the manufacturer's and may describe features your panel or software version does not have. For a plain-language introduction read the PM Designer guide; for help with a specific panel contact TSL Automation.