Cookies are important for this site to function properly, to guarantee your safety, and to provide you with the best experience. By clicking OK, you accept all cookies. For more information, please access our Privacy Policy.
Table of Contents
Tutorials / 
Encoder Setup on the S7-1200 G2 Using the Onboard HSC
Advanced

Encoder Setup on the S7-1200 G2 Using the Onboard HSC

Siemens
TIA Portal
S7-1200 G2
Hardware

Introduction

If you've ever needed encoder feedback on an S7-1200 G2 but didn't want to spend on a dedicated Technology Module, you already know the frustration. The onboard High Speed Counter (HSC) is right there, yet by default it won't talk to your Technology Objects. As a result, print-mark positioning, synchronous motion, and probe-based correction feel out of reach without extra hardware. That's exactly the gap the LHSCTO library closes, and it's worth understanding if you want lean, cost-effective machine designs. Whether you're chasing tighter print registration or want your onboard I/O to pull more weight, this is a skill that pays off on real panels, not just in theory.

Overview

It's common in simple automation applications to skip Profibus encoders and extra Technology Modules altogether, using the built-in peripherals instead. The S7-1200 G2 PLC, in its default state, doesn't allow an encoder or measuring probe to be linked to Technology Objects via the onboard High Speed Counter (HSC). What the LHSCTO library does, which you can download here, is establish a connection path for an encoder and measuring probe into specific Technology Objects via the onboard HSC. Whether you need print-mark-based positioning or print mark correction, this applies to synchronous applications. There are two configurations demonstrated in this application example. In the first case, an encoder acts as the leading value, paired with a measuring probe. The second setup involves an encoder serving as the positioning feedback encoder, plus a measuring probe.

Figure 1.1: Encoder setup guide to S7-1200 G2 HSC - Application example overview
Figure 1.1: Encoder setup guide to S7-1200 G2 HSC - Application example overview

Working Principle

Figure 2.1 breaks down the working principle behind the configuration that pairs an encoder with a measuring probe. 

Figure 2.1: Encoder setup guide to S7-1200 G2 HSC - Telegram 83 communication (ExternalEncoder TO & HSC)
Figure 2.1: Encoder setup guide to S7-1200 G2 HSC - Telegram 83 communication (ExternalEncoder TO & HSC)

Figure 2.2 is a visual breakdown of how an encoder configuration operates as the positioning feedback, alongside a measuring probe. 

Figure 2.2: Encoder setup guide to S7-1200 G2 HSC - Telegram 83 communication (PositionAxis TO & HSC)
Figure 2.2: Encoder setup guide to S7-1200 G2 HSC - Telegram 83 communication (PositionAxis TO & HSC)

Through the LHSCTO_HSCEncoder block, the onboard HSC gets tied to the telegram 83 data block interface. As a result, the TOs (Technical Objects) can communicate with the encoder and measuring probe over the HSC.

Figure 2.3: Encoder setup guide to S7-1200 G2 HSC - LHSCTO_HSCEncoder function block
Figure 2.3: Encoder setup guide to S7-1200 G2 HSC - LHSCTO_HSCEncoder function block

Encoder & Probe Configuration

If you need to wire the encoder's A/B phases and the measuring probe to the SIMATIC S7-1200 G2 digital inputs, look at Figure 3.1 for guidance. A 24-volt signal level is the only one the S7-1200 G2 PLC will accept from encoders.

Figure 3.1: Encoder setup guide to S7-1200 G2 HSC - Hardware connection
Figure 3.1: Encoder setup guide to S7-1200 G2 HSC - Hardware connection

HSC1 is set up to work with an encoder here, matching the configuration shown in Figure 3.2.

Figure 3.2: Encoder setup guide to S7-1200 G2 HSC - Encoder HSC configuration
Figure 3.2: Encoder setup guide to S7-1200 G2 HSC - Encoder HSC configuration

Configuration of the 'Capture Input' should match what's shown in Figure 3.3. A rising edge from the sensor is what triggers the input. Different modes are available if you want to change this behavior.

Figure 3.3: Encoder setup guide to S7-1200 G2 HSC - Capture input HSC configuration
Figure 3.3: Encoder setup guide to S7-1200 G2 HSC - Capture input HSC configuration

The onboard hardware inputs tied to the HSC being used also require proper configuration beforehand. You can see the HSC1 configuration used in this example by checking Figure 3.4. Earlier wiring details are what guide the selection of the number of inputs.

Figure 3.4: Encoder setup guide to S7-1200 G2 HSC - Hardware inputs HSC configuration
Figure 3.4: Encoder setup guide to S7-1200 G2 HSC - Hardware inputs HSC configuration

The 'MC_Servo' organization block needs to have the input addresses of the used HSC assigned to it. Figure 3.5 shows a visual of the configuration used here.

Figure 3.5: Encoder setup guide to S7-1200 G2 HSC - I/O addresses HSC configuration
Figure 3.5: Encoder setup guide to S7-1200 G2 HSC - I/O addresses HSC configuration

Following the layout in Figure 3.6, in this application example, channels 0 through 7 each had their input filters adjusted. The digital input channels currently in use require their input filters to be changed to just 0.1 microseconds. Signal changes might slip past undetected if the input filter time is set too long.

Figure 3.6: Encoder setup guide to S7-1200 G2 HSC - Digital input channels configuration
Figure 3.6: Encoder setup guide to S7-1200 G2 HSC - Digital input channels configuration

Technology Objects Configuration

You'll need to create and configure Technology Objects according to whatever configuration is required. If you're working with the 'ExternalEncoder' Technology Object configuration, the encoder's data connection must be set up using a telegram-83-based data block, following what's shown in Figure 4.1.

Figure 4.1: Encoder setup guide to S7-1200 G2 HSC - Encoder hardware interface (ExternalEncoder TO)
Figure 4.1: Encoder setup guide to S7-1200 G2 HSC - Encoder hardware interface (ExternalEncoder TO)

A rotatory measuring system rated at 2048 increments per revolution, combined with standard telegram 83, is used in this application project, as shown in Figure 4.2. With the HSC's A/B counter configured as fourfold, the 'Bits in Gx_XIST1' fine resolution setting comes out to 2, since multiplying by 4 corresponds exactly to a shift of 2 bits.

Figure 4.2: Encoder setup guide to S7-1200 G2 HSC - Encoder data exchange (ExternalEncoder TO)
Figure 4.2: Encoder setup guide to S7-1200 G2 HSC - Encoder data exchange (ExternalEncoder TO)

Whenever a measuring probe is required, it should be configured through the PROFIdrive telegram within the 'MeasuringInput' Technology Object, exactly as shown in Figure 4.3. A value of 1 for the 'Number of Measuring Probe' option maps directly to the HSC's recording input. No matter which specific hardware input address is configured in the HSC settings, the measuring probe's value stays fixed permanently at 1 when using an HSC.

Figure 4.3: Encoder setup guide to S7-1200 G2 HSC - ExternalEncoder TO measuring probe
Figure 4.3: Encoder setup guide to S7-1200 G2 HSC - ExternalEncoder TO measuring probe

The 'LHSCTO_HSCEncoder' function block's 'hwID_HSC' input is assigned to the configured high-speed counter's system constant, as illustrated in Figure 4.4. That particular tel83-based data block ends up getting assigned to the 'tel83' InOut.

Figure 4.4: Encoder setup guide to S7-1200 G2 HSC - HSC assignment to ExternalEncoder TO
Figure 4.4: Encoder setup guide to S7-1200 G2 HSC - HSC assignment to ExternalEncoder TO

In the 'ExternalEncoder' Technology Object scenario, you will need to configure the encoder's data connection using a properly built telegram 83 data block, exactly as shown in Figure 4.5. This example has the encoder set up as 'Encoder 2'.

Figure 4.5: Encoder setup guide to S7-1200 G2 HSC - Encoder hardware interface (PositioningAxis TO)
Figure 4.5: Encoder setup guide to S7-1200 G2 HSC - Encoder hardware interface (PositioningAxis TO)

A rotatory measuring system rated at 2048 increments per revolution, combined with standard telegram 83, is used in this application project, as shown in Figure 4.6. With the HSC's A/B counter configured as fourfold, the 'Bits in Gx_XIST1' fine resolution setting comes out to 2, since multiplying by 4 corresponds exactly to a shift of 2 bits.

Figure 4.6: Encoder setup guide to S7-1200 G2 HSC - Encoder data exchange (PositioningAxis TO)
Figure 4.6: Encoder setup guide to S7-1200 G2 HSC - Encoder data exchange (PositioningAxis TO)

Defining the extended mechanical parameters for the external encoder has to align closely with the given system parameters. This particular configuration for this scenario is shown in Figure 4.7.

Figure 4.7: Encoder setup guide to S7-1200 G2 HSC - Encoder mechanics extended parameters (PositioningAxis TO)
Figure 4.7: Encoder setup guide to S7-1200 G2 HSC - Encoder mechanics extended parameters (PositioningAxis TO)

The 'PositioningAxis' Technology Object's external encoder supports active homing through a digital input, through a PROFIdrive telegram zero mark, or through a combination of a reference cam together with a PROFIdrive telegram zero mark. For 'Encoder 2' in this example, the PROFIdrive telegram zero mark is used, as shown in Figure 4.8. It gives the 'PositioningAxis' Technology Object the ability to treat its connected measuring probe, via HSC, as a zero mark.

Figure 4.8: Encoder setup guide to S7-1200 G2 HSC - Encoder active homing mode (PositioningAxis TO)
Figure 4.8: Encoder setup guide to S7-1200 G2 HSC - Encoder active homing mode (PositioningAxis TO)

Whenever a measuring probe is required, it should be configured through the PROFIdrive telegram within the 'MeasuringInput' Technology Object, exactly as shown in Figure 4.9. Only when the 'Number of Measuring Probe' setting equals 1 does the onboard HSC actually support the measuring probe.

Figure 4.9: Encoder setup guide to S7-1200 G2 HSC - PositioningAxis TO measuring probe
Figure 4.9: Encoder setup guide to S7-1200 G2 HSC - PositioningAxis TO measuring probe

The 'LHSCTO_HSCEncoder' function block's 'hwID_HSC' input is assigned to the configured high-speed counter's system constant, as illustrated in Figure 4.10. That particular tel83-based data block ends up getting assigned to the 'tel83' InOut.

Figure 4.10: Encoder setup guide to S7-1200 G2 HSC - HSC assignment to PositioningAxis TO
Figure 4.10: Encoder setup guide to S7-1200 G2 HSC - HSC assignment to PositioningAxis TO

Operation

The watch table gives you a way to operate this example directly. Follow these steps to test the application example with an encoder set as the leading value. Homing or measuring input should be requested when it's needed.

Figure 5.1: Encoder setup guide to S7-1200 G2 HSC - Leading encoder watch table
Figure 5.1: Encoder setup guide to S7-1200 G2 HSC - Leading encoder watch table

To try this application example using an additional encoder for the position feedback, follow these steps. Make sure the 'PositioningAxis' Technology Object is enabled. Change the sensor selection to the external encoder. Homing or measuring input should be requested when it's needed.

Figure 5.2: Encoder setup guide to S7-1200 G2 HSC - Additional encoder watch table (positioning axis)
Figure 5.2: Encoder setup guide to S7-1200 G2 HSC - Additional encoder watch table (positioning axis)

As an additional feature, the 'LHSCTO_SIMEncoderPulsesPTO' function block provides a simple example illustrating how an external encoder, through PTO (Pulse Train Output), can be simulated with A/B phase-shifted pulses.

Figure 5.3: Encoder setup guide to S7-1200 G2 HSC - LHSCTO_SIMEncoderPulsesPTO function block
Figure 5.3: Encoder setup guide to S7-1200 G2 HSC - LHSCTO_SIMEncoderPulsesPTO function block

The S7-1200 G2's hardware configuration setup is a prerequisite for doing this step. Figure 5.4 shows how PTO1 is configured for this application example. PTO2's hardware configuration can be set up the same way. Here, the external encoder is simulated via A/B phase-shifted pulses.

Figure 5.4: Encoder setup guide to S7-1200 G2 HSC - PTO1 hardware configuration (ExternalEncoder TO)
Figure 5.4: Encoder setup guide to S7-1200 G2 HSC - PTO1 hardware configuration (ExternalEncoder TO)

For the configuration that pairs two Technology Objects called 'ExternalEncoder' and 'MeasuringInput' together, the wiring is shown in Figure 5.5.

Figure 5.5: Encoder setup guide to S7-1200 G2 HSC - Hardware simulation (ExtEnc ⇄  MeasInput)
Figure 5.5: Encoder setup guide to S7-1200 G2 HSC - Hardware simulation (ExtEnc ⇄  MeasInput)

For the configuration involving the 'PositioningAxis' Technology Object, the wiring is shown in Figure 5.6.

Figure 5.6: Encoder setup guide to S7-1200 G2 HSC - Hardware simulation (PosAxis ⇄  MeasInput)
Figure 5.6: Encoder setup guide to S7-1200 G2 HSC - Hardware simulation (PosAxis ⇄  MeasInput)

If you want to test the application example using PTO1 simulation for the 'ExternalEncoder' Technology Object configuration, here's what to do. Configure the simulated velocity accordingly. Make sure the simulated encoder pulses are enabled. Carry out the operation the way Figure 5.1 explains.

Figure 5.7: Encoder setup guide to S7-1200 G2 HSC - Simulation configuration watch table (ExternalEncoder TO)
Figure 5.7: Encoder setup guide to S7-1200 G2 HSC - Simulation configuration watch table (ExternalEncoder TO)

If you want to test the application example using PTO2 simulation for the 'PositioningAxis' Technology Object configuration, here's what to do. Ensure the simulated encoder pulses are enabled. Carry out the operation the way Figure 5.2 explains.

Figure 5.8: Encoder setup guide to S7-1200 G2 HSC - Simulation configuration watch table (PositionAxis TO)
Figure 5.8: Encoder setup guide to S7-1200 G2 HSC - Simulation configuration watch table (PositionAxis TO)

Conclusion

In conclusion, you have learned how to bridge the S7-1200 G2's onboard HSC to Technology Objects using the LHSCTO library, wiring an encoder and measuring probe, configuring HSC1 and its capture input, and properly setting input filters to avoid missed signal edges. You've also configured ExternalEncoder and MeasuringInput Technology Objects through telegram 83, calculated fine resolution for a quadrature-counted encoder, and set up PositioningAxis homing via digital input or zero mark. Finally, you tested everything using the watch table and saw how PTO-based pulse simulation lets you verify the whole setup without any physical encoder on hand.