summaryrefslogtreecommitdiff
path: root/docs/man/man9/pwmgen.9
blob: df4a74bf9943044d1232ef2411fe6b4ebaa65ee2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
.TH PWMGEN "9" "2007-01-16" "LinuxCNC Documentation" "HAL Component"
.de TQ
.br
.ns
.TP \\$1
..

.SH NAME
pwmgen \- software PWM/PDM generation
.SH SYNOPSIS
\fBloadrt pwmgen output_type=\fItype0\fR[,\fItype1\fR...]

.SH DESCRIPTION
\fBpwmgen\fR is used to generate PWM (pulse width modulation) or
PDM (pulse density modulation) signals.  The maximum PWM frequency
and the resolution is quite limited compared to hardware-based 
approaches, but in many cases software PWM can be very useful.
If better performance is needed, a hardware PWM generator is a
better choice.
.P
\fBpwmgen\fR supports a maximum of eight channels.  The number of
channels actually loaded depends on the number of \fItype\fR values
given.  The value of each \fItype\fR determines the outputs for that
channel.
.P
.TP
type 0: single output
A single output pin, \fBpwm\fR, whose duty cycle is determined by the
input value for positive inputs, and which is off (or at \fBmin-dc\fR)
for negative inputs.  Suitable for single ended circuits.
.TP
type 1: pwm/direction
Two output pins, \fBpwm\fR and \fBdir\fR.  The duty cycle on \fBpwm\fR
varies as a function of the input value.  \fBdir\fR is low for positive
inputs and high for negative inputs.
.TP
type 2: up/down
Two output pins, \fBup\fR and \fBdown\fR.  For positive inputs, the
PWM/PDM waveform appears on \fBup\fR, while \fBdown\fR is low.  For
negative inputs, the waveform appears on \fBdown\fR, while \fBup\fR
is low.  Suitable for driving the two sides of an H-bridge to generate
a bipolar output.

.SH FUNCTIONS
.TP 
\fBpwmgen.make-pulses \fR(no floating-point)
Generates the actual PWM waveforms, using information computed by
\fBupdate\fR.  Must be called as frequently as possible, to maximize
the attainable PWM frequency and resolution, and minimize jitter.
Operates on all channels at once.
.TP
\fBpwmgen.update \fR(uses floating point)
Accepts an input value, performs scaling and limit checks, and converts
it into a form usable by \fBmake-pulses\fR for PWM/PDM generation.  Can
(and should) be called less frequently than \fBmake-pulses\fR.  Operates
on all channels at once.

.SH PINS
.TP
\fBpwmgen.\fIN\fB.enable\fR bit in
Enables PWM generator \fIN\fR - when false, all \fBpwmgen.\fIN\fR output
pins are low.
.TP
\fBpwmgen.\fIN\fB.value\fR float in
Commanded value.  When \fBvalue\fR = 0.0, duty cycle is 0%, and when
\fBvalue\fR = +/-\fBscale\fR, duty cycle is +/- 100%. (Subject to
\fBmin-dc\fR and \fBmax-dc\fR limitations.)
.TP
\fBpwmgen.\fIN\fB.pwm\fR bit out (output types 0 and 1 only)
PWM/PDM waveform.
.TP
\fBpwmgen.\fIN\fB.dir\fR bit out (output type 1 only)
Direction output: low for forward, high for reverse.
.TP
\fBpwmgen.\fIN\fB.up\fR bit out (output type 2 only)
PWM/PDM waveform for positive input values, low for negative inputs.
.TP
\fBpwmgen.\fIN\fB.down\fR bit out (output type 2 only)
PWM/PDM waveform for negative input values, low for positive inputs.

.SH PARAMETERS
.TP
\fBpwmgen.\fIN\fB.curr-dc\fR float ro
The current duty cycle, after all scaling and limits have been applied.
Range is from -1.0 to +1.0.
.TP
\fBpwmgen.\fIN\fB.max-dc\fR float rw
The maximum duty cycle.  A value of 1.0 corresponds to 100%.  This can
be useful when using transistor drivers with bootstrapped power supplies,
since the supply requires some low time to recharge.
.TP
\fBpwmgen.\fIN\fB.min-dc\fR float rw
The minimum duty cycle.  A value of 1.0 corresponds to 100%.  Note that
when the pwm generator is disabled, the outputs are constantly low,
regardless of the setting of \fBmin-dc\fR.
.TP
\fBpwmgen.\fIN\fB.scale\fR float rw
.TQ
\fBpwmgen.\fIN\fB.offset\fR float rw
These parameters provide a scale and offset from the \fBvalue\fR pin to the
actual duty cycle.  The duty cycle is calculated according to \fIdc =
(value/scale) + offset\fR, with 1.0 meaning 100%.
.TP
\fBpwmgen.\fIN\fB.pwm-freq\fR float rw
PWM frequency in Hz.  The upper limit is half of the frequency at which
\fBmake-pulses\fR is invoked, and values above that limit will be changed
to the limit.  If \fBdither-pwm\fR is false, the value will be changed to
the nearest integer submultiple of the \fBmake-pulses\fR frequency.  A
value of zero produces Pulse Density Modulation instead of Pulse Width
Modulation.
.TP
\fBpwmgen.\fIN\fB.dither-pwm\fR bit rw
Because software-generated PWM uses a fairly slow timebase (several to many
microseconds), it has limited resolution.  For example, if \fBmake-pulses\fR
is called at a 20KHz rate, and \fBpwm-freq\fR is 2KHz, there are only 10
possible duty cycles.  If \fBdither-pwm\fR is false, the commanded duty cycle
will be rounded to the nearest of those values.  Assuming \fBvalue\fR remains
constant, the same output will repeat every PWM cycle.  If \fBdither-pwm\fR is
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.  \fBdither-pwm\fR
has no effect if \fBpwm-freq\fR is zero (PDM mode), since PDM is an inherently
dithered process.