lm_analog_pwm

Pulse Width Modulator

The Pulse Width Modulator node converts an analog input into a pulse signal where the ON/OFF ratio depends on the modulated value of the Input connector.
The node computes the ratio between the Input value, the Input Min. property and the Input Max. property, then applies it to the Period of the output pulse to determine the ON time.
The ratio is calculated at every expiration of the Period, therefore it considers the actual value of the Input connector at that moment.

 Behaviour of PWM

Behaviour of PWM

Connector Type Description
Input Input Analog value used to calculate the PWM duty cycle.
Output Output Digital pulse generated by the node. The ON/OFF ratio depends on the current Input value.
Property Description
Input Min. Minimum value of the analog input range.
Input Max. Maximum value of the analog input range.
Period Duration of a complete PWM cycle.

The PWM node converts a continuous analog value into a time-proportional digital signal.

The current Input value is evaluated within the configured input range:

Duty Cycle = (Input - Input Min.) / (Input Max. - Input Min.)

The resulting ratio is then applied to the configured Period in order to calculate the ON time of the output pulse.

Conceptually:

ON Time = Period × Duty Cycle

OFF Time = Period - ON Time

If the input is close to Input Min., the output remains ON for a short time and OFF for most of the period.
If the input is close to Input Max., the output remains ON for most of the period.

The duty cycle is recalculated only at the expiration of the current Period.
If the Input value changes while a cycle is already in progress, the new value will be considered starting from the next PWM period.

Assume the following configuration:

Property Value
Input Min. 0
Input Max. 100
Period 10 s

Examples:

Input Duty Cycle ON Time OFF Time
0 0% 0 s 10 s
25 25% 2.5 s 7.5 s
50 50% 5 s 5 s
75 75% 7.5 s 2.5 s
100 100% 10 s 0 s

Consider the following values:

Property Value
Input Min. 0
Input Max. 100
Period 20 s
Input 30

The duty cycle is:

30 / 100 = 30%

The output pulse will therefore be:

  • ON for 6 seconds
  • OFF for 14 seconds

At the end of the 20-second period, the node reads the current Input value again and calculates the next output cycle.

The PWM node is useful when an analog regulation value must drive a digital ON/OFF command.

Typical examples include:

  • converting a heating demand into a time-proportional command;
  • controlling valves or actuators that accept only ON/OFF switching;
  • converting the output of a proportional regulator into a digital pulse sequence.

A common use case is the combination with a PID Controller, where the PID generates an analog control value and the PWM node converts it into a pulsed digital output.

The PWM node can be tested using the Logic Module simulation tools.

A typical test procedure is the following:

  • connect a variable analog value to the Input connector;
  • configure Input Min., Input Max. and Period;
  • start the simulation;
  • change the input value;
  • observe how the ON/OFF ratio of the Output changes;
  • verify that a new ratio is applied when the current period expires.

During simulation, remember that the output does not change continuously.
It changes according to the PWM cycle timing defined by the Period property.

  • Input Min. and Input Max. should match the actual range of the input value.
  • Input Max. must be greater than Input Min..
  • Choose a Period compatible with the switching speed of the controlled device.
  • Very short periods may be unsuitable for mechanical relays or slow actuators.
  • The PWM node does not generate an analog value; it generates a digital ON/OFF signal with a variable duty cycle.
  • When used together with a PID Controller, the PID output range should be compatible with the configured PWM input range.
  • lm_analog_pwm.txt
  • Last modified: 2026/09/21 12:45
  • by francesco