Combine Two Registers
medium
Combines two 16-bit device registers into one 32-bit word.
What it teaches
Devices and protocols often split one 32-bit value across two 16-bit registers, and a 16-bit register is an INT. Put the low register in output bits 0-15 and the high register in bits 16-31. Register order matters; a register whose top bit is set reads as a negative number, so mask each one to its own 16 bits before combining, or the sign spreads across the bits above it. Setting output bit 31 then makes the DINT itself negative.
Parameters
| Tag | Direction | Type | Default | Description |
|---|---|---|---|---|
| In_LowRegister | Input | INT | 22136 | Low register from the device |
| In_HighRegister | Input | INT | 4660 | High register from the device |
| Out_Value | Output | DINT | 0 | Combined 32-bit value |
Required behavior
- Out_Value bits 0-15 follow In_LowRegister every scan.
- Out_Value bits 16-31 follow In_HighRegister every scan.
- A negative register still contributes its own 16 bits and nothing above them: In_HighRegister of -21555 (16#ABCD) fills bits 16-31 with 16#ABCD and leaves bits 0-15 to the low register.
- All 32 bits of Out_Value are rebuilt every scan; no previous output bits are retained.
- With the defaults, low register 22136 (16#5678) and high register 4660 (16#1234) produce 305419896 (16#12345678).