PWM (Pulse Width Modulation)
Converts analog percentage to pulsed digital output with proportional duty cycle.
The PWM (Pulse Width Modulation) function block converts an analog percentage value (0-100%) into a pulsed digital output signal. The duty cycle of the output matches the input percentage: 50% input produces a signal that is ON half the time and OFF half the time within each period. PWM is used to control devices with digital outputs that need proportional control, such as heaters controlled by solid-state relays, solenoid valves, and simple motor speed control where analog outputs are not available.
Parameters
Inputs
| Name | Type | Description |
|---|---|---|
| IN | REAL | Input value 0-100% (duty cycle) |
| PERIOD | TIME | PWM cycle period |
| MIN_PULSE | TIME | Minimum on-time (prevents short pulses) |
Outputs
| Name | Type | Description |
|---|---|---|
| Q | BOOL | PWM output signal |
Structured Text Example
VAR
Heater_PWM : PWM;
PID_Output : REAL; // 0-100%
Heater_SSR : BOOL; // Solid state relay
END_VAR
Heater_PWM(
IN := PID_Output,
PERIOD := T#2s,
MIN_PULSE := T#100ms
);
Heater_SSR := Heater_PWM.Q;Free · no signup to try
Run this block in your browser
Try the instruction on a live rung before you copy it into a project — nothing to install.
Try it in your browser — no signupOpens plcsimulationsoftware.com — same team
Prefer ready-made code? Ladder Logic Pack — $29 on Gumroad
Platform-Specific Implementation
Siemens (TIA Portal)
Use PULSEGEN function block in TIA Portal for PID output to PWM conversion.
Allen-Bradley (Studio 5000)
Implement using timer logic or dedicated pulse output module.
CODESYS
OSCAT library provides PWM function block, or implement with timer logic.
Common Applications
- Heater control via SSR
- Simple motor speed control
- Valve proportional control
- LED brightness control
- Time-proportional control
Frequently Asked Questions
What is PWM (Pulse Width Modulation) in PLC programming?
Converts analog percentage to pulsed digital output with proportional duty cycle. The PWM (Pulse Width Modulation) function block converts an analog percentage value (0-100%) into a pulsed digital output signal. The duty cycle of the output matches the input percentage: 50% input produces a signal that is ON half the time and OFF half the time within each period.
What are common applications of PWM (Pulse Width Modulation)?
PWM (Pulse Width Modulation) is commonly used for: Heater control via SSR, Simple motor speed control, Valve proportional control, LED brightness control, Time-proportional control.
How do I use PWM (Pulse Width Modulation) in different PLC platforms?
Siemens: Use PULSEGEN function block in TIA Portal for PID output to PWM conversion. Allen-Bradley: Implement using timer logic or dedicated pulse output module. CODESYS: OSCAT library provides PWM function block, or implement with timer logic.
Related Function Blocks
PID (Proportional-Integral-Derivative Controller)
Closed-loop feedback controller using proportional, integral, and derivative terms.
View Reference →TP (Timer Pulse)
Generates a fixed-duration pulse on rising edge of input.
View Reference →RAMP (Ramp Function / Rate Limiter)
Limits rate of change to create smooth transitions between values.
View Reference →LIMIT (Limiter / Clamp)
Clamps a value between minimum and maximum boundaries.
View Reference →Free · no signup to try
Wire this block up and run it
Drop the instruction into a rung, press Run and watch it execute in your browser — then adapt it to your vendor tool.
Try it in your browser — no signupOpens plcsimulationsoftware.com — same team
Prefer ready-made code? Ladder Logic Pack — $29 on Gumroad