AutomateDirectUSAMotion LibraryIndustrial monitors & PCs

Explainer

Why a PLC driving an H-bridge needs a phase sequence table

Servo and stepper motion Published 8 min read By AutomateDirectUSA engineering team

Short answer

The L298 only switches winding current; it has no translator, so the PLC must produce the four full-step or eight half-step states itself. The design lives or dies on a written next-state table that reads CLK, DIR and MODE and advances exactly one state per clock edge, held in persistent memory and owned by one routine.

On this page
  1. The bridge switches, the PLC sequences
  2. Name the windings before the states
  3. The eight-state phase table
  4. One state per clock edge
  5. Where the clock comes from
  6. Working the ramp from a 200 ms cycle to a 2 ms cycle
  7. Symptoms that point back at the table
  8. Commissioning order
  9. Questions asked

The L298 will not step the motor for you. It is a dual full-bridge power stage: it accepts TTL logic levels, applies one polarity or the other across each of two windings, and nothing more. Which winding is energized, in which direction and in what order has to come from whatever drives its inputs — here, the PLC. A step-and-direction drive hides a translator between its pulse input and the bridge; a bare bridge has none, so the PLC is the translator. The whole project stands on one sheet: a next-state table that reads CLK, DIR and MODE and, on every clock edge, moves from the present phase state to exactly one legal successor.

The bridge switches, the PLC sequences #

The L298 datasheet describes a dual full-bridge driver that accepts standard TTL logic levels and drives inductive loads. There is no counter, no direction latch and no phase table inside the chip. Each bridge has two logic inputs that set the polarity across its winding — the pair 1 0 drives it one way, 0 1 the other — plus an enable that gates it. That is the entire intelligence on the silicon.

That is the difference from a step-and-direction servo drive compared with an open-loop stepper: those drives contain the translator, so one pulse in becomes one step out. With a bare bridge, the pulse-to-state conversion is your program.

Check the electrical interface before the logic: the PLC output type must satisfy the bridge's input thresholds with a shared signal reference. Relay outputs cannot carry stepping frequencies, and a transistor output still needs compatible levels.

Name the windings before the states #

With the motor disconnected, find the pairs with a continuity meter: low resistance within a winding, none between windings. A bipolar motor has exactly two.

  • Give bridge 1 winding 1 and bridge 2 winding 2. Call the logic inputs A and B for the first bridge and C and D for the second — working names for the sequence, not PLC output addresses; map them to physical outputs last.
  • Fix a polarity convention: 1 0 on a pair means positive, 0 1 negative. Swapping the two wires of one winding flips that winding's polarity.
  • Record what the sequence cannot do: it does not limit winding current. Current follows from the supply voltage, the winding resistance and any chopping or series resistance, and it must stay inside both the motor's and the bridge's ratings.

The eight-state phase table #

Half stepping alternates a two-winding state with a one-winding state, which doubles the angular resolution; the one-winding states hold less torque. Full step uses only the four two-winding rows, half step runs all eight rows in order. A and B drive winding 1, C and D drive winding 2.

State A B C D Excitation Used in
1 1 0 1 0 W1 +, W2 + Full and half
2 1 0 0 0 W1 +, W2 off Half
3 1 0 0 1 W1 +, W2 - Full and half
4 0 0 0 1 W1 off, W2 - Half
5 0 1 0 1 W1 -, W2 - Full and half
6 0 1 0 0 W1 -, W2 off Half
7 0 1 1 0 W1 -, W2 + Full and half
8 0 0 1 0 W1 off, W2 + Half

Run the rows in reverse order for the opposite DIR command; which physical rotation you get depends on the wiring and on which end of the shaft you watch.

Handle the enables in the one-winding rows: disable the idle bridge. A bridge left enabled with both inputs at 0 0 does not release its winding — it shorts the winding through the bridge and brakes it, and the decay of the winding current then depends on the enable and the recirculation path.

The same row order, generated from microcontroller pins rather than PLC outputs, is written out in stepper full-step and half-step sequencing with a TM4C123.

One state per clock edge #

The controller is a state machine: a memory word holds the current state, and on each rising edge of CLK the program reads DIR and MODE, selects the successor from the table, stores it, then decodes it to A, B, C, D and the two enables. Without a new edge, nothing changes.

Edge, not level. If the advance runs on every scan while CLK is high, one pulse wider than a scan advances several states at once. If the scan is slower than the pulse, edges vanish between scans. The first is a level-triggering error, the second a scan-rate error, and both are cured by detecting edges in logic that runs fast enough — where that logic lives is the next section.

Ownership. The state word sits in memory that survives between calls; a subroutine called every scan must not reinitialize it, or the motor snaps back to state 1 each time. One routine owns both the transition and the decode — a second rung writing a single bridge input will fight it.

MODE at standstill, for the first version. A one-winding half-step position is not one of the four full-step positions, so an on-the-fly mode change needs a defined route to the nearest two-winding state first.

Where the clock comes from #

A timer in the main program is the honest first clock at a deliberately slow rate of a few steps per second, but its spacing depends on scan time, timer resolution and the moment the outputs update. At the 1 kHz this project currently runs, a fresh state must land every 1 ms, and no main-program scan should be trusted with that.

A working rule of thumb: the logic that detects the clock edge and advances the state should execute at least ten times per step interval. Where that stops holding, move the advance into a timed interrupt, or take the clock from the hardware pulse output — it generates edges independently of scan timing, but it will not update four phase outputs by itself, so the timing event still has to reach the sequence generator. How ordinary outputs behave when they carry step pulses is measured in stepper pulse timing from a PLC discrete output module.

One documented constraint shapes any ramp: the S7-200 system manual states that a PWM cycle-time change takes effect asynchronously and briefly interrupts the pulse train. A ramp that rewrites the period once per second therefore shows one short hiccup per second — acceptable in a demonstration, and visible as a tick in torque.

If timed sequences in ladder are new territory, a siren pulse count sequence in S7-1200 ladder logic shows the same skeleton — timer, state word, decoded outputs — in a simpler example.

Working the ramp from a 200 ms cycle to a 2 ms cycle #

The ramp is not decoration: a stepper motor stalls above a certain step rate, so the clock has to climb to speed and back down. The inputs are the project's own spec.

  • Slowest clock cycle: 200 ms, the ramp's start value.
  • Fastest clock cycle: 2 ms, the ramp's end value.
  • Decrement: 5 ms, written once per second.
  • Hold at the fast end: 10 s, then reverse.
  • One clock edge advances one table state; an electrical cycle is 4 states in full step, 8 in half step.

The rules in words: the step rate is the reciprocal of the clock cycle; the number of decrements is the cycle span divided by the decrement size; the ramp time is the number of decrements times the interval between them.

The arithmetic:

  • Start rate: 1 ÷ 0.200 s = 5 steps/s.
  • Fast rate: 1 ÷ 0.002 s = 500 steps/s.
  • Span: 198 ms. 198 ÷ 5 = 39.6, so the grid does not land on the end value. 39 decrements of 5 ms reach 5 ms, which is 200 steps/s; the 40th write must be 3 ms to finish on target.
  • Time per direction: 40 writes × 1 s = 40 s.
  • Whole cycle: 40 s down + 10 s hold + 40 s back up = 90 s.

On the same clock, the half-step shaft turns at half the full-step speed — 8 states per electrical cycle against 4 — so one ramp table serves both modes at two shaft speeds.

The decision: the main program owns the ramp list, DIR and MODE, and rewrites the period once per second. The state advance does not run from the main program — with the ten-to-one rule, a 2 ms step interval needs the edge logic every 0.2 ms, which is timed-interrupt or pulse-output territory. Let the interrupt advance the state for the whole profile and feed it only the period. Make the last decrement 3 ms so the ramp ends where the spec says, and keep the hold at a constant period so that stretch runs without the documented update hiccup.

Symptoms that point back at the table #

Every check reads against the table. Cheapest first:

Symptom Likely mechanism Deciding check
Shaft quivers, no rotation Winding pair crossed, or rows out of order Meter the pairs, then force each state and compare the bridge inputs with the table
Several states advance per pulse Advance triggered on level, not edge Trace CLK edges against state changes on the same capture
Step spacing shifts when other logic runs Clock timed from the scan Measure transition intervals while the rest of the program executes
Pulse train present, bridge inputs frozen No path from the timing event to the sequence Force one edge and follow it through to A, B, C, D
One winding warm, weak detents in half step Idle bridge left enabled at 0 0, braking its winding Read both enable outputs against the table

Commissioning order #

  1. Logic supply on, motor supply off. Force every row of the table and verify all four inputs and both enables at the bridge pins. Keep it that way for this pass: a wrong sequence at full current can cook a winding in seconds, because the sequence does not limit current.
  2. Clock at a few steps per second. Confirm exactly one transition per edge — forward, reverse, and across the wrap from state 8 back to state 1.
  3. Raise the clock toward the fast end while watching the inputs: no skipped, doubled or reordered states.
  4. Enable the online ramp, then MODE at standstill; trust DIR changes on the fly only after the edge logic has proven itself.

Questions asked

Do both bridge enable inputs have to come from the PLC?

Not for pure full-step motion, where both windings are always energized and the two enables can stay on. The half-step pattern needs them: a bridge left enabled with both logic inputs low shorts its winding and brakes it, which drags the rotor and heats that winding on every single-winding state. Driving both enables from the state decoder costs two outputs and makes every row of the table defined.

Can direction change while the motor is still stepping?

Yes, provided DIR is read on the clock edge rather than acted on continuously. The next edge then takes the neighboring state in the new direction, so the motor reverses its order of states with at most one state of electrical overshoot. Mode is the command to respect: a one-winding half-step position is not a full-step position, so change MODE at standstill or route through the nearest two-winding state first.

Why is torque weaker on every second half step?

The one-winding rows energize half the copper, so those steps hold less torque than the two-winding rows, and stiffness alternates through the cycle. Full step keeps both windings on and gives the smoother, stronger hold; half step buys twice the angular resolution at the price of that ripple. Pick the mode by what the mechanism needs: resolution or torque.

Does swapping one winding's motor wires change the table?

No. Reversing the two wires of one winding reverses that winding's polarity, so the unchanged table now turns the shaft the other way. Treat the swap as a direction correction rather than a logic change, then re-check which DIR command produces which rotation, because the physical result also depends on which end of the shaft you watch.

Is the pulse output's fixed 50 percent duty cycle a problem as a clock?

No. The state machine needs one rising edge per period and nothing more, so duty cycle is irrelevant to it. That is why a pulse-train output intended for step ramps still serves as a clock here even though it cannot modulate pulse width. What matters is a stable period and a clean edge, not how long the pulse stays high.

Keep reading

  • Explainer

    What a Stepper Driver Control Connector Needs From a PC

    A PC can drive a stepper driver's control inputs only when the step and direction signals meet the driver's documented input voltage and current, and the current-select inputs are grounded or pulled high to match the motor's rated current before power-up. Buffer the PC outputs whenever their levels or drive current are uncertain.

    Servo and stepper motion

  • Explainer

    Convert an open loop stepper to closed loop control

    Converting an open loop stepper to closed loop control means a rotary encoder on the motor shaft, a drive mode that uses it for commutation and position, a position-tracking-error threshold that turns lost motion into a fault, and a non-zero recovery setting that returns the axis to the commanded setpoint after the fault clears. The motor's back EMF still sets the top speed.

    Servo and stepper motion

  • How-to

    Following a Master Axis With a Stepper Traverse

    Gear the traverse stepper to measured spool rotation, not to a fixed speed ratio: commanded traverse speed is v_t = p × n_s, so pitch stays constant as the spool fills. The follower ratio comes from pitch, screw lead and drive resolution — 25 step pulses per 64 master counts in the worked example — and master acceleration must be limited so the amplified slave ramp cannot stall the open-loop stepper.

    Servo and stepper motion