
adccommunitymod (AutomationDirect) asked a question.
BIN v BCD
Created Date: June 13,2012
Created By: ssthill
**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****
Please pardon my ignorance, but I have come out of an embedded programming background and picked up some legacy ladder code for a DL06. Throughout the code the primary data type is BCD. Is there a reason for this? Is there limitations to working in Binary all the time? I just wanted to ask before I set about doing everything in BIN only to find the limitations later and have to re-do everything. Thanks...
Created Date: June 13,2012
Created by: bcarlton
BCD is used in Timers and Counters. You will have to put up with that since it's buried in the system. In general using binary for most of the calculations, using conversions when needed, will yield faster execution than staying with BCD. Use the execution time tables and make your own judgement if the added overhead of the conversions is worth it. There is also the added number range of a binary word compared to a BCD word to consider.
Created Date: June 13,2012
Created by: franji1
Back in the early '80's when Koyo developed their first PLC, they had Timer/Counter preset modules that were basically discrete modules with thumb wheels on them, with BCD digit encoding on the wheel such that the discrete values came in as BCD digits. Hence, the Timer/Counter instructions supported BCD presets and current values. Then, if you needed to do arithmetic to calculate these preset values instead of using a mechanical UI, the math instructions were natively BCD.
Their next family of PLCs in the late 80's for Texas Instruments (their first PLC family was sold by GE as Series One) maintained this "legacy ", but added support for binary math instructions. The initial analog modules supported BCD, but jumpers were added to support binary.
Their next famly of PLC's in the mid 90's for PLC Direct (now Automation Direct) also maintained this BCD "legacy " in Timers and Counters, and binary math and analog, and soon IEEE 32-bit floating point math.
Yes, this will be on the History quiz tomorrow. ;)
Created Date: June 13,2012
Created by: ssthill
Thanks....
In other words a legacy item from a electro mechanical system is now carried over... to the point that the software I have is almost entirely written with BCD as the number format....
I will swot up for the quiz...
Created Date: June 14,2012
Created by: franji1
Thanks....
In other words a legacy item from a electro mechanical system is now carried over... to the point that the software I have is almost entirely written with BCD as the number format....
I will swot up for the quiz... BCD is supported, but as Bernie mentioned, binary is the way to go (or even REAL, but it's more of a CPU hit than binary). Bernie might know, but some of the REAL instructions are actually faster than the BCD counterparts (not all, but some).
If you then need to use a calculation as a Timer or Counter preset, just do
LD binaryValue
BCD
OUT bcdEquivalent
TMR T0 bcdEquivalent
This way, all your calculations are in the binary form, e.g. ADDB or MATHBIN IBox, but not ADD nor MATHBCD IBox. Or, use the REAL instructions e.g. ADDR or MATHR IBox.
Created Date: July 09,2012
Created by: bartb102
Oh, the fun of programming Koyo's. Just always be sure that you include the type of number in the documentation. Guaranteed at some time you'll be adding 0010 + 10 and wondering why the answer is wrong. No fun debugging your math when it doesn't work right, and you find that you added a BCD value to a BIN value. Or programming your O/I to write a BCD value to a BIN register. Better yet is comparing a BCD value to a BIN value.
Created Date: July 12,2012
Created by: marksji
Better yet is comparing a BCD value to a BIN value. That's my favorite :cool:
Created Date: June 13,2012
Created by: ssthill
Please pardon my ignorance, but I have come out of an embedded programming background and picked up some legacy ladder code for a DL06.
Throughout the code the primary data type is BCD. Is there a reason for this? Is there limitations to working in Binary all the time?
I just wanted to ask before I set about doing everything in BIN only to find the limitations later and have to re-do everything.
Thanks...