MulDiv Command

Character: '
Decimal: 39
Hexadecimal: 0x27
Command Value: Destination Address (80-2303)

 

Note: This command is supported in RMC100 CPU firmware dated 20011113 or newer.

 

Note: This command should only be used in the Event Step table. It is usually not useful to issue this command directly from the PLC.

 

This command is used to multiply, divide, or scale a value in the RMC. It reads a value from an RMC register, multiplies it by one constant, divides it by another constant, rounds the result, and stores it in another RMC register.

Tip: To use this command to multiply only, set the Speed field to 1. To use this command to divide only, set the Deceleration field to 1. Refer to the definitions of the command fields below.

The memory locations available for the source of this operation include any Status, Command, Parameter, or Event Step register. The memory locations available for the destination of this operation include any Command, Parameter, or Event Step register.

The addresses of the source and destination registers match the addresses shown in the RMC Register Map (PROFIBUS-DP Message Mode) topic, except that only addresses 0-2303 are usable by this command.

Tip: Use the Address Tool to greatly simplify entering addresses for this and other commands that use addresses. See Address Tool for details.

This command uses the command fields as follows:

Mode: The Mode field controls how the 16-bit source, destination, and constant values are sign-extended. Its bits are defined as follows:

Bits 7-15 Reserved. Must be 0.

Bits 4-6 Position Range Axis. These bits are used only if bit 1 (Register Sign Extension) is set. They then determine which axis's position range is used for the source and destination registers.

Bits 2-3 Reserved. Must be 0.

Bit 1 Register Sign Extension. If this bit is 1, then the source and destination registers are sign extended to fit the position range for the axis selected by Mode bits 4-6.

If this bit is 0, then the source and destination registers are sign extended the same way as the constants.

Bit 0 Constant Sign Extension. If this bit is 0, then the constants in the Deceleration and Speed fields are signed. Otherwise, these constants are unsigned.

Tip: To simplify computing and entering the Mode value, use the pop-up editor. First enter the command so that RMCWin knows which Mode dialog box to display. Then either double-click the mode value or press ENTER when the cursor is in the Mode field. You will then be able to select the options you want, and the Mode will be computed for you.

Acceleration: Source Address. This is the address (see above) of the register to start with. The register's value can be signed, unsigned, or a position value depending on Mode bits 0-1.

Deceleration: This is a constant value that is multiplied by the register specified by the Acceleration field before being divided by the constant in the Speed field. This constant can be signed or unsigned as determined by Mode bit 0.

Speed: This is a constant value that is divided into the product of the register specified by the Acceleration field and the constant in the Deceleration field. This constant can be signed or unsigned as determined by Mode bit 0.

Command Value: Destination Address. This is an address (see above) of the register to store the result in. Before the result is stored, it is rounded to the nearest integer and checked if it falls in the range selected by Mode bits 0-1 (signed, unsigned, or a position value). If the result does not fall within this range, the result is limited to this range and an internal error bit is set, which can be tested with the MathOK (0x12) and MathERR (0x13) link types.

Command: ' (39 decimal, 0x27 hexadecimal)

Although this command is limited to multiplying and dividing by constants, it is possible to multiply and divide by computed values by stringing other math commands together whose destinations are the Deceleration and/or Speed fields of this command. For example, the first event step might be an Add command with a 0 in the Speed command field to copy a field from the original RMC register into the Speed command field of the next event step. The next event step would then perform a "constant" MulDiv command, but because this constant had just been set to another register value, the MulDiv effectively divides one register by another.

 

Example:

Suppose that Axis1 needs to go to a position that is 90% of Axis0's Actual Position. This can be done using two Event Steps. The first will calculate 90% of the Axis0 Actual Position and store it in the second step's Command Value. The second step will issue a Go (G) command to the newly-calculated position. A step sequence that accomplishes this is shown below:

 

Step 18

Step 19

Mode

0x0012

0x0081

Accel

(2)

100

Decel

900

100

Speed

1000

10000

Command Value

(412)

0

Command

'

G

Commanded Axes

Default

1

Link Type

MathERR

BitsON

Link Value

0

0x0001

Link Next

40

20

Step 18:

We use a MulDiv command to compute 90% of the Axis0 Actual Position and store it in Step 19 Command Value. We first need to find the source and destination register addresses. We recommend using the Address Tool to bookmark the Axis0 Actual Position and Step 19 Command Value on screen, although the RMC Register Map (PROFIBUS-DP Message Mode) help topic can be used to manually look up the addresses. Both methods show that address 2 (Axis0 Actual Position) should be entered in the Accel field, and address 412 (Step 19 Command Value) should be entered in the Command Value field.

Note: If these steps were moved around in the Event Step table (say to steps 20 and 21), the address that pointed to Step 19 Command Value (#412) would be automatically adjusted to point to Step 21 Command Value (#428).

The constants in the Decel and Speed fields are used to give 90%. That is 900/1000 is 0.9 or 90%. We could also have used 90 and 100 or 9 and 10. Because Mode bit 0 is zero, these values are signed, although for positive values under 32,767, this makes no difference.

Finally, notice that the range of the register values has been selected by Mode bits 0-1 and 4-6 to be the position range for Axis1. Therefore, if the result of the multiply and divide does not fall in the position range for Axis1, then the Math Error bit will be set. Notice that the value read from the Axis0 Actual Position is also treated as being in the Axis1 position range. Therefore, these axes must have similar position ranges.

As you can see, the MathERR link type is used to detect an overflow and jump to step 40 if there is such an error. If there is no error, then the MathERR link type links to the next step (step 19).

Step 19:

This step issues a Go (G) command to Axis1. The Command Value will have been overwritten by step 18 with a value that is 90% of the Axis0 Actual Position. This step then waits for the In Position bit to set before linking to step 20.

 

See also: Add Command, Subtract Command

 


Copyright (c) 1997-2015 by Delta Computer Systems, Inc.