How do I convert BCD for a PLC parking count display?

David Krause8 min read
Other ManufacturerOther TopicTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

A PLC parking count can be converted to BCD and sent digit by digit to a compatible display, but first decide whether the display represents cars currently parked or separate entry and exit totals. Those are different values, and a correct conversion cannot fix a counter that measures the wrong quantity.

Choose the value the display must represent

Binary-coded decimal (BCD) stores each decimal digit in a four-bit group. A count of 10, for example, is represented as two BCD digits: the tens digit is 0001 and the units digit is 0000. It is not the same bit pattern as the binary integer 10.

For a parking system, distinguish occupancy from traffic totals:

  • Current occupancy: increment for a valid entry and decrement for a valid exit. This is the value to display if the operator needs to know how many cars are parked now.
  • Entry total and exit total: maintain separate counters if the purpose is to show how many cars have entered and how many have left over a period. These totals do not, by themselves, equal current occupancy.

With ten parking spaces, occupancy ranges from 0 through 10, which requires two decimal digits at the upper limit. If the project instead counts cumulative entries or exits, the maximum value and digit count depend on the counter's reset policy and the intended operating period.

Check 1: Write down the displayed quantity and its permitted minimum and maximum. For a ten-space occupancy display, the expected range is 0–10; for cumulative totals, define the reset point and range before mapping digits.

Condition the two sensor signals into count events

Use each sensor's transition to generate one count event, rather than allowing a sensor that remains blocked to add repeatedly on every PLC scan. A one-shot or equivalent edge-detection logic typically turns a sensor transition into a single event; select the correct transition for the sensor and application. Confirm actual sensor behavior—such as whether its output is active while a car blocks the beam—before choosing the edge.

Two sensors can be used to determine direction when a vehicle passes them in sequence. The sequence must be evaluated so an entry produces one increment and an exit one decrement. A single sensor transition does not inherently identify direction. Define what should happen if the sequence is incomplete, reversed, or overlaps another vehicle; do not count each sensor independently as a complete passage unless the installation's detection arrangement supports that interpretation.

If the system also uses infrared sensors to indicate whether individual spaces are occupied, treat those spot indications as a separate measurement. A disagreement between summed spot occupancy and the entry-minus-exit count can reveal missed passages, double counts, or a spot sensor that failed to detect a parked car.

Check 2: Monitor the raw sensor states and count-event bits while testing a controlled passage. Expected result: one valid entry sequence produces exactly one increment, and one valid exit sequence produces exactly one decrement; a sensor held active does not generate repeated counts.

Keep the occupancy counter within its valid range

For occupancy, implement the count as entries minus exits, with bounds based on physical capacity. At zero, another exit must not make occupancy negative; at capacity, another entry must not raise the displayed occupancy above the number of spaces. Decide whether an invalid event should be ignored, alarmed, or handled by another defined recovery method.

Maintain separate entry and exit totals only when operators need those totals. If both totals are retained, calculate occupancy from their difference and validate that result against capacity. The arithmetic and counter data types must support the selected range. Do not assume a cumulative total will stay within a two-digit display range.

A useful plausibility check compares the calculated occupancy with the number of spot sensors currently reporting occupied spaces. They can differ temporarily while a car moves between the entrance, exit, and parking spaces, so define when the comparison is meaningful and what tolerance or response the application requires.

Check 3: Test the lower and upper boundaries in a safe commissioning state. Expected result: occupancy remains between 0 and the configured space capacity, and an attempted count beyond either boundary produces the defined response rather than a wrapped or misleading value.

Convert the integer count to BCD

Use a PLC's integer-to-BCD conversion instruction when the selected CPU or programming environment provides one. The conversion input should be the value selected for display—occupancy or a chosen entry/exit total—and the destination should be a word or other BCD data object supported by that instruction. The exact instruction name, operand format, and supported range depend on the PLC; check the instruction help and CPU documentation rather than copying syntax from a different platform.

Conversion must occur after the count has been updated and before digit bits are copied to the physical outputs. In a cyclic program, arrange the logic so that all output digits come from the same updated value; otherwise the display can briefly show a mixed old/new number. If the PLC's BCD instruction returns a packed word, each four-bit nibble carries a decimal digit. Confirm the word's digit order and which nibble contains the units digit in the instruction documentation.

Do not substitute a binary-to-BCD shortcut based on adding six unless its supported input range has been proven. A correction that happens to produce valid digits for a narrow range can fail as soon as the count crosses another decimal boundary. A native conversion instruction or a fully tested conversion routine is the safer choice.

Check 4: Force or simulate known legal input values and inspect the conversion destination. Expected result: decimal 9 produces a units digit of 9; decimal 10 produces tens 1 and units 0; decimal 0 produces zero in each displayed digit.

Map each BCD digit to its own output group

For a two-digit display with BCD inputs, connect the units nibble to the units digit input group and the tens nibble to the tens digit input group. Map the four bits in the order specified by the display interface and PLC wiring. Do not assign an entire converted word to a single digit's four inputs: the display needs the separate digit nibbles.

Check whether the display expects BCD inputs and what electrical input type it uses before connecting outputs. PLC output modules and display input circuits must be electrically compatible, and the wiring diagram must match the module and display terminals. The available source information does not identify an output module or display model, so obtain voltage, current, common/reference, and polarity requirements from their manuals rather than assuming the PLC can drive the display directly.

For a capacity of ten spaces, the display needs to represent 10 as tens 1 and units 0. If the physical display has only one digit, it cannot show the full occupancy range unambiguously; select a display arrangement with enough digits or define a different indication.

Check 5: With output logic monitored or the display safely isolated, test each digit group. Expected result: 10 drives the tens digit with BCD 1 and the units digit with BCD 0; no tens/units nibble swap occurs.

Distinguish a BCD display from a seven-segment display

A BCD input display accepts a four-bit decimal code and decodes that code internally. A bare seven-segment display instead needs segment control signals (or a separate decoder/interface). Connecting BCD bits directly to segment terminals will not produce the intended numeral. If the hardware is a seven-segment display, use a compatible BCD-to-seven-segment decoder or generate the segment pattern in the PLC, following the actual display and interface specifications.

Confirm whether the physical device is a BCD-input unit, a decoder plus display, or a directly controlled seven-segment unit. The phrase “BCD display” alone does not identify the hardware interface. Also confirm whether leading zero suppression is required; for a two-digit occupancy display, showing 00 or blanking the tens digit at values below 10 is a display behavior to configure or implement, not a property guaranteed by BCD conversion.

Check 6: Test the display at 0, 1, 9, and 10. Expected result: each value appears as the intended decimal numeral, and the chosen leading-zero behavior is consistent at 0–9.

Commission the complete count-to-display path

Verify the installation from sensor event to visible value, not just the conversion block. Test one car passage at a time and compare the sensor sequence, count event, internal count, converted digits, output states, and visible display. If entry and exit use separate sensors or sequences, test each direction independently.

For spot monitoring, compare the displayed occupancy with the sum of occupied-space indications after vehicles have settled into or left spaces. Investigate any persistent difference by checking missed sensor transitions, duplicate count events, counter bounds, and output-digit mapping. If the display differs while the internal count is correct, isolate the conversion and wiring stages rather than changing the counting logic.

Check 7: Complete an end-to-end test with a controlled entry followed by a controlled exit. Expected result: the entry changes occupancy by +1, the exit changes it by −1, the display follows the internal value at each step, and the final occupancy agrees with the occupied-space indications when all vehicles are stationary.

FAQ

Why does my PLC count look wrong when I send it to a BCD display?

A binary integer and a BCD digit group use different encodings. Convert the displayed value with the PLC's supported integer-to-BCD function, then map each four-bit digit nibble to the corresponding display input group.

Why does a count of 10 need two BCD digits?

BCD encodes each decimal digit separately: 10 is tens digit 1 and units digit 0. For a ten-space occupancy display, provide two digit positions so the full 0–10 range is visible.

Why does my parking occupancy disagree with the spot sensors?

Missed or repeated entry/exit events can make a running count diverge from actual occupied spaces. Test one direction at a time, verify one count per complete passage, enforce the 0-to-capacity bounds, and finish by comparing the display with the settled spot indications.

Back to blog