S7-1200 Carousel Control: 24-Position Recipe-Based Indexing

David Krause19 min read
S7-1200SiemensTutorial / How-to
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

Overview

A 24-position carousel is a rotary indexing mechanism that carries 24 discrete loads past a single load station and then past one or more unload stations. The reference application is a drying chamber in which 24 plates are loaded at one station, indexed around a central axis through a heated environment, and finally released at one of three downstream unload stations or rejected as defective. The choice of unload station is set by a recipe code (1, 2, 3, or 4) written to that plate's slot when the plate is loaded. Code 4 marks a defective plate and is sent to the reject chute; codes 1, 2, and 3 each map to a configurable unload position along the carousel.

This document gives a complete, field-ready implementation on a SIMATIC S7-1200 CPU programmed with TIA Portal V17 or V18. The same logic ports to the S7-1500 family with no functional change. Sample code is supplied in both Ladder (LAD) and Structured Control Language (SCL) so it can be maintained by electricians who draw every change on paper or by programmers who prefer IEC 61131-3 text languages.

The control scope covers:

  • Incremental encoder position tracking with a high-speed counter (HSC1) on the S7-1200
  • Home referencing against a 24 VDC proximity switch wired to a CPU fast input
  • A 24-cell recipe data block (one integer per position) loaded from the HMI
  • A station-decision matrix that maps recipe code to target unload station
  • Variable-frequency drive (SINAMICS V20) control of the index motion
  • HMI screens for recipe entry, current-position display, and fault diagnostics
  • Defect handling (recipe code = 4) with a separate counter

The mechanical scope is intentionally kept off the PLC. The PLC must, however, be told when the table is mechanically locked in position, when motion is permitted, and when each unload position has been reached.

Prerequisites

Verify the following hardware, software, and mechanical items are in place before commissioning.

Hardware

  • SIMATIC S7-1200 CPU. The minimum part is the CPU 1214C DC/DC/DC (6ES7214-1AG40-0XB0) with firmware V4.5 or higher. The CPU 1215C (6ES7215-1AG40-0XB0) is recommended if analog signals (motor temperature, current) are also monitored.
  • If the onboard 14 DI / 10 DO of the CPU 1214C is not sufficient, add an SM 1223 DI16/DQ16 (6ES7223-1PL32-0XB0) for digital I/O expansion. Up to eight SMs can be stacked on a single CPU per the S7-1200 System Manual.
  • Incremental encoder, 1024 pulses per revolution, 24 VDC push-pull or HTL, mounted on the carousel shaft. The encoder should have a 0-channel (index pulse) for the home reference. Choose a PPR that is an integer multiple of 24 (240 PPR or 600 PPR) to avoid fractional counts per station.
  • One 24 VDC PNP proximity switch mounted at the home (0 deg) position, wired to one of the CPU fast inputs (I0.0 to I0.5 on the CPU 1214C/1215C). HSC1 through HSC6 can use these inputs.
  • 24 VDC power supply rated for at least 5 A. Use a SITOP PSU100S (6EP1334-3BA10) or equivalent, properly grounded to the same protective earth as the CPU.
  • Variable frequency drive sized for the carousel. A SINAMICS V20 (6SL3210-5BE27-5UV0) covers most low-inertia carousel applications up to 3 kW.
  • Three inductive proximity switches (one per unload station) plus a fourth for the defect bin. These are wired as digital inputs and do not need to be HSC inputs.

Software

  • TIA Portal V17 or V18, with the corresponding HSP installed for the chosen CPU. TIA Portal V18 is the recommended baseline for new projects.
  • WinCC Comfort/Advanced or a basic HMI panel such as the KTP1200 Basic (6AV2123-2MB03-0AX0) for recipe entry and visualization.

Mechanical

  • Carousel must be indexable (move and stop precisely at 24 positions, 15 deg between stations).
  • Mechanical detent or brake must hold position when the drive is off.
  • Encoder coupling without backlash greater than +/- 1 pulse.
Safety: This document covers functional control only. A risk assessment per ISO 12100 and EN ISO 13849-1 is required before commissioning. Add a category 3 or 4 emergency stop, guard interlock, and safe stop of the drive before any live test. The S7-1200 F-CPU variants (for example CPU 1214FC) are recommended for guarding circuits and may be required by the application standard.

System Architecture and I/O Assignment

The S7-1200 sits in the centre of a three-tier architecture: sensor inputs at the bottom, the CPU in the middle, and the drive plus HMI above. The table below gives a complete I/O map that can be pasted into the PLC tag table.

Tag Address Type Function
ENC_A %I0.0 Bool Encoder phase A (HSC1 input)
ENC_B %I0.1 Bool Encoder phase B (HSC1 input)
ENC_Z %I0.2 Bool Encoder index pulse (home reference)
HOME_PROX %I0.3 Bool Home proximity switch (redundant with encoder Z)
START_BTN %I0.4 Bool Operator start pushbutton, NO contact
STOP_BTN %I0.5 Bool Operator stop pushbutton, NC contact
STN1_PROX %I0.6 Bool Unload station 1 detected
STN2_PROX %I0.7 Bool Unload station 2 detected
STN3_PROX %I1.0 Bool Unload station 3 detected
DEFECT_PROX %I1.1 Bool Defect reject position detected
DRIVE_RDY %I1.2 Bool VFD ready feedback
ESTOP_OK %I1.3 Bool Estop chain closed, safety relay healthy
DRIVE_ENABLE %Q0.0 Bool Run permit to VFD
DRIVE_FWD %Q0.1 Bool Direction = forward (one direction only for carousels)
DRIVE_FAST %Q0.2 Bool Fast jog speed select
BRAKE_RELEASE %Q0.3 Bool Hold brake release contactor
STN1_DUMP %Q0.4 Bool Unload station 1 dump actuator
STN2_DUMP %Q0.5 Bool Unload station 2 dump actuator
STN3_DUMP %Q0.6 Bool Unload station 3 dump actuator
DEFECT_DUMP %Q0.7 Bool Defect reject actuator
GREEN_LAMP %Q1.0 Bool Run indication
RED_LAMP %Q1.1 Bool Fault indication
YELLOW_LAMP %Q1.2 Bool Home / ready indication

The encoder is wired directly to the CPU's HSC1 fast inputs (I0.0, I0.1, I0.2). The remaining digital I/O is brought in through the onboard terminals of the CPU 1214C; if more outputs are needed, add an SM 1223 DQ16 and renumber the outputs to start at %Q2.0.

Position Tracking and Homing

Carousel position is tracked by HSC1 counting encoder pulses. The mechanical model assumes an encoder on the shaft configured as follows. Open the device configuration in TIA Portal, select the CPU, expand Digital inputs, and configure channel 0 (HSC1) as:

  • Operating mode: Count continuously
  • Count direction: Bidirectional count, phase A leading
  • Initial counter value: 0
  • Initial reference value: 0
  • Compare value for interrupt: not used (handled in OB1)

The CTRL_HSC and CTRL_HSC_EXT instructions can also be used to drive the HSC from code; both methods are documented in the SIMATIC S7-1200 System Manual (entry ID 109772940) under High-speed counter.

The current count is read into the program using the ID1000 input area for HSC1, or via the symbolic name assigned in the device configuration. For this reference the count is mapped to a global tag HSC1_Count of type DInt. A cycle-accurate position word is derived as:

// With 600 PPR encoder, quadrature x4 = 2400 counts/rev
// 100 counts per station (15 deg)
'Position'     := HSC1_Count MOD 2400;     // 0..2399 wraps within one rev
'StationNo'    := Position / 100;          // 0..23
'StationNo'    := LIMIT(0, StationNo, 23);
'PulsesPerRev' := 2400;
'PulsesPerStation' := 100;

For a 1024 PPR encoder (4096 edges/rev) the division gives 170.67 counts per station, which produces rounding noise at the station boundary. Pick an encoder whose PPR divides evenly by 24.

Home Referencing Sequence

On power-up the PLC must know the absolute station. The home sequence runs once at startup and whenever the operator triggers Rehome from the HMI.

  1. Disable the drive enable output.
  2. Jog the carousel slowly in the forward direction.
  3. Watch the home proximity switch HOME_PROX.
  4. When HOME_PROX transitions from 0 to 1, switch to creep speed (5 to 10 % of full speed) so the encoder index pulse is captured cleanly.
  5. On the next encoder index pulse (Z-channel rising edge), load the HSC count to a known reference value (typically 0). This is done with the CTRL_HSC instruction by writing to the load input of the HSC hardware configuration.
  6. Reverse the carousel by 0.5 stations to back off the home flag.
  7. Drive forward at creep speed until the home flag reappears, then stop. The HSC is now at a known reference value and StationNo = 0. Set the bHomed flag TRUE.

Wrap this sequence in a small FB (Homing) so it can be called from the main OB1 whenever the position is unknown (bHomed is FALSE).

Recipe Data Structure

The recipe for one carousel revolution is a 24-element array. Each element is the recipe code (1, 2, 3, or 4) for the corresponding station. The DB is defined as follows in TIA Portal:

DATA_BLOCK 'DB_Carousel'
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
  STRUCT
    Recipe        : ARRAY[1..24] OF INT;   // 1..3 = unload station, 4 = defect
    RecipeLoaded  : BOOL;                  // TRUE when HMI has filled the array
    PlatePresent  : ARRAY[1..24] OF BOOL;  // TRUE if a plate is on the station
    CycleCount    : DINT;                  // total revolutions
    PlatesProcessed : DINT;                // plates unloaded successfully
    PlatesRejected  : DINT;                // plates sent to defect bin
  END_STRUCT;
END_DATA_BLOCK

Set Retain to TRUE on the Recipe, PlatePresent, CycleCount, PlatesProcessed, and PlatesRejected tags so the data survives a power cycle. The HMI writes to DB_Carousel.Recipe[1..24] via a recipe view. A typical HMI screen is shown later.

If more than one recipe must be stored (the usual case), extend the DB with a 2-D array Recipes[1..10, 1..24] OF INT and a current-recipe number tag. Ten recipes by 24 stations by 2 bytes equals 480 bytes, well within the work memory of any S7-1200.

Position-Based Decision Logic

Each time the carousel arrives at an unload station, the PLC must decide what to do with the plate. The decision is based on two things:

  1. The recipe value stored for the station that is currently aligned with the unload station.
  2. The physical unload station the plate has reached (detected by the three station proximity switches).

In a 4-station layout (1 load, 3 unload, 1 defect reject) the unload position is at a fixed station number, but the recipe dictates which physical dump actuator to fire. A compact SCL implementation is shown below.

// In OB1 or a cyclic interrupt OB (e.g. OB30, 100 ms cycle)
// HSC handles the timing precision

'bAtStation' := (ABS('Position' - 'iLastStationPos') >= 'iPulsesPerStation' - 2)
                AND (ABS('Position' - 'iLastStationPos') <= 'iPulsesPerStation' + 2);

IF 'bAtStation' AND 'PlatePresent'['StationNo'] THEN
    // Read the recipe for this station
    iRecipe := 'DB_Carousel'.Recipe['StationNo'];

    CASE iRecipe OF
        1:  'STN1_DUMP'   := TRUE;   // Fire station 1 actuator
        2:  'STN2_DUMP'   := TRUE;   // Fire station 2 actuator
        3:  'STN3_DUMP'   := TRUE;   // Fire station 3 actuator
        4:  'DEFECT_DUMP' := TRUE;   // Fire reject actuator
        ELSE ;                       // 0 or out-of-range: leave plate on the carousel
    END_CASE;

    // After the actuator is fired and a confirmation has been received
    // (proximity switch on the dump station), clear the plate
    IF 'iConfirmTimer' > 30 THEN     // 3 s at 100 ms
        CASE iRecipe OF
            1:  'STN1_DUMP'   := FALSE;
            2:  'STN2_DUMP'   := FALSE;
            3:  'STN3_DUMP'   := FALSE;
            4:  'DEFECT_DUMP' := FALSE;
        END_CASE;
        'PlatePresent'['StationNo'] := FALSE;
        IF iRecipe = 4 THEN
            'DB_Carousel'.PlatesRejected := 'DB_Carousel'.PlatesRejected + 1;
        ELSE
            'DB_Carousel'.PlatesProcessed := 'DB_Carousel'.PlatesProcessed + 1;
        END_IF;
        'iLastStationPos' := 'Position';
        'iConfirmTimer'   := 0;
    END_IF;
END_IF;

The exact dump delay depends on the mechanical stroke of the actuator. Set iConfirmTimer to 2 to 5 s and adjust in commissioning. The CASE statement with an ELSE branch makes the program robust to HMI errors that might write 0 or 5 to the array.

Sample Ladder Program

For maintenance teams that work in LAD, the same logic can be expressed in ladder. The segments below handle drive enable, brake release, and homing.

Segment 1: Drive enable
|---[ ]---[ ]---[ ]---( )---|
| Start  Home  Estop  Drive_Enable |

Segment 2: Hold brake release
|---[ ]---( / )---|
| Drive_En  Brake_Release |

Segment 3: Homing request latch
|---[ ]---( S )---|
| Rehome_Btn  HomingActive |

Segment 4: Homing complete
|---[ ]---( )---|
| Home_OK  bHomed |

The rest of the ladder replicates the SCL CASE structure using compare coils. Compare the recipe value to a constant and latch the corresponding dump output. Keep the logic in a single FB (Function Block) instance FB_Carousel with instance DB IDB_Carousel so it can be reused if a second carousel is added later.

HMI Recipe Entry

A 6AV2-1 KTP1200 Basic panel is sufficient. Configure a recipe view bound to the DB_Carousel.Recipe array. Each row shows the station number (1 to 24) and an input/output field for the recipe code (1 to 4). Add the following control buttons on the same screen:

  • Load Recipe from PLC
  • Save Recipe to PLC
  • Delete Recipe (zeros all values)
  • Rehome
  • Reset Counters

Configure the HMI input field as a dropdown so operators cannot type 0 or 5. A second screen shows the current station (0 to 23), the recipe value, the number of plates processed, and the number of rejected plates. Add a third screen for diagnostics: drive ready, estop state, bHomed, last fault code, and a list of stations where PlatePresent is TRUE.

Commissioning

Commission in the following order. Do not proceed to the next step until the previous step is fully green.

  1. Wire check. Power down, verify all grounds, then power up. Confirm the CPU goes to RUN and the HMI starts without diagnostics.
  2. I/O check. From the watch table, force each input to 0/1 and verify the corresponding tag. Repeat for the outputs with the drive enable still de-energized.
  3. Encoder check. Manually rotate the carousel one full turn. Verify that the HSC count moves from 0 to 2399 (600 PPR) or 4095 (1024 PPR) and that StationNo cycles 0..23 exactly once.
  4. Homing check. Trigger Rehome from the HMI. Watch the sequence in online mode and verify the carousel stops on the index pulse within +/- 1 pulse.
  5. Drive check. Enable the drive at low speed. Confirm the carousel rotates in the correct direction. Reverse the encoder wiring or change the count direction in the HSC if not.
  6. Dry run with no plates. Force PlatePresent[1..24] to FALSE, load a recipe, and run a full revolution. Verify that the dump actuators do not fire.
  7. Dry run with one plate. Force PlatePresent[1] to TRUE and set Recipe[1] to 1. Start the carousel. The plate should be released at station 1.
  8. Full recipe test. Load a 24-element recipe covering codes 1, 2, 3, and 4, and load 24 plates. Run for one full revolution. All plates should be released at the correct station and the rejected count should equal the number of 4-coded entries.
  9. Fault injection. Block a proximity switch with your hand and verify that the fault lamp lights and the drive stops.
  10. Production sign-off. Document the tested recipes, the cycle time, and the fault-free run time. Save the TIA Portal project to the project archive.

Fault Handling and Troubleshooting Matrix

The fault latch bFault is set by any of the conditions in the table below. The operator must clear it from the HMI after the cause is removed.

Fault Detection Action
Not homed at startup bHomed = FALSE and Start pressed Refuse start, prompt rehome
Encoder Z pulse missed Home sequence runs more than 60 s Latch fault, check encoder wiring
Plate present without recipe PlatePresent[i] = TRUE and Recipe[i] = 0 Refuse to start, log warning
Drive not ready DRIVE_RDY = FALSE while Drive_Enable = TRUE Stop motion, latch fault, light red lamp
Estop pressed ESTOP_OK = FALSE Drop drive enable, light red lamp
Station dwell timeout Position not within +/- 2 pulses of expected after 2 s Drop drive enable, latch fault
Recipe value out of range Recipe[i] < 1 or > 4 Refuse to start, log warning
Counter overflow CycleCount exceeds preset Trigger maintenance reminder

For Siemens-specific diagnostic events, use the GET_DIAG instruction to pull the diagnostic status of the CPU and the SMs. The buffer is in the diagnostic interrupt OB (OB82). See the S7-1200 System Manual section on Diagnostics for the full list of error codes and SFC/SFB usage.

Symptom Likely Cause First Check Fix
Carousel does not move when Start is pressed Drive enable not asserted Watch table: bHomed, Estop_OK, Drive_Rdy Clear the blocking condition and try again
Position drift after several revolutions Encoder slipping on shaft Watch HSC count, check coupling Re-couple encoder, increase spring pressure
Wrong station receives the plate Encoder counts off by one tooth Read StationNo online, mark a station with tape Adjust initial reference value or change encoder PPR
Recipe value lost on power cycle Recipe written to volatile area Inspect DB attributes Set Retain = TRUE on the Recipe tag
Recipe not updating from HMI HMI recipe view not bound to the right DB Inspect HMI tags in TIA Portal Reconnect the HMI tag to DB_Carousel.Recipe
HSC count does not move Encoder wired to wrong terminal Check wiring against I0.0, I0.1, I0.2 Move encoder wiring to the fast inputs
Drive runs in the wrong direction Encoder A/B swapped Verify sequence with oscilloscope Swap A and B or change the HSC count direction
Fault lamp on at power-up Recipe not yet loaded Read Recipe[1] online Load a valid recipe from the HMI
Estop cannot be reset Safety relay in fault Check safety relay diagnostics Cycle power to safety relay per vendor manual
HMI shows 'Connection lost' IP address mismatch Ping the PLC from a laptop Reconfigure IP in the device configuration

Cycle-Time Optimisation

The carousel cycle time is the time to move from one station to the next plus the dwell time at the unload station. For a 1.5 m diameter table with 24 stations, the linear distance between stations is pi times 1.5 m divided by 24 equals approximately 196 mm. With a maximum tangential speed of 0.5 m/s the move time is 196 / 500 = 0.39 s. Add a 200 ms acceleration ramp and a 1 s dwell at the unload station and the total cycle is 1.6 s per station, or 38.4 s per revolution.

To reduce the cycle time, increase the drive speed, shorten the actuator stroke, or add a continuous-motion mode where the carousel does not stop between stations. Continuous motion requires a flying unload mechanism (mechanical latch that releases the plate as the station passes the unload position) and is not in scope here.

Apparent-power sizing for the drive uses the standard three-phase formula. If the carousel motor draws 6 A at 400 V line-to-line, kVA = sqrt(3) times 400 times 6 / 1000 = 4.16 kVA. If the source is single-phase 230 V, kVA = 230 times 6 / 1000 = 1.38 kVA. The SINAMICS V20 selection must be checked against the actual measured current in the application.

Migration to S7-1500

If the project is later moved to an S7-1500 (for example CPU 1512C-1 PN, 6ES7512-1DK02-0AB0), the same logic applies. The HSC configuration moves from the device configuration to the axis configuration under Technology objects to Counting and measuring. The SCL code in the recipe block is unchanged. Watch for two differences:

  • The S7-1500 has optimised access only; the optimisation cannot be disabled as on the S7-1200. Use symbolic addressing everywhere.
  • DBs with Retain set on the S7-1500 write to the non-volatile load memory, not to the work memory. This is faster and more reliable but uses more load memory.

For drives with PROFINET IRT, the S7-1500 can offload the position loop entirely to a SINAMICS S120 or V90 with the TO_Positioning technology object. The S7-1200, by contrast, must close the position loop in the HSC firmware of the CPU.

Standards and Acceptance

Verify against the standards below for the application; the values in this document are guidelines, not certifications.

  • ISO 12100 - General principles for design - Risk assessment and risk reduction
  • EN ISO 13849-1 - Safety of machinery - Safety-related parts of control systems (PL a to PL e)
  • IEC 61131-3 - Programmable controllers - Programming languages (LAD, FBD, SCL, ST, IL, GRAFCET)
  • IEC 60204-1 - Safety of machinery - Electrical equipment of machines
The duty cycle of the dump actuator must be verified against the cycle time of the carousel. If the actuator is rated for 30 cycles/minute and the carousel produces one dump every 1.6 s (37.5 per minute), the actuator will overheat. Select a higher-duty-cycle actuator or add a delay between cycles.

Acceptance Test Sheet

Use the following checklist at the end of commissioning. The operator signs each line, and the sheet is filed with the project documentation.

  • Drive enable latches and drops on Estop: __________ (initial)
  • Homing completes within 60 s: __________ (initial)
  • One full revolution with all 24 plates loads and unloads correctly: __________ (initial)
  • Recipe code 4 sends plates to the defect bin: __________ (initial)
  • Counter values survive a power cycle: __________ (initial)
  • Fault lamp latches on simulated encoder loss: __________ (initial)
  • HMI recipe view loads and saves recipes: __________ (initial)
  • Cycle time measured at 38.4 +/- 2 s: __________ (initial)

All of the sample code, the data block definitions, and the I/O map in this document are vendor-neutral S7-1200 constructs. They can be pasted directly into a TIA Portal V18 project, downloaded to a CPU 1214C with firmware V4.5, and run as a starting point for a real carousel machine. Adjust the drive parameters, the dump-actuator timing, and the safety category to match the actual mechanical installation before production sign-off.

FAQ

How do I track 24 positions on the S7-1200 without an encoder?

Mount a 24-tooth cam ring on the shaft and use a single 24 VDC PNP proximity switch wired to a fast input. Configure HSC2 in single-count mode, with the load value reset to 0 on a second proximity switch at the home position. The HSC count modulo 24 gives the current station number 0..23.

What encoder PPR works cleanly with 24 stations?

Choose a PPR that is an integer multiple of 24. Common picks are 240 PPR (10 counts per station in quadrature) and 600 PPR (100 counts per station). Avoid non-integer divisions like 1024 PPR (170.67 counts per station) because the modulo math becomes fuzzy at the station boundary.

Can I store more than one recipe in the PLC?

Yes. Extend the DB to a 2-D array, for example Recipes[1..10, 1..24] OF INT, and add a current-recipe index tag. The HMI recipe view can manage up to 100 recipes without further code changes, and recipe transfer is handled by the standard recipe view data record mechanism.

How do I make the recipe survive a power cycle?

In TIA Portal, open the DB, select the Recipe tag, and set Retain to TRUE. The data is stored in the non-volatile load memory. Note that the S7-1200 load memory is limited to 4 MB on the CPU 1214C, so keep the recipe set lean.

Why does the carousel overshoot the station by one position?

Usually the encoder counts per station is not an integer, or the brake is too slow. Either pick an encoder with PPR equal to N times 24, increase the brake voltage, or add a 'creep plus final position' profile in the drive: high speed for 80 percent of the move, low speed for the last 20 percent, then a 200 ms brake set time before the dump actuator fires.

Back to blog