PLC Simulator
PLC memory and values

PLC Data Types: Choose the Value Before You Write the Logic

A PLC tag is not only a name. Its data type defines which values the tag can store, how instructions interpret its bits, what precision you keep, and which failures can hide at conversion boundaries. This guide turns BOOL, INT, DINT, REAL, TIME, WORD and DWORD into practical engineering decisions.

Product evidence: the browser runtime declares and executes these scalar types, exposes numeric forcing for INT/DINT/REAL, formats TIME values, and supports bit access on word values. Exact vendor ranges and conversions still belong to the target-controller documentation.

From physical quantity to trustworthy PLC valueevidence path

Type choice belongs near the start of the signal path. If the representation is wrong, every comparison, alarm, trend and output after it inherits the error.

Answer first

What are PLC data types?

PLC data types are contracts for stored values. BOOL represents a two-state condition. INT and DINT represent signed whole numbers with different ranges. REAL represents fractional values with finite floating-point precision. TIME represents a duration. WORD and DWORD represent groups of bits that are often used for masks, status registers and protocol data. A type controls storage, valid operations, literal syntax, conversion behavior and how online tools display a tag.

Meaning first

Choose a type from the engineering meaning and required range. A motor-running state is BOOL; a production count is usually an integer; a pressure in engineering units often needs REAL.

Boundaries are behavior

Maximum values, negative values, rounding, overflow and division are not corner trivia. They determine whether a controller produces a credible answer under load.

Vendor details vary

IEC names create a shared vocabulary, but memory layout, implicit conversions, extended types and fault behavior can differ by controller family and firmware.

Decision model

Select the smallest type that is clear, safe and large enough

The right question is not “which type is common?” It is “what values can this tag legitimately hold during normal operation, commissioning, failure and future expansion?”

A practical PLC type-selection path

Start with meaning, then prove range and precision. Storage size is a later concern unless the platform or communication map imposes a hard constraint.

Begin with the domain. A discrete input is naturally Boolean because its useful states are on and off. A reject counter is numeric even if it starts at zero. A sixteen-bit diagnostic register may look like the integer 32768 on screen, but its engineering meaning is a set of independent status flags; treating it as WORD makes bit operations and documentation clearer. A five-second delay is a duration, not merely the integer 5000. TIME communicates the unit and avoids a hidden milliseconds-versus-seconds contract.

Next calculate the envelope. Include startup defaults, sensor failure values, calibration span, intermediate arithmetic and the total expected over the machine life. A batch counter that reaches 20,000 during a shift might fit an INT today, while a lifetime totalizer can exceed that range quickly. Multiplication can overflow before assignment even when the final scaled result would fit. Write the range beside the tag definition and test both sides of it.

Finally consider interoperability. HMI drivers, fieldbus registers, databases and vendor libraries may use different type names or widths. Map the boundary explicitly rather than relying on an implicit cast. If a sixteen-bit Modbus register contains an unsigned raw value, document whether the PLC interprets it as a bit string, signed integer or unsigned integer supported by that platform. The same sixteen bits can produce very different engineering values.

Core type selection table
TypeUse it forAsk before choosingCommon failure
BOOLCommands, permissives, interlocks, statusIs the state truly binary, and what does false mean at startup?A vague bit name hides whether it is command, feedback or fault state.
INTSigned whole numbers with a modest rangeCan any intermediate or future value exceed the platform range?Overflow or a negative raw value produces a believable but wrong result.
DINTLarge counts, totals, timestamps or intermediate mathDoes the connected device or protocol supply the same width and sign?A narrow conversion truncates the value at an interface.
REALScaled analog values and fractional calculationsWhat precision and comparison tolerance does the requirement allow?Exact equality fails after ordinary floating-point arithmetic.
TIMETimer presets, elapsed durations and delaysIs the value a duration or a wall-clock date/time?A naked integer creates a hidden unit conversion.
WORD / DWORDPacked flags, masks, register images and bit fieldsAre the bits independent states or a numeric magnitude?Arithmetic is applied to a status register that should be masked.

Discrete logic

BOOL is simple storage, but industrial state is rarely simple

A Boolean stores two values, yet its name, source, lifecycle and scan timing determine whether the logic remains understandable and safe to diagnose.

Separate command, decision and feedback bits

Four true-or-false tags can describe four different facts. Keeping them separate makes a failed start diagnosable.

Name Boolean tags as statements that can be read as true or false: GuardClosed, StartRequest, MotorCommand, MotorRunning and OverloadTripped. Avoid a bare tag such as Motor because it does not reveal whether true means requested, energized, moving or faulted. Direction also matters. An HMI command is written by the operator interface; feedback is read from the process. Combining both roles in one bit creates race conditions and makes a stale display difficult to distinguish from a failed actuator.

A BOOL also has time behavior. A momentary pushbutton may be true for several scans. An edge detector creates a one-scan event from that level. A latched fault remains true after the initiating condition clears until the reset rules are satisfied. None of those behaviors is contained in the type itself; they come from logic around the bit. Document whether a tag is a level, pulse, latch, request or acknowledgement.

Startup values deserve deliberate treatment. False may mean stopped, healthy, not initialized or communications missing depending on the tag. Those meanings are not interchangeable. When missing communications is important, provide a separate quality or connection status instead of allowing a default false value to impersonate a healthy process state. During tests, inspect power-up, warm restart and the first scan as separate conditions.

  • Use positive, observable names such as ValveOpenFeedback instead of ambiguous abbreviations.
  • Keep operator request, PLC command and physical feedback as separate tags.
  • Document whether a bit is a maintained level, one-scan pulse, latch or derived status.
  • Test initial state, transition order, stuck-on input and contradictory feedback.

Whole-number arithmetic

INT and DINT fail at the edges, not in the easy middle

Integer logic is exact within its valid range. The engineering risk appears when sign, width, division or intermediate arithmetic does not match the requirement.

Trace an integer from raw count to accepted value

Validate and widen before arithmetic. Clamp only when the requirement says clamping is the correct response; otherwise expose the invalid condition.

INT commonly describes a signed integer of modest width, while DINT describes a wider signed integer. The exact range is part of the platform contract, so use the controller manual when the boundary matters. In portable reasoning, the important distinction is width: DINT provides much more room for counts and intermediate arithmetic. It does not make arithmetic limitless, and it does not repair a signed-versus-unsigned mismatch at an input register.

Intermediate results are a frequent trap. Suppose two INT values are multiplied and then assigned to DINT. On some systems the multiplication may occur at INT width before the result is widened. The destination can hold the answer, but the answer has already overflowed. Convert or promote the operands before the operation. The same discipline applies to accumulated production counts, encoder calculations and scaled analog values.

Integer division discards the fractional remainder. That can be correct for indexing or grouping and wrong for flow, speed or efficiency. Make the intention visible: keep integer arithmetic when truncation is required, or convert to REAL before division when the fractional result carries engineering meaning. Test negative operands as well because rounding direction can differ from an informal “drop the decimals” mental model.

Overflow handling is platform-dependent. A value may wrap, saturate, fault an instruction or set diagnostic flags. Never base a production safety claim on assumed behavior. Prevent overflow through range design, explicit checks and appropriately wide types; then verify the exact target behavior. In a learning simulator, use edge cases to see how your control strategy responds, not to certify a vendor CPU.

Analog calculations

REAL represents useful decimals, not mathematical perfection

Floating-point values make scaling and process calculations readable, but finite precision changes how equality, accumulation and display rounding should be designed.

Build a tolerant analog comparison

A process usually needs a band, not exact equality. The band should come from sensor resolution and process requirements rather than a random tiny number.

REAL is suitable for temperature, pressure, speed, level and calculated ratios that need fractional values. Its decimal display can create false confidence: many decimal fractions cannot be represented exactly in binary floating point. A sequence of valid calculations may produce 9.999999 instead of 10.0. For that reason, exact equality is usually the wrong acceptance rule for calculated REAL values.

Use inequalities, hysteresis or a documented tolerance. If a setpoint is 50.0 °C, a control decision might turn on below 49.5 and turn off above 50.5. A verification check might accept an absolute error no greater than 0.05 because that matches sensor resolution and the process requirement. The tolerance must be meaningful; an arbitrary epsilon copied from software code can be either too strict to pass or too loose to protect the process.

Repeated addition can accumulate error. Totalizers and billing-related quantities often benefit from fixed-point integer accumulation—such as storing millilitres or watt-seconds—followed by conversion for display. REAL can still be appropriate, but decide from the maximum duration, required resolution and audit need. Keep raw and calculated values available long enough to explain a discrepancy.

Display precision is not storage precision. Formatting a value to one decimal place does not change the underlying tag unless the program explicitly rounds it. Likewise, an HMI that shows 10.0 may be hiding a value just below or above the threshold. Tests should assert the control behavior and an acceptable numeric band rather than trusting the formatted text alone.

REAL comparison patterns
RequirementWeak implementationStronger implementationEvidence to retain
Reached targetPV = SPABS(PV - SP) <= accepted tolerancePV, SP, tolerance and sample time
High alarmPV > limit with no return bandRaise above high limit; clear below high limit minus deadbandRaise and clear thresholds
Scaled inputOne opaque expressionNamed raw, span and engineering-unit stages with range checksRaw count and scaled result
Long totalRepeated REAL addition without reviewChoose REAL or fixed-point from required range and resolutionMaximum duration and error budget

Durations and bit fields

TIME, WORD and DWORD prevent two different kinds of ambiguity

TIME carries duration meaning. WORD and DWORD carry bit-field meaning. Both are clearer than a generic integer when the operations are temporal or bitwise.

Two representations, two operation families

The stored bits may be similar in memory, but the program should reveal whether engineers are reasoning about elapsed time or independent flags.

TIME represents a duration used by timers, pulse widths, debounce periods and sequence supervision. A typed literal makes the unit visible. This matters because an integer value of 5000 can mean milliseconds in one library and seconds in another. Keep wall-clock timestamps separate from durations: “five seconds elapsed” and “2026-08-31 14:05” answer different questions and often use different platform types.

Timer function blocks add state around TIME. A TON commonly has an input, preset time, elapsed time and done output. The block must be evaluated according to the platform scan model. Changing a preset while a timer runs, resetting the input near completion and using a preset shorter than the task period are boundary behaviors that deserve explicit tests. The type communicates duration, while the block defines temporal state transitions.

WORD and DWORD are bit strings. Use them for device status registers, communication flags, alarm bitmaps and compact masks when each bit has a documented meaning. A bit string can be displayed as hexadecimal because hex groups bits cleanly. Convert to a numeric type only when the entire pattern genuinely represents a magnitude. Conversely, do not pack unrelated states merely to save a few tags if doing so makes diagnostics obscure.

Bit numbering and byte order become important at boundaries. Protocol documentation may call the least significant bit bit zero, while a drawing or HMI label starts at one. Multi-register values may order words differently. Define the mapping with an example pattern, then test a value that activates bits in more than one byte or word. A zero-only test cannot expose swapped order.

  • Write duration literals with units and document the task or scan assumptions around timers.
  • Test timer behavior at zero, one scan below, exactly at and one scan above the preset boundary.
  • Document every used status bit with its bit number, meaning, active polarity and source.
  • Use non-symmetric test patterns such as 16#8001 to expose bit and byte-order mistakes.

Type boundaries

Make every lossy conversion visible and testable

A conversion is a design decision about range, sign, rounding and failure behavior. Hiding it inside a long expression makes the most fragile part of the calculation hardest to review.

A safe conversion boundary

The validation belongs before the narrowing conversion. Once information has been truncated or wrapped, a later range check cannot reconstruct it.

Widening an INT to DINT normally preserves a valid value. Narrowing a DINT to INT can lose high-order information. Converting REAL to an integer discards or rounds the fraction according to the platform operation. Interpreting WORD as INT may change the upper half of the apparent numeric range because the high bit becomes a sign bit. These are different transformations and deserve different review questions.

Prefer explicit conversion functions or clearly named intermediate tags. PressureRaw, PressureCounts, PressureReal and PressureBar may appear verbose, but they expose the path an engineer must diagnose. One enormous expression that reads a register, changes sign, scales and compares the result conceals which assumption failed. Structured stages also make tests smaller and error messages more specific.

At communication boundaries, store enough context to reverse the interpretation: source register, byte and word order, scaling factor, unit and quality state. If a device uses 65535 as “invalid,” do not scale it into a plausible engineering value. Detect the sentinel first. If a protocol sends two registers for a 32-bit value, test patterns across both halves before commissioning.

Conversions should be reviewed whenever the equipment range, transmitter scaling or protocol map changes. A type that was adequate for a 0–1000 sensor can fail after replacement with a 0–100000 device even though the tag name and control logic remain unchanged. Treat interface changes as contract changes, not mere parameter edits.

Test design

Verify the type contract with values that can break it

A nominal value proves the easy path. A useful type test set proves the edges, invalid inputs, conversions and recovery behavior.

Minimum type-verification matrix

The matrix is intentionally small enough to repeat after a mapping change and broad enough to expose the most common representation errors.

For BOOL, test both levels, each transition, startup and stuck states. For integers, test zero, one, negative one when permitted, the documented extremes and intermediate operations near overflow. For REAL, test the scaling endpoints, a middle value, values just inside and outside tolerance, and a sensor-invalid representation. For TIME, test zero, one scan, the preset boundary, reset and restart. For WORD or DWORD, activate isolated high and low bits plus a pattern spanning byte or word boundaries.

A test should state the requirement, stimulus, observation and verdict. “Try a large number” is not reproducible. “Given ProductionCount is one below the approved maximum, when one accepted product pulse occurs, then the counter equals the maximum and no rollover diagnostic is active” can be rerun after a refactor. Add the next pulse as a separate case that proves the defined overflow policy.

Record evidence from the representation boundary, not only the final output. A wrong scaled pressure can still produce the expected pump command for one convenient input. Capturing raw count, converted value, threshold and command makes the reason visible. This evidence is especially important when a fieldbus, HMI and PLC each display the same bits differently.

Simulation is valuable because edge conditions can be repeated without forcing a live machine. It does not prove hardware I/O conversion, vendor firmware behavior, task scheduling under real load or communication timing. Carry the same test matrix into target-controller simulation and controlled commissioning, adapting it to the site risk assessment.

Example data-type acceptance cases
TagCaseStimulusExpected evidence
MotorRunning (BOOL)Command without feedbackStart request true; feedback remains falseCommand state and timeout/fault remain distinguishable
BatchCount (DINT)Upper approved boundaryIncrement from maximum minus oneMaximum accepted; next-step policy is defined
TankLevelPct (REAL)Alarm hysteresisCross raise and clear thresholds slowlyOne raise and one clear without chatter
MixTime (TIME)Preset boundaryAdvance in known scan incrementsDone changes at the documented temporal boundary
DriveStatus (WORD)Word-order proofApply a non-symmetric diagnostic patternNamed bits match device documentation

Verified product surface

What you can practise here today

The existing simulator already provides a practical subset for learning typed PLC behavior. These claims are tied to runtime and editor code in the repository rather than a future roadmap.

Typed declarations and literals

The interpreter AST includes BOOL, INT, DINT, REAL, TIME, WORD and DWORD alongside timer, counter, trigger and PID function-block instance types.

Numeric forcing

The live force controls handle INT, DINT and REAL values with type-aware bounds or increments so learners can exercise numeric states.

Time and word operations

Runtime utilities format TIME values, mask words and double words, and read or set individual bits for inspection and logic.

Behavioral scenarios

Analog, counter, timer, batch and process scenarios provide typed I/O and executable checks rather than a static syntax reference.

Product boundary

This is an educational runtime, not a claim of complete IEC 61131-3 or vendor conformance. The current scenario I/O contract exposes BOOL, INT and REAL, while the interpreter supports a broader internal scalar set. STRING, every vendor-specific integer width, production communications mapping and exact CPU overflow behavior require target-platform documentation and testing.

Answer-engine questions

Direct answers to the questions engineers ask

What are the most common PLC data types?

The most common transferable types are BOOL for two-state conditions, INT or DINT for signed whole numbers, REAL for fractional engineering values, TIME for durations, and WORD or DWORD for packed bits. Vendor platforms usually add more signed, unsigned, string, date/time, array, structure and user-defined types.

What is the difference between INT and DINT in a PLC?

Both store signed whole numbers, but DINT has a wider range than INT. Use the exact controller manual for the supported widths and overflow behavior. Choose from the maximum credible value and intermediate arithmetic, not from the current example value.

When should I use REAL instead of INT?

Use REAL when the engineering requirement needs fractional values, such as pressure, flow, temperature or a ratio. Keep INT or DINT for exact counts and fixed-point values. When converting to REAL, define a comparison tolerance and retain enough raw evidence to diagnose scaling.

Why should REAL values not be compared with exact equality?

Binary floating-point cannot represent every decimal fraction exactly, so valid arithmetic can produce a value slightly above or below the displayed decimal. Compare with an engineering tolerance, hysteresis band or greater-than/less-than threshold derived from the process requirement.

Is WORD the same as INT?

The bits may occupy a similar-sized storage area on some platforms, but the meanings differ. INT is a signed numeric magnitude; WORD is a bit string suited to masks and independent flags. An explicit conversion may reinterpret the high bit as a sign, so document and test it.

What is TIME used for in PLC programming?

TIME represents a duration for timer presets, elapsed values, delays, debounce periods and sequence supervision. It is not automatically a wall-clock timestamp. Typed duration literals make the unit visible and reduce milliseconds-versus-seconds errors.

How do I choose a PLC data type for an analog input?

Keep the raw device value in a type that matches the I/O or protocol contract, validate diagnostic and out-of-range codes, then convert into a named REAL engineering-unit tag if fractional calculations are needed. Preserve the raw value and quality state for troubleshooting.

What causes integer overflow in a PLC?

Overflow occurs when an operation produces a value outside the valid range of its type. Accumulation, multiplication and narrowing conversions are common causes. Widen operands before risky arithmetic, check ranges explicitly and verify the exact target-controller response.

Can I practise PLC data types without hardware?

Yes. A simulator can exercise typed declarations, conversions, thresholds, timers and boundary cases repeatedly. It cannot certify physical I/O scaling, firmware-specific behavior or production task timing, so repeat critical acceptance tests on the target platform.

Which PLC data types does this simulator support?

The browser interpreter models BOOL, INT, DINT, REAL, TIME, WORD and DWORD plus TON, TOF, TP, CTU, CTD, CTUD, R_TRIG, F_TRIG and PID instances. Individual scenarios expose a narrower I/O set, and the product does not claim full IEC or vendor conformance.

Turn the guide into evidence

Turn type choices into executable boundary checks

Pick a scenario with analog values, counters or timers. Write down the range and failure policy first, then run nominal, boundary and recovery cases until the typed behavior is evidence rather than assumption.

Run a typed PLC exercise