Conversions, Encoder counter rollover – Rockwell Automation 1398-PDM-xxx IQ Master Version 3.2.4 for IA-2000 and IQ-5000 Positioning Drive Modules, IQ-55 User Manual

Page 153

Advertising
background image

User Variables and Arithmetic • Conversions

131

Publication 1398-PM601A-EN-P — October 2000

TUTORIAL

Conversions

Position can be represented in encoder counts or as user units using a scale factor. Encoder counts are
the number of encoder counts observed as the motor moves. The IQ counts each edge of an encoder
pulse, therefore, the number of encoder lines is multiplied by 4 for one revolution. For a 2,000 line
encoder, there are 8,000 encoder counts per motor revolution. If the motor started at zero and moved
one revolution, the new position would be 8,000 counts.

To make the IQ easier to use, a user scale factor is used to convert encoder counts to user units. With the
SCALE parameter, set in the System dialog box under the Parameter menu, you tell the IQ how many
encoder counts there are in the unit of measure that you would like to use. The SCALE argument must
be an integer. For example, if you want to work in units of revolutions, set the SCALE parameter to how
many encoder counts in one revolution. Once the SCALE is set, all distances or positions will be speci-
fied or read in revolutions. Throughout this text, scaled units are referred to as user units: the units spec-
ified by the user of the IQ.

Occasionally the need arises to convert between encoder counts and user units. To do this, several func-
tions are available in IQ Basic: @, UTOC1, UTOC2, CTOU1, CTOU2.

Placing an “at” sign, @, in front of a position system variable such as POS1 will cause that value to be
read in encoder counts rather than in user units. UTOC1 (UTOC2) will convert from user units to
encoder counts using SCALE (SCALE2). CTOU1 (CTOU2) will convert counts to user units using
SCALE (SCALE2)

For example:

V1 = POS1

;V1 contains position 1 in user units

V2 = @POS1

;V2 contains position 1 in encoder counts

V3 = UTOC1 V1

;V3 contains position 1 in encoder counts

V4 = CTOU1 V2

;v4 contains position 1 in user units

Encoder Counter Rollover

Many IQ applications require reading encoder positions often as the machine operates. If the application
is unidirectional (the net motion is always in one direction), eventually the IQ encoder counter will roll
over from a large positive value to a large negative value (or from a large negative value to a large posi-
tive value). The IQ encoder counters store encoder positions as a 32 bit signed value. When the counter
value reaches 2

31

(2,147,483,648) counts, the next encoder pulse will cause the value to roll over to -2

31

(-2,147,483,647). If math is performed on two different position samples, the calculated result may be
wrong if one position sample is read just before rollover occurs, and the second is read just after rollover
occurs. To avoid this problem, the conversion functions may be used to perform math on position values
in encoder counts rather than user units. Performing math in encoder counts avoids this problem
because IQ variables store values in 32 bit signed values just like the encoder counters. When the math
is performed, the math itself “rolls over” just like the encoder counter, and the result will be correct.

Example: The SCALE parameter is set to 8000 counts/unit. Variable V1 reads POS1 (with the statement

V1 = POS1

) in user units. The value of POS1 is 268,435 (2,147,480,000 counts). Variable V2 reads

POS1 (with the statement

V2 = POS1

) in user units after the counter has rolled over when the value of

POS1 is -268,432 (-2,147,456,000 counts). If the difference in position between the two different
instances is desired, the two values may be subtracted. To do this, V3 is calculated as V2 - V1. In this
example, since V1 and V2 were read in user units instead of counts, the value calculated in V3 would be
-268,432 - 268,435 = -536,867. This very large negative value is not the correct difference. The solu-
tion is to capture the positions into V1 and V2 in counts using the statements

V1 = @POS1

and

V2 =

@POS1

. Now, V1 will contain 2,147,480,000 and V2 will contain -2,147,456,000. When these values

are subtracted (

V3 = V2 - V1

), the 32 bit math will properly set V3 to a value of 31,295. This is the

correct value in counts of the position difference. V3 can now be converted to user units using the state-
ment

V3 = CTOU1 V3

which would convert V3 to a value of 3.9119 units which is the desired posi-

tion difference.

Another important consideration in correcting for encoder counter rollover is when a program compares

Advertising