pwmset: Set PWM Duty-Cycle
The pwmset
application can be used to change the duty cycle of a PWM output. The value of the duty cycle has a width of
10 bits, i.e. the minimum value is 0 and the maximum value is 1023. The application can be used to set the value
in different ways. On the one hand, the output can be set to a specific value. On the other hand, the user can
change the duty cycle interactively. Another option is to generate simple signals at the output.
Note
The PWM channel must first be enabled via systemset
. The period or frequency
of the PWM signal can also be set applying this command. This value is identical for all PWM outputs.
Synopsis
- Options:
- -h, --help
Displays help on commandline options.
- --help-all
Displays help, including generic Qt options.
- -v, --version
Displays version information.
- -a, --address <host>
Host address of the gateway [localhost].
- -p, --port <port>
Port of the gateway [51955].
- -s, --severity <level>
Max severity (fatal|error|warning|info|debug|verbose) of log message.
- -f, --frequency <period>
Frequency (period) of sending in ms [1000]
- --debug
Report additional debug info in log.
- --value <value>
(Max) value to be set.
- --min <value>
Minimum value to be set.
- --step <number>
Number of intermediate steps.
- --signal <algorithm>
Signal to be generated (linear|scurve).
- --stepdown
Stepdown the signal before repetition.
- Arguments:
channel identifier of the pwm channel.
Examples
Interactive Mode
In the simplest case, the application starts in interactive mode when it is called
using ./pwmset -a blackbox1 -s info 0
. The duty cycle of PWM channel 0 is changed according to the user input.
Single Mode
The call ./pwmset -a blackbox1 -f 0 --value 0 -s info 0
sets the duty cycle to the constant value (in this case 0)
and the application exits.

This example uses --value 200
to set the duty cycle to 200/1023 == 19.55%.
User-Defined Sequence
By specifying the parameter --value
several times, the duty cycle is changed according to the specified
frequency. This allows a simple sequence of different duty cycle values to be generated. In this
example ./pwmset -a blackbox1 -f 500 --value 100 --value 500 --value 1000 -s info 0
, a duty cycle of
100, 500 and 1000 is changed one after the other at intervals of half a second (according to -f 500
). The
sequence then starts again.
If the parameter --stepdown
is also specified, the intermediate steps (i.e. the values between the first and last parameters)
are repeated in reverse order before the sequence starts again from the beginning.
Signal Generator
It is possible to generate a sequence of duty cycle values automatically. By specifying the parameter --signal
,
you can choose between two generated signals, linear
or scurve
. An ascending sequence of values is generated,
starting from the minimum (can be changed using --min
) to the maximum value (can be changed using -value
). The
number of intermediate steps is specified by the parameter --step
.
The used sigmoid function (S-like shape scurve
) to generate the signal is based on \(f(t) = \frac{1}{1+e^{-t}}\).
Using ./pwmset -a blackbox1 -f 250 -s info --value 1000 --signal scurve --step 10 --stepdown 0
changes the duty cycle of the channel 0 from 0 to 1000 with 10 intermediate steps corresponding to a sigmoid function
with a period of 250 milliseconds. The intermediate steps are then run through in reverse order before the entire
sequence starts again.
2024-05-10 11:01:25.446 NONE Press Ctrl-C to abort application.
2024-05-10 11:01:25.446 INFO Set PWM channel #0
2024-05-10 11:01:25.446 INFO Try to connect to blackbox1@51955...
2024-05-10 11:01:25.446 INFO Generate s-curve signal [0..1000] steps: 10
2024-05-10 11:01:25.446 INFO Step-down the signal, in total 22 steps.
2024-05-10 11:01:25.446 INFO The values are: 0, 36, 72, 139, 251, 410, 589, 748, 860, 927
2024-05-10 11:01:25.446 INFO 963, 1000, 963, 927, 860, 748, 589, 410, 251, 139
2024-05-10 11:01:25.446 INFO 72, 36.
2024-05-10 11:01:25.468 INFO Client is connected...
2024-05-10 11:01:25.472 INFO Session identifier 7, protocol version 0
Using the parameter --signal linear
instead results in different distribution of the values.
2024-05-10 11:10:49.612 NONE Press Ctrl-C to abort application.
2024-05-10 11:10:49.613 INFO Set PWM channel #0
2024-05-10 11:10:49.613 INFO Try to connect to blackbox1@51955...
2024-05-10 11:10:49.613 INFO Generate linear signal [0..1000] steps: 10
2024-05-10 11:10:49.613 INFO Step-down the signal, in total 22 steps.
2024-05-10 11:10:49.613 INFO The values are: 0, 90, 181, 272, 363, 454, 545, 636, 727, 818
2024-05-10 11:10:49.613 INFO 909, 1000, 909, 818, 727, 636, 545, 454, 363, 272
2024-05-10 11:10:49.613 INFO 181, 90.
2024-05-10 11:10:49.715 INFO Session identifier 11, protocol version 0