PLC Programming · Lab Manual

Siemens PLC Data Types and Memory Areas: Lab Manual with I, Q, DB, UDT and Retain

The wrong data type is a bug that waits: an Int counter that turns negative after 32,767 parts, a Real that is never exactly 5.0, a count lost on a power cut. This lab manual chooses types the professional way through all six stages and lets you watch each failure happen live.

2,500+ engineers trained 4.9/5 Google rating 21+ years, Chinchwad, Pune Next batch: contact for dates
Quick answer

Bool for single bits, Int up to 32,767, DInt for anything that accumulates, Real for scaled measurements and Word for grouped status bits. Physical signals live in the process image (%I, %Q) and are copied once into DB_IO; application data lives in optimized global DBs built from UDTs, with Retain set only on values that must survive a power cut.

  • DInt for counters and totals – Int overflows at 32,767.
  • Never compare a Real for exact equality; use a tolerance.
  • Retain values that matter after a power cut, not machine state.

Why Data Types Matter

Choosing a type is choosing what can go wrong. An Int that should have been a DInt turns negative after 32,767 parts; a Real compared for equality never matches; a non-retentive counter is zero after a power cut. Get the type right once, at the DB, and every block and every HMI tag inherits it.

Lab Flow: From Sensor Signal to the Right Data Type

Every lesson in the Softwell PLC lab manual series follows the same six stages and the same address rule, so the code you write here plugs straight into the HMI lessons.

Lab manual flow: field input to tested HMI screenSix stages: field device and PLC tag, input mapping to DB_IO, PLC logic, HMI tags, graphics linking, and perform and test.1Field + tags%I6.3 %IW100Bool, Int2Input mappingFC_InputMapping→ DB_IO Real3LogicUDT_ProdDInt, Word, retain4HMI tagsDB_Prod_*types must match5GraphicsFields, lampssingle-bit anim.6Perform + testSimulatoroverflow, retainAddress rule for every lesson: %I only in FC_InputMapping, %Q only in FC_OutputMapping, symbolic DB members everywhere else – including the HMI.
Figure 1 – Six-stage lab flow for this lesson.

Stage 1Field Signals and PLC Tag Table

PLC tagAddressTypeDevice / comment
B30_Part%I6.3BoolPart sensor at the outfeed
PT30_Raw%IW100IntPressure transmitter 4–20 mA = 0 – 27648 (0 – 10 bar)
H30_Status%QW84WordExample of a 16-bit status output to a remote I/O panel
TypeSizeRangeUse for
Bool1 bit0 / 1Contacts, commands, status bits
Int16 bit−32,768 … 32,767Raw analog values, small set values
DInt32 bit±2,147,483,647Counters, totals, runtime seconds
Real32 bit float±3.4E38, ~7 digitsScaled measurements, setpoints
Word / DWord16 / 32 bitbit patternGrouped status and fault bits for the HMI
Time32 bit±24 days (ms)Timer presets and elapsed times
Stringup to 254 charstextProduct codes, user names

Stage 2Input Mapping and Memory Areas

AreaExampleWritten byRule in this series
Inputs (process image)%I6.3, %IW100Input moduleRead only in FC_InputMapping
Outputs (process image)%Q3.0Program → output moduleWritten only in FC_OutputMapping
Bit memory%M10.0ProgramAvoid in new projects
Data blocks"DB_Prod".Count_DIntProgram, HMIAll application data, symbolic, optimized
Temp / static#tmp, #statBlockLocal to FC/FB
// FC_InputMapping
"DB_IO".B30_Part  := "B30_Part";
"DB_IO".PT30_bar  := SCALE_X(MIN := 0.0, MAX := 10.0,
                     VALUE := NORM_X(MIN := 0, VALUE := "PT30_Raw", MAX := 27648));

Scaling details: PLC analog input scaling.

Stage 3Logic: UDT_Prod, Retain and Safe Comparisons

// PLC data type UDT_Prod
Count_DInt : DInt;    // accumulates → DInt, Retain in DB_Prod
Pressure   : Real;
Status     : Word;    // %X0 run, %X1 overload, %X2 door … for the HMI

// FB_Production – STAT: PartOld : Bool;
IF "DB_IO".B30_Part AND NOT #PartOld THEN
    "DB_Prod".Data.Count_DInt := "DB_Prod".Data.Count_DInt + 1;
END_IF;
#PartOld := "DB_IO".B30_Part;
"DB_Prod".Data.Pressure := "DB_IO".PT30_bar;

// Never: IF "DB_Prod".Data.Pressure = 5.0 THEN …   (exact Real compare)
"DB_Prod".AtSetpoint := ABS("DB_Prod".Data.Pressure - 5.0) < 0.05;

"DB_Prod".Data.Status.%X0 := "DB_M1".Run_Cmd;     // slice access into a Word

Tick Retain for Count_DInt in DB_Prod; leave commands and state non-retentive. The same Word-of-bits idea drives the HMI alarm word in HMI alarm configuration.

Stage 4Link PLC Tags to the HMI

Drag DB_Prod into the HMI tag table – TIA Portal copies the data types exactly. A Real written into an Int tag silently loses its decimals, as shown in HMI I/O fields and setpoint entry.

HMI tagPLC memberUsed by
DB_Prod_Data_Count_DInt"DB_Prod".Data.Count_DInt (DInt)Output field
DB_Prod_Data_Pressure"DB_Prod".Data.Pressure (Real)Output field 99.99 bar
DB_Prod_Data_Status"DB_Prod".Data.Status (Word)Lamps with single-bit animation

Stage 5Link the Graphics

#ObjectPropertiesTag / event
①Output field countFormat 999999999, no decimalsDB_Prod_Data_Count_DInt
②Output field pressureFormat 99.99, unit text barDB_Prod_Data_Pressure
③8 lampsAppearance animation type Single bit, bit 0 … 7DB_Prod_Data_Status

Stage 6Perform and Test: Data Types Live

Parts are counted into an Int and a DInt at the same time; a Real pressure drifts around 5.0 bar; a Word packs eight status bits for the HMI. Watch the Int overflow, the exact Real comparison that never fires, and the effect of the Retain setting on a power cycle.

Field and PLC
HMI · Data type monitor
Data typesDB_Prod
Count_Int (Int)
Count_DInt (DInt)
PT30 (Real, bar)
PT30 = 5.0 (exact)|PT30 − 5.0| < 0.05
Status (Word)

Troubleshooting

SymptomLikely causeFirst check
Counter jumps to −32768Int overflowUse DInt
Comparison never trueExact Real equalityUse a tolerance or range
Count lost after power cutMember not retentiveRetain checkbox in the DB
HMI shows wrong valueHMI tag type differs from PLCDrag DB members, do not type addresses

Hands-On Lab: Choose and Prove PLC Data Types

Hands-on
Before you start
  • TIA Portal with an S7-1200 or PLCSIM
  • Estimated time: 60 minutes
1

Declare the tags with the right types

Declare B30_Part (Bool), PT30_Raw (Int) and the status outputs, and note each type's range.

Each tag has the type that fits its range.
2

Map and scale into DB_IO

Copy B30 and scale PT30 to bar (Real) in FC_InputMapping.

DB_IO.PT30_bar reads in bar.
3

Build UDT_Prod and DB_Prod

Create a UDT with Count_DInt, Pressure, Status (Word) and a retentive DB_Prod; count with an edge.

Count_DInt increments once per part and survives a power cycle.
4

Link HMI tags

Drag DB_Prod into the HMI tag table and check that every HMI type matches.

HMI and PLC types are identical.
5

Display and test

Show counts, pressure and status bits, then power-cycle the CPU and verify retain.

Status lamps follow single bits of the Word.
6

Prove the failure cases

Force an Int past 32,767, compare a Real for equality and confirm the tolerance version works.

Int overflows at 32,767 while DInt keeps counting; the tolerance compare works.
Checkpoint—how to know you did it right

Every value has a type that fits its range and use, counts survive a power cycle, and no comparison depends on exact floating-point equality.

Frequently asked questions

When should I use DINT instead of INT?

Whenever a value accumulates. INT stops at 32,767, so production counts, runtime seconds and totalisers need DINT.

What is the difference between optimized and standard data blocks?

Optimized blocks store data in the CPU's preferred order and are accessed only symbolically. Standard blocks keep a fixed byte layout and allow absolute addressing, which some older partners require.

Why does my REAL comparison never trigger?

Floating point values are rarely exactly equal to a constant. Compare against a range or use a tolerance instead of testing for exact equality.

What does retentive memory actually protect?

Values you need after a power cycle, such as production counters, runtime hours and recipe parameters. Machine state and commands should normally start clean.

Should I still use M memory in new projects?

Sparingly. Optimized DB members are symbolic, cannot clash between programmers and can be released to the HMI. Keep M memory for system bits such as clock memory if you use them at all.

What is a UDT and why use one?

A PLC data type: a named structure such as UDT_Motor that you declare once and reuse for every motor. Changing the UDT updates every instance, and the HMI can use the same structure.

Reviewed by Bhawesh Kumar SinghIndustrial Automation Trainer and Industry 4.0 Consultant · Softwell Automation · 21+ years industry experience

Get the full syllabus + free demo class

Share your details—a Softwell training advisor will contact you with batch dates, fees and hardware-practice options.

No spam. Used only to share course details for this enquiry.

Learn with practical industrial examples

Join live online, Pune classroom or corporate in-plant automation training.

Request Course Details
Verified learning pathway

Discuss Siemens PLC Data Types and Memory

Explore practical curriculum, software, hardware and batch options for this technology.

Content reviewed: 16 October 2026

Siemens PLC & TIA Portal Learning Path

Continue with the related Siemens PLC tutorials in this practical learning series.

  1. SCL vs Ladder Logic
  2. Upload PLC Program
  3. TIA Selection Tool
  4. Analog Input Scaling
  5. PLC Counters
  6. PLC Timers
  7. Addressing & Data Types
  8. Hardware & PLC Tags
  9. OB, FB, FC & DB
☎ Call WhatsApp ✉ Email Enquire Now