# Simatic Ti & 32 bit words

K

#### kevin

Anyone set up a 32 bit signed word which can be incremented by a variable who's value can change? When the 32 bit word exceeds the max value it rolls over keeping the count correct. If you've done this - a copy of the code will save me reinventing the wheel. Cheers.

J

#### jmGiraud

> Anyone set up a 32 bit signed word which can be incremented by a variable who's value can change? When the 32 bit word exceeds the max value it rolls over keeping the count correct. If you've done this - a copy of the code will save me reinventing the wheel. Cheers. ____________________________ For what purpose ? What kind of information (Process Data)is in that 32 bit word ?

T

#### Tony R. Gunderman

If you are using SIMATIC controllers with real number processing like the 545 or 555, you can do this in special function programs. These can be compiled in later versions of the controllers. You want to create your rollover point somewhere before an overflow would occur and ensure that does not happen. Basically, the program would look something like this (if I am remembering syntax correctly): * CHOOSE 9e18 AS A ROLLOVER POINT. IF V1. + V2 < 9 * 10 ** 18 MATH V1. := V1. + V3 ELSE MATH V1. := V1. + V3 - 9 * 10 ** 18 ENDIF This program can be called from ladder when the calculation needs to occur. It assumes the adder number will fit in 16 bit number (V3) and the counter is in the 32 bits occupied by V1 and V2. Keep in mind that this will be storing the result in IEEE real number format. If you are actually wanting the number to be a 32 bit integer (or are forced to do this because you are using an earlier model controller like the TI520 or TI530), the problem gets a lot more tricky. I built a 28-bit adder once on a 530T and remember taking a bit to figure it out. At this point, I cannot even remember why I limited it to 28 bits. Probably had something to do with overflow.