Converting Unsigned Double Integer (UDINT) to Floating Point (FP) in TelePACE Studio
In TelePACE Studio, data is stored in 16 bit holding registers. Depending on the data format, a value might need one or two registers. In some instances, a programmer may need to have a value converted between two different data formats. TelePACE Studio does have some function blocks to help convert between formats. For example:
- UTOF: Unsigned integer To Floating point (FP)
- STOF: Signed integer To FP
- FTOU: FP To Unsigned integer
- FTOS: FP to Signed integer
Although TelePACE Studio does work with unsigned double integers (UDINT), it does not have any function blocks to convert to or from UDINT.
Unsigned Double Integers (UDINT):
A single unsigned integer (UINT) requires 1 register (16 bits) to store its value whereas a UDINT value requires 2 consecutive registers (32 bits), a high register and a low register. A UINT value can count up to 65535, whereas a UDINT can count up to 4,294,967,295
For small integers, 65535 or lower, a UDINT will be able to store the value in the low register and have a 0 in the high register. If the UDINT is increased by 1 to a value of 65536, it will cause the high register to increase to 1, and the low register will have a value of 0.
Essentially, for an UDINT value of 1,000,000, the high register stores the number of times 65536 divides into 1,000,000 and the low register stores the remainder. To represent 1,000,000 as a UDINT, the High Register would have a value of 15 and the Low Register would have a value of 16960. (1,000,000 = 15*65536 + 16960).
Floating Points (FP):
A 32-bit floating point also requires two 16-bit registers. A FP can represent very large numbers (123,456,000,000,000) or very small number (0.000 000 000 123 456). The limitation with 32-bit floating point math is that it can only accurately represent a little more than 7 digits.
Converting UDINT to FP:
The TelePACE Studio sample code below has a UDINT value in registers 48001-48002. To convert this value to a FP, the logic looks at both the UDINT High Register and Low Register separately and then combines the result in registers 49007-49008.
In a second example, a larger UDINT value of 12,000,001 ends up getting converted to 12,000,000 as a floating point.
This is a limitation of 32-bit math in general and it will be up to the user to decide if their UDINT values will get large enough to introduce this issue OR if the decrease in accuracy is significant for their application.
發佈於: 施耐德電機Taiwan


需要協助?
產品選型工具
快速輕鬆地為您的應用找到合適的產品和附件。
取得報價
立即線上提交您的銷售需求,專業團隊將主動聯繫您。
購買地點
輕鬆在您所在地區找到最近的施耐德電機經銷商。
支援中心
在同一位置找到滿足您所有需求的支援資源。