Control Expert ยท Track 04 ยท reuse, the Modicon way

DDT & DFB

Two letters apart, two halves of reuse. A DDT (Derived Data Type) is a structure you design once and stamp everywhere โ€” change the type, every copy follows. A DFB (Derived Function Block) is your own reusable logic block with private memory โ€” call it ten times and each call remembers its own state. Play with both.

๐Ÿงฑ DDT = data๐Ÿง  DFB = logic + memory
01 ยท DDT โ€” the data cutter

Change the type, change every copy

Left is the DDT T_Valve. Right are three valves stamped from it in a DB. Click โž• add a field to the type and watch all three instances gain it at once โ€” one edit, zero drift. That's why a DDT beats a pile of loose valve1_open, valve2_open tags.

๐Ÿ“ TYPE T_Valve

the derived data type

๐Ÿ“ฆ valves : ARRAY[1..3] OF T_Valve

3 fields ร— 3 valves
02 ยท DFB โ€” logic with memory

One block, two independent runtimes

Here's the DFB FB_PumpHours โ€” it counts a pump's run-hours, holding the total in its private instance data. It's instanced twice: Pump_1 and Pump_2. Run one and only its meter climbs โ€” same code, separate memory. An EFB or a plain section couldn't do this; the DFB's per-instance storage is the point.

FUNCTION_BLOCK FB_PumpHours
  // PRIVATE (retained per instance):  runHours : REAL;
  // runs each scan:  IF Running THEN runHours := runHours + dt; END_IF;
Pump_1 : FB_PumpHours ยท instance data
๐ŸŒ€
0.0 h
Pump_1.runHours
Pump_2 : FB_PumpHours ยท instance data
๐ŸŒ€
0.0 h
Pump_2.runHours

Fix a bug in FB_PumpHours once and both pumps inherit it โ€” yet Pump_1's hours never leak into Pump_2's. DDT for the shape of data, DFB for reusable behaviour with state: together they're how a Modicon project scales without copy-paste.

03 ยท Check yourself

DDT or DFB?

You need a reusable conveyor controller that holds its own state machine and a timer, dropped onto 8 conveyors. What do you build?