ET 200SP AI Energy Meter CT ST: DRV Compile and Counter Restore

David Krause14 min read
SiemensTechnical ReferenceTIA Portal
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

1. Module Identification and System Context

The SIMATIC ET 200SP AI Energy Meter CT ST (article number 6ES7134-6PA01-0BU0) is a 2-channel analog input module designed to record electrical energy and power values on single-phase and three-phase AC systems using external current transformers. The module plugs into a standard ET 200SP BaseUnit and communicates with the head module (IM 155-6) over the internal backplane bus. The module occupies a width of 15 mm and provides 32 bytes of input data and 20 bytes of output data to the controller, which must be configured as the matching submodule variant in the device configuration.

Per the official ET 200SP manual collection, the module is commissioned in TIA Portal by inserting it into the ET 200SP station, choosing the submodule variant with 32 bytes of input and 20 bytes of output, and assigning the channel parameters. The quick-start documentation walks through wiring, parameter assignment, and the diagnostic data records of the module.

AI Energy Meter CT ST (6ES7134-6PA01-0BU0) - Quick Start in the TIA Portal Manual Collection

Table 1 - AI Energy Meter CT ST Identification
Attribute Value
Article number 6ES7134-6PA01-0BU0
Module type Analog input (energy meter)
Signal type Current transformer (CT)
Input data length 32 bytes
Output data length 20 bytes
Width 15 mm
Required BaseUnit BU type A0 (light-colored)
Head module IM 155-6 (PROFINET or PROFIBUS)

2. Library Package Contents

The AI Energy Meter application library (Siemens documentation number 86299299) ships as a TIA Portal library and contains the function blocks, data blocks, PLC data types, and HMI faceplates required to evaluate the raw values of the AI Energy Meter CT ST. The library is delivered as a compiled, know-how protected package so that the application logic can be instantiated in a project without exposing the source. A small set of test/example projects is included in the delivery to demonstrate commissioning.

The core blocks of the library are:

  • E2M_AIEnergyMeter_DRV - main function block (FB) that processes the input image of the module, performs the energy and power calculation, and drives the HMI bits.
  • E2M_AIEnergyMeter_DRV_DB - instance data block for the DRV FB; contains the Restore_En_Count_Values structure that must be retained across power cycles.
  • HMI_Bits - input structure that aggregates the HMI control and status bits, passed to the DRV FB.
  • PLC data types - UDTs describing the input process image, the restore structure, and the HMI tag area.
Note: The library is delivered in compiled form with know-how protection. The blocks cannot be recompiled from source without the matching password; see Section 4 for the supported workflow.

3. Prerequisites

Before the library can be put into service the following items must be available:

  1. TIA Portal V16 or higher, matching the library release version. Consult the release notes of documentation 86299299 for the exact TIA Portal / CPU firmware compatibility matrix.
  2. An S7-1500 CPU (recommended) or S7-1200 with firmware V4.2 or higher that supports WRREC and the AI Energy Meter library.
  3. An ET 200SP station with an IM 155-6 head module and a BU type A0 BaseUnit under the module slot.
  4. The AI Energy Meter CT ST module (6ES7134-6PA01-0BU0) with the 32/20-byte submodule variant selected in the device configuration.
  5. The library archive (TIA Portal Library, *.zal15 file) opened and the master copies dragged into the project library.
  6. Current transformers wired to the module per the wiring section of the quick start.
  7. Free space in the load memory of the CPU to retain the Restore_En_Count_Values structure.

4. Initial Compilation and Know-How Protection

When the library is first inserted into a project, the FBs arrive in compiled form. If the documentation asks the engineer to recompile the library blocks (for example when changing firmware or when re-importing into a newer TIA Portal version), TIA Portal will display a dialog requesting the know-how protection password. Without this password the recompile aborts and the program cannot be downloaded to the CPU.

Common error message: "Cannot compile block ... because it is know-how protected. The password is required."

There are two supported ways to proceed:

  1. Use the compiled blocks as delivered - do not trigger a recompile. The supplied instance DB and the program already match the library version. This is the path used for the vast majority of installations.
  2. Recompile from source - request the source version of the library (with password) from Siemens Support, open the project that contains the sources, recompile, and then re-archive. The compiled result is functionally identical to the delivered binary.

If a recompile is forced by TIA Portal during a project upgrade, open the library archive, drop the FBs into the project tree first, and only then trigger a full project compile. This avoids the password dialog and uses the pre-compiled binaries that ship with the library. The user-level program (call sites in OB1, OB100, instance DBs) is compiled normally - only the library FBs are protected.

5. Energy Counter Retention Architecture

The AI Energy Meter CT ST module integrates the energy counters in the input image of the module. The DRV FB copies these counters into the instance DB and accumulates them. To survive a power off / restart of the CPU, the relevant area of the instance DB must be marked as retentive and the values must be restored at the start of the DRV.

The library handles two persistence layers:

  • DRV-internal accumulation - the DRV FB keeps running totals in the instance DB E2M_AIEnergyMeter_DRV_DB.
  • Retain of Restore_En_Count_Values - the structure that stores the last saved counter values, declared as RETAIN in the DB so that the PLC load memory keeps the value across power cycles.

By default the library enables retention of the Restore_En_Count_Values area. The engineer must verify in the DB properties that the "Retain" attribute is set for this structure. If retention is not active the counters reset to zero on every restart regardless of the WRREC restore procedure described in Section 6. To check: open the instance DB in TIA Portal, select the Restore_En_Count_Values structure, and inspect the "Retain" column in the table view.

6. WRREC Restore Procedure (Register / Data Record 143)

The DRV FB does not automatically re-write the saved counter values back into the module on restart. The module holds the energy counters internally and the DRV expects them to be restored by the user program before the DRV is enabled. Siemens documents this in the application notes of the library as data record 143 (decimal). The procedure is:

  1. After a CPU restart, run the startup OB (OB100 for warm restart) before the cyclic OB is processed.
  2. Build a source data block area that contains the last saved energy counter values. A simple BLKMOV or MOVE_BLK in the startup OB copies the values from the retentive Restore_En_Count_Values of the DRV instance DB into a non-retentive working DB that is fed to WRREC.
  3. Call WRREC with the following parameters:
    • ID = hardware identifier of the AI Energy Meter submodule (from the device configuration, e.g. 270). For ET 200SP submodule writes, this is the submodule HW ID, not the head module ID.
    • INDEX = 143 (data record number for the energy counter restore).
    • LEN = length of the restore structure, typically 32 bytes for the AI Energy Meter CT ST.
    • RECORD = ANY pointer to the working DB area that holds the restore data.
  4. Wait for WRREC.DONE = TRUE or WRREC.ERROR = TRUE before enabling the DRV FB in the cyclic OB. If ERROR is TRUE, evaluate WRREC.STATUS; common status values are 0x80B1 (data length error) and 0x80C3 (resource busy).
  5. Only then set the Enable input of E2M_AIEnergyMeter_DRV to TRUE.
Critical: The WRREC call must be made before the DRV FB is enabled. If the DRV is already running when WRREC is executed, the values written to the module are overwritten by the DRV with the old, in-RAM counter state on the next cycle. Use a startup-only one-shot to serialize the order.

Example SCL call (S7-1500) for the startup OB:

// Startup OB - restore energy counters into the module
// before the DRV FB is enabled in OB1.
IF "FirstRun" THEN
    "FirstRun" := FALSE;
    "wrRec_DB".Restore := "E2M_AIEnergyMeter_DRV_DB".Restore_En_Count_Values;
    "WRREC_DB"(
        REQ     := TRUE,
        ID      := "HwIo_AI_EnergyMeter",   // HW identifier of the submodule
        INDEX   := 143,                      // Data record 143
        LEN     := UINT#32,                  // Length of the restore structure
        DONE    => "wrDone",
        BUSY    => "wrBusy",
        ERROR   => "wrError",
        STATUS  => "wrStatus",
        RECORD  := "wrRec_DB".Restore
    );
END_IF;

7. HMI_Bits Configuration

The HMI_Bits input of the DRV FB carries the control and status flags that are exchanged with the HMI faceplate (for example reset counters, freeze totals, acknowledge alarms, request maintenance data). The bits are not active by default; the user must explicitly enable the connection to the HMI by setting the HMI_Bits_Connected input of the DRV FB to TRUE.

If HMI_Bits_Connected is FALSE, the DRV ignores the entire HMI_Bits input structure and the operator commands from the HMI faceplate have no effect - the toggles in the HMI appear dead. The symptom matches the field behavior: "The HMI_Bits settings at input of E2M_AIEnergyMeter_DRV fb don't work."

Table 2 - HMI_Bits Connectivity
Input Default Effect when FALSE Effect when TRUE
HMI_Bits_Connected FALSE All HMI commands ignored; faceplate buttons inert HMI commands processed by DRV; faceplate buttons live

Set the input to TRUE in the instance DB or in the call site of the DRV FB. The input is a single BOOL at the top of the FB interface, separate from the HMI_Bits structure. The naming reflects the semantic that an HMI is actually wired to the project; leave it FALSE in headless, control-only installations to avoid spurious resets from leftover HMI tags.

8. Commissioning Sequence

The correct order of operations is important because the DRV and the module hold the same counters and the most recent writer wins. Follow this sequence during initial commissioning:

  1. Wire and parameterize the module in TIA Portal (channel parameters, current transformer ratio, mains type, channel diagnostics enable).
  2. Insert the library by opening the *.zal15 archive and dragging the master copies into the project library.
  3. Call the DRV FB from OB1 with the hardware identifier of the submodule as the input. Leave Enable = FALSE for now.
  4. Program the startup OB with the WRREC sequence from Section 6. Use a one-shot flag (e.g. FirstRun) that is set on STOP and cleared on the first scan of the next RUN so that the restore runs on every cold start.
  5. Set HMI_Bits_Connected to TRUE if an HMI is connected.
  6. Compile and download the project. Use "Compile > Software (rebuild all)" so that the library blocks are placed in the project context without forcing a re-archive of the protected source.
  7. Enable the DRV only after the WRREC DONE bit is TRUE. Wire this as a qualifier on the Enable input of the DRV.
  8. Power on the plant and verify the counters resume their previous values per Section 9.
Tip: When the project is downloaded for the first time on a fresh CPU, the restore values are still zero. Run the plant for a known period, stop, restart, and verify the counters are non-zero. This validates the full retention path including the WRREC sequence. A counter that drops back to zero on the first restart means the WRREC did not run or the retain was not set.

9. Verification and Diagnostics

After commissioning, the following checks confirm that the library and the module are operating correctly.

9.1 Counter retention check

  1. Read E2M_AIEnergyMeter_DRV_DB.Restore_En_Count_Values in an online watch table; note the values.
  2. Power off the CPU (STOP -> MRES not required, just remove power).
  3. Power on the CPU; the DRV should re-initialize.
  4. Read the same tags; the values should match the pre-power-off values within one update cycle.

9.2 HMI control check

  1. From the HMI faceplate, trigger a reset of the energy counter.
  2. Verify in the watch table that the corresponding bit in HMI_Bits is set by the DRV and that the counter resets.
  3. If the bit never changes, verify HMI_Bits_Connected is TRUE and that the HMI tags are correctly bound to the HMI_Bits tag area of the instance DB.

9.3 Module diagnostics

The AI Energy Meter CT ST supports standard ET 200SP diagnostics (channel diagnostics, maintenance events). The most useful data records are:

Table 3 - Key Data Records of the AI Energy Meter CT ST
Data Record Purpose Access
0 Module parameter assignment RDREC / WRREC
1 Channel parameter assignment RDREC / WRREC
143 Restore energy counter values WRREC (startup)
192 Diagnostics data RDREC

10. Troubleshooting Matrix

Table 4 - Common AI Energy Meter CT ST DRV Library Issues
Symptom Likely Cause Resolution
Compile error: "Block is know-how protected" Full project compile triggers recompile of library FBs Use the delivered compiled blocks; do not re-archive the library; only compile user blocks
Energy counters reset to 0 after CPU restart WRREC to data record 143 not executed before DRV is enabled, or Restore_En_Count_Values not retentive Add WRREC call to OB100; mark Restore_En_Count_Values as RETAIN; ensure DRV is not enabled until WRREC is done
WRREC returns status 0x80B1 Length of RECORD does not match the module's expected 32 bytes Verify the LEN parameter matches the size of the restore structure
WRREC returns status 0x80C3 Module still busy after a previous write Wait for BUSY to drop; serialize the call; check the previous DONE bit
WRREC returns status 0x80A1 Wrong HW identifier passed (head module ID instead of submodule ID) Use the submodule hardware identifier from the device configuration
HMI toggles have no effect on the DRV HMI_Bits_Connected is FALSE Set the input to TRUE in the instance DB or in the FB call
Counter values jump at startup DRV enabled before WRREC completed Hold Enable FALSE until WRREC DONE = TRUE
Module not detected in device configuration HSP / GSD not installed for the module variant Install the latest HSP for the AI Energy Meter CT ST; restart TIA Portal
Library version mismatch warning at download Project uses an older *.zal15 than the installed TIA Portal library master copies Re-drag master copies from the current *.zal15; re-download the project

11. Field-Proven Notes

  • Use the same hardware identifier (HW ID) for the AI Energy Meter submodule in both the DRV call and the WRREC call. Mixing the IM 155-6 head identifier and the module identifier is a common reason the module does not respond to the WRREC.
  • Keep the WRREC call in OB100 (warm restart) and not in OB101/OB102 unless the application specifically needs cold or hot restart semantics. The DRV FB expects the module to be in a known state and the warm restart is the typical path for energy-meter retention.
  • Mark only the Restore_En_Count_Values area as retentive. Marking the whole instance DB retentive can increase the load memory footprint unnecessarily and may slow the restart.
  • When upgrading the library, install the new version of the *.zal15 file first, then re-drag the master copies. Do not delete and re-create the instance DBs by hand; the DRV will pick up the new version on download.
  • If the energy counters must survive a CPU STOP/RUN transition as well as a power off, the WRREC sequence must run on every STOP -> RUN transition, not just on a power-on. Use a one-shot flag that is set on STOP and cleared on the first scan of the next RUN.
  • For three-phase meters, verify the current transformer polarity (k -> L direction) and the phase assignment (L1, L2, L3). A reversed CT on a single phase will cause the power calculation to read near zero while the counters still increment from noise.
  • When the CPU is in RUN but the module has been removed or failed, the DRV inputs become zero. The library reads the input image directly; a module failure does not raise a PLC stop, so monitor the channel diagnostics via data record 192 in the HMI faceplate.

For the official quick-start procedure and the full set of supported data records, refer to the TIA Portal manual collection entry for the AI Energy Meter CT ST: 6ES7134-6PA01-0BU0 Quick Start.

FAQ

Why does TIA Portal ask for a password when I try to recompile the AI Energy Meter library?

The library is delivered as a compiled, know-how protected TIA Portal library. A full project compile forces a recompile of the protected FBs and the password dialog appears. Use the delivered compiled blocks instead - do not trigger a recompile of the library FBs. Only re-archive the library from a source version you have the password for.

The energy counters reset to zero after a power off. What is the correct way to retain them?

Mark Restore_En_Count_Values in the DRV instance DB as RETAIN, and in the startup OB (OB100) call WRREC with INDEX = 143 to write the saved values back into the module. Wait for DONE before enabling the DRV FB. The module does not store the counters itself across a CPU restart; the restore must be done by the user program.

HMI commands do nothing even though the faceplate is wired to the DRV. Why?

The HMI_Bits_Connected input of the DRV FB is FALSE by default. When FALSE, the DRV ignores the entire HMI_Bits structure. Set the input to TRUE in the instance DB or at the call site of the FB; the HMI commands will then take effect and the faceplate buttons will respond.

What data record holds the energy counter restore values for the AI Energy Meter CT ST?

Data record 143 is used to restore the energy counter values into the module. The write is performed with WRREC using the hardware identifier of the submodule and a RECORD that matches the 32-byte restore structure expected by the module. The call must complete before the DRV is enabled.

Which CPU is recommended for the AI Energy Meter library?

An S7-1500 CPU is recommended. The library uses constructs (WRREC with large data records, retentive DB areas, complex data types, UDTs) that are fully supported on S7-1500. S7-1200 with firmware V4.2 or higher is supported for smaller installations, but verify the specific library release notes for the exact CPU compatibility list.

Back to blog