How to Configure the FirstScan Bit in Siemens TIA Portal

Summary

The First Scan (FirstScan) trigger coordinates the initialization of program elements across the PLC upon initial startup or when the PLC transitions from stop to run. This engineering brief demonstrates how to enable this functionality in TIA Portal using the S7-1200 PLC shown in Figure 1. We assume a working knowledge of TIA Portal as the FirstScan operation is an intermediate PLC topic.

:stopwatch: Estimated reading time: 4 minutes

:link: This article is part of DigiKey’s Siemens PLC and Automation Resource Hub. Visit the hub for more technical briefs on Siemens components, applications, and programming.

What is the PLC’s First Scan and Why Is It Important

The First Scan is a system-level Boolean memory location. This bit, hereafter called FirstScan, is automatically set TRUE for the first, and only the first program scan cycle.

FirstScan serves as an initializer flag. The programmer can use this one-shot to perform an orderly initialization of their Program Organizational Units (POUs). For example, FirstScan may be used within a conditional assignment block to initialize a state machine to the idle state.

// FirstScan prototype in structured text
IF "FirstScan" THEN
    // Initialize my variables
END_IF;

As a system-level memory location, we can expect the FirstScan to be pulsed every time the PLC is powered on or when transitioning from stop to run. With proper attention, FirstScan becomes an essential part of the PLC startup, yielding consistent and predictable program initialization.

Figure 1: A Siemens S7-1200 PLC on the author’s workbench.

What steps are required to enable the FirstScan in Siemens TIA Portal?

Two steps are necessary to enable the Siemens FirstScan:

  1. Enable the system memory bits option as shown in Figure 2.

  2. Compile and then download the new hardware configuration as shown in Figure 3.

Tech Tip: Don’t confuse the hardware process shown in Figure 3 with the primary program (e.g., ladder logic). They have different and independent PLC download mechanisms. We can think of these in terms of configuration (prepare the hardware) and software (to run your program).

I encountered this the hard way when the main program would compile but the FirstScan-related code failed to operate. Surprisingly, the TIA Portal code compiled even when the system memory bits are disabled.

Figure 2: Location of the FirstScan enable checkbox within TIA Portal.

Figure 3: Location of the hardware compile and download options within TIA Portal.

Verification of the FirstScan

This simple structured text program demonstrates the operation of the FirstScan bit. For this program there are three inputs, including a selector switch and an on-off-on momentary selector switch. There are also two outputs for the dual-colored red/green panel lamp.

FirstScan is found in the first line of the program where it is used to initialize the panel lamp color based on the state of the selector switch. This provides a highly visible indicator that the FirstScan logic is operating.

We have high confidence of success when we power cycle the PLC and the panel lamp color changes based on the position of the selector switch.

Code Block to Demonstrate FirstScan Operation

// FirstScan Initialization Demonstration
IF "FirstScan" THEN

    IF "gxSW1" THEN
        "gxPLGreen" := FALSE;
        "gxPLRed" := TRUE;
    ELSE
        "gxPLGreen" := TRUE;
         "gxPLRed" := FALSE;
    END_IF;

END_IF;

IF "gxSSLeft" THEN
    "gxPLGreen" := FALSE;
    "gxPLRed" := TRUE;
END_IF;

IF "gxSSRight" THEN
    "gxPLGreen" := TRUE;
    "gxPLRed" := FALSE;
END_IF;

Tech Tip: Personally, I like to use Hungarian notation as a reminder of the scope and type of memory. In this application the prefix gx stands for global and Boolean.

Frequently Asked Questions

What is the purpose of the FirstScan bit?

The FirstScan bit is an enable signal. This trigger signal occurs when the PLC is first powered on or when transitioned from stop to run.

When your programs detect this bit, they know it’s time to initialize the critical memory locations such as a counter to zero or a state machine to the idle state.

Why doesn’t my FirstScan work?

Assuming your primary program(s) compiles, chances are high there are three likely problems:

  • System memory bits not enabled (see Figure 2)
  • Hardware changes not compiled (see Figure 3)
  • Hardware changes not downloaded to the PLC (Figure 3)

Parting Thoughts

The FirstScan bit is like the first breath a PLC takes when it awakens. It signals that it’s time to get your house in order in preparation for the real work that is to come.

Best wishes,

APDahlen

Related Articles by this Author

If you enjoyed this article, you may also find these related articles helpful:

About This Author

Aaron Dahlen, LCDR USCG (Ret.), serves as an application engineer at DigiKey. He has a unique electronics and automation foundation built over a 27-year military career as a technician and engineer which was further enhanced by 12 years of teaching (interwoven). With an MSEE degree from Minnesota State University, Mankato, Dahlen has taught in an ABET-accredited EE program, served as the program coordinator for an EET program, and taught component-level repair to military electronics technicians.

Dahlen has returned to his Northern Minnesota home, completing a decades-long journey that began as a search for capacitors. Read his story here.