Convert to BCD (TO_BCD)

This table lists the controllers and applications that support this instruction.
Architecture
Standard applications
Safety applications
CompactLogix 5370, ControlLogix 5570, Compact GuardLogix 5370, and GuardLogix 5570 controllers
Yes
No
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Yes
Yes
The TO_BCD instruction converts a decimal value (0 Less than or equal to Source Less than or equal to 99,999,999) to a BCD value and stores the result in the Destination.
TIP: In Logix Designer version 36, the mnemonic for this instruction changed from TOD to TO_BCD.
Available Languages
Ladder Diagram
Function Block Diagram
Function Block Diagram supports these elements:
FBD Block
Structured Text
This instruction is not available in structured text.
Operands
IMPORTANT: Unexpected operation may occur if:
  • Output tag operands are overwritten.
  • Members of a structure operand are overwritten.
  • Except when specified, structure operands are shared by multiple instructions.
There are data conversion rules for mixing numeric data types within an instruction. See Data conversions.
Ladder Diagram
Operand
Data Type
CompactLogix
5370,
ControlLogix
5570,
Compact GuardLogix
5370, and
GuardLogix
5570 controllers
Data Type
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Format
Description
Source
SINT
INT
DINT
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
Immediate
tag
Value to convert to BCD
0 Less than or equal to Source Less than or equal to 99,999,999
Destination
SINT
INT
DINT
SINT
INT
DINT
LINT
USINT
UINT
UDINT
ULINT
tag
Tag to store the result
Function Block Diagram
FBD Block
Operand
Type
Format
Description
TO_BCD tag
FBD_CONVERT
Structure
TO_BCD structure
FBD_CONVERT Structure
Input Member
Data Type
Description
EnableIn
BOOL
Enable input. If cleared, the instruction does not execute and outputs are not updated.
Default is set.
Source
DINT
Input to the conversion instruction.
Valid = any integer
Output Member
Data Type
Description
EnableOut
BOOL
Enable output.
Dest
DINT
Result of the conversion instruction. Math status flags are set for this output.
Description
BCD is the Binary Coded Decimal number system that expresses individual decimal digits (0-9) in a 4-bit binary notation.
Source
Destination
Destination Type
Negative source < 0
0
Source > 9,999, 999,999, 999,999
16#9999_9999_9999_9999
ULINT
Source > 9,999, 999,999, 999,999
16#9999_9999_9999_9999
LINT
Source > 99,999,999
16#9999_9999
UDINT
Source > 99,999,999
16#9999_9999
DINT
Source > 99,999,999
16#9999
UINT
Source > 99,999,999
16#9999
INT
Source > 99,999,999
16#99
USINT
Source > 99,999,999
16#99
SINT
Affects Math Status Flags
Controllers
Affects Math Status Flags
CompactLogix 5380, CompactLogix 5480, ControlLogix 5580, Compact GuardLogix 5380, and GuardLogix 5580 controllers
Conditional, see .
CompactLogix
5370,
ControlLogix
5570,
Compact GuardLogix
5370, and
GuardLogix
5570 controllers
Yes
Major/Minor Faults
See for operand related faults.
A minor fault will occur if:
Fault type
Fault code
feature is enabled and overflow detected and Source < 0
4
4
feature is enabled and overflow detected and Source > 99,999,999 / 9,999, 999,999, 999,999
4
4
feature is enabled and overflow detected
4
4
Execution
Ladder Diagram
Condition/State
Action Taken
Prescan
N/A.
Rung-condition-in is false
N/A.
Rung-condition-in is true
The controller converts the Source to BCD and places the result in the Destination.
Postscan
N/A.
Function Block Diagram
FBD Block
Condition/State
Action Taken
Prescan
N/A
Tag.EnableIn is false.
EnableOut is cleared to false
Tag.EnableIn is true
Dest = the result of computation in BCD value.
If overflow occurs
Clear EnableOut to false.
else
Set EnableOut to true.
Instruction first scan
N/A
Instruction first run
N/A
Postscan
N/A
Example
Ladder Diagram
Function Block
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.