Question:
Certain system variables (e. g. CAN2_dnOutD1_p) share one memory area (in the servo PLC e. g. the double word %QD32.0 contains the words %QW32.0 and %QW32.1) with other system variables (CAN2_nOutW1_a, CAN2_nOutW2_a). Which conversion formulas are to be used, when one 32-Bit-variable is to be converted to two 16-Bit-variables or the other way round?
Answer:
Apply the following formulas:
Conversion from one 32-Bit-variable (dnOriginalValue_p) to two16-Bit-variables (low-word (wLowWord) and high-word (wHighWord)):
wHighWord:=DINT_TO_WORD(SHR(DINT_TO_DWORD(dnOriginalValue_p),16))
wLowWord:=DINT_TO_WORD(dnOriginalValue_p);
Conversion from two 16-Bit-variables (low-word (wLowWord) and high-word (wHighWord)) to one 32-Bit-variable (dnOriginalValue_p):
dnOriginalValue_p:=DWORD_TO_DINT(SHL(WORD_TO_DWORD(wHighWord),16) OR wLowWord)
Applications:
When item values are transmitted (32-Bit-values) on the system blocks CAN1, CAN2, CAN3, as well as AIF1, AIF2 and AIF3 there is only one 32-Bit-value available as a system variable each. In such cases,where two item values per system block are to be transmitted, via the above-mentioned conversion formulas the other two data words (16-Bit-values) can be used for the transmission of 32-Bit-values. This requires that the value is separated in low- and high-word and that after transmission it is reconverted to a 32-Bit-value.
Note:
As the splitting in two 16-Bit-values or the re-conversion of the 32-Bit-value is executed in several IEC-operations, the user must ensure the data consistency (e. g. by semaphores, interlocking...).