PLC DC motor speed control — complete worked companion lesson
Implement a documented start/stop sequence, encoder scaling and a discrete PI speed loop with actuator limits. This is an authored companion lab; no unverified YouTube video is attached.
Learning Objectives
- Specify the PLC I/O and run-state logic.
- Convert encoder counts into rpm and a speed reference into a bounded drive command.
- Implement and explain discrete PI control with conditional integration.
- Test stop priority, communication loss, saturation recovery and restart prevention.
Purpose and system boundary
Build a teaching speed-control loop: HMI reference → PLC PI controller → rated motor drive → DC motor → encoder → PLC. The PLC sends a command; the drive switches motor power. This companion lesson is independent of any unverified video-specific hardware configuration.
Use a secured, low-energy motor rig and a current-limited supply. An emergency stop must act through the appropriate independent hardwired protective circuit or rated drive safety function; ordinary PLC application logic and a web/HMI button do not establish a safety-rated stop.
I/O and state design
| Signal | Meaning | Initial/fault behavior |
|---|---|---|
| StartRequest | Momentary operator start | Does not auto-restart after power recovery |
| StopOK | Permissive stop chain feedback | False removes run request |
| DriveReady / DriveFault | Drive status | Fault latches a diagnostic |
| EncoderCount | Signed, decoded output-shaft count | Missing/implausible data inhibits control |
| SpeedSet_rpm | Bounded HMI reference | Clamped to validated rig limit |
| DriveEnable / SpeedCommand | Separate enable and demand | Disabled and zero demand |
Stop and fault dominate Start. Reset clears the fault only after its cause is removed; it does not start the motor. Define a separate deliberate Start action.
Encoder speed and command scaling
Nrev is effective decoded counts per output-shaft revolution, including quadrature mode and gearing; Ts is seconds. Handle count rollover and timestamp jitter. A nominal PLC scan period is not a substitute for measured elapsed time.
The raw command endpoints must come from the actual drive/interface manual. They are not universal PLC constants. A 0–10 V output might encode a 0–100% demand, but speed still depends on the drive mode and feedback implementation.
Discrete PI with conditional anti-windup
Accept I* only when the output is unsaturated, or when the error would drive a saturated output back toward its valid range. Otherwise retain the previous integral. When Run is false, apply zero command and reset the integrator for this teaching design.
// Illustrative Structured Text; adapt types and I/O to the PLC.
IF NOT Run THEN
Integral := 0.0;
SpeedDemand := 0.0;
ELSE
Error := SetpointRpm - MeasuredRpm;
CandidateI := Integral + Ki * SampleSeconds * Error;
CandidateU := Kp * Error + CandidateI;
IF ((CandidateU >= 0.0) AND (CandidateU <= 1.0))
OR ((CandidateU > 1.0) AND (Error < 0.0))
OR ((CandidateU < 0.0) AND (Error > 0.0)) THEN
Integral := CandidateI;
END_IF;
SpeedDemand := LIMIT(0.0, Kp * Error + Integral, 1.0);
END_IF;This is a conceptual unidirectional loop, not a complete machine program. Add input validity checks, drive handshake, current/temperature limits and a measured sample time appropriate to the actual rig.
Numerical example
Assume 2,048 effective counts/revolution and 512 counts measured in 0.25 s: measured speed = 60 rpm. With reference 80 rpm, Kp = 0.01 duty/rpm, Ki = 0.02 duty/(rpm·s), Ts = 0.02 s and previous integral 0.10, the proposed integral is 0.108 and output is 0.308, or 30.8% demand. The 0.25 s speed-estimation window and 20 ms controller period are different; analyze the measurement delay before tuning aggressively.
If demand is constrained to 0–100% and the motor cannot reach the reference under load, continuing to integrate positive error creates windup. Confirm saturation handling by lowering the reference after a deliberately limited run.
Commissioning sequence
- Document wiring, drive mode, protective circuit, current limit and validated maximum speed.
- With power disabled, test truth-table transitions and restart prevention in simulation.
- Verify encoder count direction and counts/revolution at low energy.
- Test the open-loop drive demand, then start with low proportional gain and zero integral gain.
- Log reference, measured rpm, error, requested/applied duty, integral and sample timestamps.
- Add integral action gradually and test load steps, stop priority, stale feedback and saturation recovery.
Evidence: I/O table, state transition trace, a time plot for reference/speed/demand, and a failure-test table including observed stop time. Acceptance thresholds must be defined for the actual apparatus before testing.
Exercise with solution
A 1,000-count/revolution encoder produces 100 counts in 0.1 s. Reference is 90 rpm. Kp = 0.005 duty/rpm, Ki = 0.01 duty/(rpm·s), Ts = 0.02 s and previous integral = 0.20. Calculate the next unsaturated PI output.
Show calculation
Measured speed = 60 rpm; error = 30 rpm. Integral candidate = 0.20 + 0.01×0.02×30 = 0.206. Output = 0.005×30 + 0.206 = 0.356, or 35.6%. It is inside the assumed 0–1 range, so accept the integral update.
Summary
PLC scan, latching and interlocks: keep units, assumptions and timing explicit. Check the numerical model against an independent observation before using it in a larger system.