DoubleToWord, Double to word conversion

List

This page is part of the IEC 61131-3 Programming Manual. Go to the index.

This function block allows you to convert a variable DWORD in two variables WORD. The 16 high bits of In will be transferred to the operand MSW, low 16 bits will be transferred to the operand LSW.

Function lock
CODESYS: Not available
LogicLab: eLLabUtyLib

In (DWORD) Variable to convert.

MSW (WORD) MSW of the input value.

LSW (WORD) LSW of the input value.

Examples

How to use the examples.
In the example a variable DWORD with value 16 # 12345678 is transferred in two variables WORD which will have value 16 # 1234 and 16 # 5678. In the example in language ST it is highlighted how the same operation is much simpler by writing it directly with the operands of the language.

LogicLab (Ptp114)
PROGRAM ST_DoubleToWord
VAR
    DData : DWORD := 16#12345678; (* Double word data *)
    High : ARRAY[ 0..1 ] OF WORD; (* MSW word *)
    Low : ARRAY[ 0..1 ] OF WORD; (* LSW word *)
    DDec : DoubleToWord; (* Double decompress *)
END_VAR

// *****************************************************************************
// PROGRAM "ST_DoubleToWord"
// *****************************************************************************
// This program shows the use of DoubleToWord function block.
// -----------------------------------------------------------------------------

    // -------------------------------------------------------------------------
    // DECOMPRESS DWORD
    // -------------------------------------------------------------------------
    // Decompress word using the FB.

    DDec(In:=DData);
    High[0]:=DDec.MSW; //MSW word
    Low[0]:=DDec.LSW; //LSW word

    // -------------------------------------------------------------------------
    // DECOMPRESS DWORD
    // -------------------------------------------------------------------------
    // The same operation as above executed directly using ST statements.

    High[1]:=TO_WORD(DData/16#10000); //MSW word
    Low[1]:=TO_WORD(DData); //LSW word

// [End of file]
Was this article helpful?