A DL05 can add a 16-bit binary offset to the H0-CTRIO2's unscaled 32-bit binary counter without converting the counter to BCD. Load the double-word count into the 32-bit accumulator, execute ADDB with a binary constant no greater than KFFFF, and store the 32-bit result with OUTD. Do not apply the BCD instruction ADDD directly to a binary counter value.
Why ADDD Fails with an Unscaled CTRIO2 Count
The unscaled H0-CTRIO2 counter value is binary, while ADDD performs BCD arithmetic. Mixing these representations may appear to work at low counts, but it is not valid arithmetic.
The immediate failure point occurs when any four-bit nibble in the binary counter contains a value greater than 9. That bit pattern is invalid BCD, so the BCD instruction refuses the operation. Even binary values whose current bit patterns happen to be valid BCD digits do not make the mixed-format calculation reliable.
Use the DL05 32-Bit Accumulator with ADDB
The DL05 math accumulator is always 32 bits wide. The “double” designation describes the operand added to the accumulator, not the accumulator width. Therefore, ADDB can add a 16-bit binary operand to a 32-bit count already loaded into the accumulator; the result remains available as a 32-bit value.
LDD V2000
ADDB K1
OUTD V2002
In this sequence, LDD loads the 32-bit counter from V2000, ADDB adds a 16-bit binary constant, and OUTD writes the 32-bit result to V2002. The binary operand must not exceed KFFFF, equivalent to unsigned decimal 65535.
Convert a Decimal Offset to the Binary Constant
Binary addition requires a hexadecimal constant. If the required offset is decimal 360, convert it before entering the operand:
Here, K168 is the hexadecimal representation of decimal 360 for the binary instruction. Using K360 with ADDD instead changes both the instruction's arithmetic format and the operand interpretation; it does not provide valid binary addition to the CTRIO2 count.
When BCD Conversion Is Appropriate
| Method | Required math | Constraint |
|---|---|---|
| Keep the CTRIO2 count binary |
LDD, ADDB, OUTD
|
The added operand is 16-bit and no greater than KFFFF. |
| Configure CTRIO2 scaling for BCD output | BCD math such as ADDD
|
The double-word BCD range is limited to 99999999. |
| Convert binary to BCD in the PLC | Convert first, then use BCD math | Adds conversion work and retains the 99999999 BCD limit. |
BCD arithmetic is slower than binary arithmetic and reduces the available numeric range. Use BCD only when the surrounding logic or interface requires it. For a binary counter plus an offset within the 16-bit operand limit, retain the binary representation and use ADDB.
Implementation and Verification Procedure
- Confirm that the H0-CTRIO2 channel is delivering its unscaled binary counter value rather than scaled BCD output.
- Load the complete double word with
LDD; do not load only one word of the counter. - Convert the desired positive decimal offset to hexadecimal and confirm that it does not exceed
KFFFF. - Add the offset with
ADDB, then store the accumulator withOUTD. - Monitor the source double word and destination double word. Verify that the destination equals the binary source count plus the intended decimal offset across counts whose bit patterns contain hexadecimal digits A through F. This test exposes logic that incorrectly uses BCD arithmetic.
FAQ
Can a DL05 add to a 32-bit H0-CTRIO2 counter with ADDB?
Yes. Load the counter with LDD, add a 16-bit binary operand with ADDB, and store the 32-bit accumulator with OUTD.
Why does DL05 ADDD stop working as the encoder count increases?
ADDD expects BCD data. It refuses the operation when a nibble in the binary counter exceeds 9, and mixed binary/BCD arithmetic is invalid even before that failure becomes visible.
What binary constant adds decimal 360 on a DL05?
Decimal 360 equals hexadecimal . Use K168 as the operand of ADDB after loading the 32-bit counter.