Computers hate decimal. I mean, just because we have ten fingers and ten toes, we think we can dictate what base other computing entities should think in. Well, it’s really quite inefficient when you think about it, its so easy to convert base 2 to base 8 or base 16, which any logical device can handle quite well. Its only those humans who need to add up all those individual bits in our registers to convert them to base 10.
Back in the days before touchscreens, seven segment displays and thumbwheel switches were used as a numerical interface between humans and PLCs. Even before the PLC, these devices were the only graphical way to interface with circuits numerically. Sure, you could move plugs around like in the days of ENIAC, but it was a lot easier to view and adjust decimal numbers with these devices.
The problem was, they were very I/O intensive. Each thumbwheel segment requires 4 inputs (+ power), while each 7 segment display requires 4 outputs (+2 power connections). Still, it was a lot easier for most of us human types than using pushbuttons and pilot lights to interface directly with signed or unsigned integers in decimal. Or dealing directly with hexadecimal!
Last week I taught a Siemens PLC class in Portland, Oregon (This week I am in Baltimore doing the same). One of the complaints I often get when doing Siemens training is the math; every data type has to be explicitly declared on the S7 platform, and converted if data types are not equivalent. Not only that, but the standard timer and counter data types incorporate BCD (Binary Coded Decimal) into their data structures. This is because the structures go all the way back to when people had to deal with things like these thumbwheels and 7 segment displays. In fact, the timer setpoints are still entered as “S5T#3S” for a three second setpoint; this goes back to the S5 PLC platform. The timer uses three BCD digits (12 bits) and two extra bits for the time base. This is also true for the counters, meaning that they only count from -999 to +999.
The table above illustrates what that really means. Each four digit section can only carry bit values from 0000 to 1001; for the next value, rather than indexing to 1010, (“10” in signed or unsigned decimal or “A” in hexadecimal), the next bit gets bumped to the next section of bits. This means that the last six combinations of bits (A-F) are effectively wasted, not possible in the BCD structure.
The BCD structure or base is also still usable in many of the newer touchscreens, but most programmers tend to choose an integer base to express decimal numbers. The problem I have seen is that BCD is sort of like DOS; engineering schools still touch on it, but people really don’t know where it comes from. Hopefully referring back to those old thumbwheels and 7 segment displays will help clear up some of the mystery and “why” of BCD!