PWMGEN(9)
π pwmgen(9) π
okay so bestie, welcome to pwmgen(9) β it's a HAL Component manpage and I'm literally obsessed with it. Buckle up π
β¨ NAME β¨
pwmgen β software PWM/PDM generation π
πΈ SYNOPSIS πΈ
loadrt pwmgen output_type=type0[,type1...]
π¦ DESCRIPTION π¦
okay so pwmgen is what you use to generate PWM (pulse width modulation) or PDM (pulse density modulation) signals. no cap π―
here's the tea though: the maximum PWM frequency and the resolution are quite limited compared to hardware-based approaches. but like, in many cases software PWM can be very useful, so don't sleep on it. if you need better performance though, a hardware PWM generator is a better choice β periodt.
pwmgen supports a maximum of eight channels. the number of channels actually loaded depends on the number of type values you give it. the value of each type determines the outputs for that channel.
the three types π§
type 0: single output
A single output pin, pwm, whose duty cycle is determined by the input value for positive inputs, and which is off (or at min-dc) for negative inputs.
Suitable for single ended circuits. π«Ά
type 1: pwm/direction
Two output pins, pwm and dir. The duty cycle on pwm varies as a function of the input value. dir is low for positive inputs and high for negative inputs. π«
type 2: up/down
Two output pins, up and down. For positive inputs, the PWM/PDM waveform appears on up, while down is low. For negative inputs, the waveform appears on down, while up is low. Suitable for driving the two sides of an H-bridge to generate a bipolar output. π₯
π FUNCTIONS π
pwmgen.make-pulses(no floating-point) β Generates the actual PWM waveforms, using information computed byupdate. Must be called as frequently as possible, to maximize the attainable PWM frequency and resolution, and minimize jitter. Operates on all channels at once. β‘pwmgen.update(uses floating point) β Accepts an input value, performs scaling and limit checks, and converts it into a form usable bymake-pulsesfor PWM/PDM generation. Can (and should) be called less frequently thanmake-pulses. Operates on all channels at once. π§
π PINS π
pwmgen.N.enablebit in β Enables PWM generatorNβ when false, allpwmgen.Noutput pins are low.pwmgen.N.valuefloat in β Commanded value. Whenvalue = 0.0, duty cycle is0%, and whenvalue = Β±scale, duty cycle isΒ± 100%(subject tomin-dcandmax-dclimitations).pwmgen.N.pwmbit out (output types 0 and 1 only) β PWM/PDM waveform. πpwmgen.N.dirbit out (output type 1 only) β Direction output: low for forward, high for reverse.pwmgen.N.upbit out (output type 2 only) β PWM/PDM waveform for positive input values, low for negative inputs.pwmgen.N.downbit out (output type 2 only) β PWM/PDM waveform for negative input values, low for positive inputs.pwmgen.N.curr-dcfloat out β The current duty cycle, after all scaling and limits have been applied. Range is from-1.0to+1.0.pwmgen.N.max-dcfloat in/out β The maximum duty cycle. A value of1.0corresponds to100%. This can be useful when using transistor drivers with bootstrapped power supplies, since the supply requires some low time to recharge. πpwmgen.N.min-dcfloat in/out β The minimum duty cycle. A value of1.0corresponds to100%. Note that when the pwm generator is disabled, the outputs are constantly low, regardless of the setting ofmin-dc.pwmgen.N.scalefloat in/outpwmgen.N.offsetfloat in/out
These parameters provide a scale and offset from the value pin to the actual duty cycle. The duty cycle is calculated according to dc = (value/scale) + offset, with 1.0 meaning 100%.
pwmgen.N.pwm-freqfloat in/out β PWM frequency in Hz. The upper limit is half of the frequency at whichmake-pulsesis invoked, and values above that limit will be changed to the limit. Ifdither-pwmis false, the value will be changed to the nearest integer submultiple of themake-pulsesfrequency. A value of zero produces Pulse Density Modulation instead of Pulse Width Modulation.pwmgen.N.dither-pwmbit in/out β Because software-generated PWM uses a fairly slow timebase (several to many microseconds), it has limited resolution. For example, ifmake-pulsesis called at a20 kHzrate, andpwm-freqis2 kHz, there are only10possible duty cycles. Ifdither-pwmis false, the commanded duty cycle will be rounded to the nearest of those values. Assumingvalueremains constant, the same output will repeat every PWM cycle. Ifdither-pwmis true, the output duty cycle will be dithered between the two closest values, so that the long-term average is closer to the desired level.dither-pwmhas no effect ifpwm-freqis zero (PDM mode), since PDM is an inherently dithered process. π²
bestie pls note: the whole "only 10 possible duty cycles" thing is real and it's giving crunchy resolution, so dither it if you care about the long-term average π
and that's the page!! slayed β¨ this was pwmgen(9) from the LinuxCNC Documentation, dated 2007-01-16 β so yeah she's an icon and she's been an icon for a minute ππ byeee π¦
π¦ where this page comes from
- debian trixie: linuxcnc-uspace 1:2.9.4-2+deb13u1 Β· GFDL-1.1-or-later
- ubuntu questing: linuxcnc-uspace 1:2.9.4-2ubuntu2
- ubuntu resolute: linuxcnc-uspace 1:2.9.4-2ubuntu4 Β· GFDL-1.1-or-later
- ubuntu stonking: linuxcnc-uspace 1:2.9.4-2ubuntu4 Β· GFDL-1.1-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms