Internal Components
Stepgen
This component provides software based generation of step pulses in
response to position commands. It has a built in pre-tuned position
loop, so PID tuning is not required. This component is strongly recommended
for stepper based EMC machines, since it eliminates the need to use
(and tune) a separate PID loop. It is a realtime component only, and
depending on CPU speed, etc, is capable of maximum step rates of 10kHz
to perhaps 50kHz. Figure shows three
block diagrams, each is a single step pulse generator. The first diagram
is for step type '0', (step and direction). The second is for step
type '1' (up/down, or pseudo-PWM), and the third is for step types
2 through 14 (various stepping patterns).
Figure:
Step Pulse Generator Block Diagram
|
-
- emc2$ halcmd loadrt stepgen step_type=<config-array>
<config-array> is a series of comma separated decimal integers.
Each number causes a single step pulse generator to be loaded, the
value of the number determines the stepping type. For example:
-
- emc2# halcmd loadrt stepgen.o step_type=0,0,2
will install three step generators, two with step type '0' (step and
direction) and one with step type '2' (quadrature). The default value
for <config-array> is ``0,0,0'' which will install
three type '0' (step/dir) generators. The maximum number of step generators
is 8 (as defined by MAX_CHAN in stepgen.c). Each generator is independent,
but all are updated by the same function(s) at the same time. In the
following descriptions, <chan> is the number of a specific
generator. The first generator is number 0.
-
- emc2$ halcmd unloadrt stepgen
Each step pulse generator will have only some of these pins, depending
on the step type selected.
- (FLOAT) stepgen.<chan>.position-cmd - Desired
motor position, in position units (inches, mm, etc).
- (S32) stepgen.<chan>.count - Feedback position
in counts, updated by capture_position().
- (FLOAT) stepgen.<chan>.position-fb - Feedback
position in position units, updated by capture_position().
- (BIT) stepgen.<chan>.step - Step pulse output
(step type 0 only).
- (BIT) stepgen.<chan>.dir - Direction output
(step type 0 only).
- (BIT) stepgen.<chan>.up - UP pseudo-PWM
output (step type 1 only).
- (BIT) stepgen.<chan>.down - DOWN pseudo-PWM
output (step type 1 only).
- (BIT) stepgen.<chan>.phase-A - Phase A output
(step types 2-14 only).
- (BIT) stepgen.<chan>.phase-B - Phase B output
(step types 2-14 only).
- (BIT) stepgen.<chan>.phase-C - Phase C output
(step types 3-14 only).
- (BIT) stepgen.<chan>.phase-D - Phase D output
(step types 5-14 only).
- (BIT) stepgen.<chan>.phase-E - Phase E output
(step types 11-14 only).
- (FLOAT) stepgen.<chan>.position-scale -
Steps per position unit. This parameter is used for both output and
feedback.
- (FLOAT) stepgen.<chan>.maxfreq - Maximum
step rate, in steps per second. If 0.0, has no effect.
- (FLOAT) stepgen.<chan>.maxaccel - Maximum
accel/decel rate, in steps per second squared. If 0.0, has no effect.
- (FLOAT) stepgen.<chan>.pos-err - The position
error - difference between commanded and actual position, in steps.
- (FLOAT) stepgen.<chan>.vel-err - The velocity
error - in steps per second.
- (FLOAT) stepgen.<chan>.frequency - The current
step rate, in steps per second. This is the output of the position
loop.
- (FLOAT) stepgen.<chan>.steplen - Length
of a step pulse (step type 0 only).
- (FLOAT) stepgen.<chan>.stepspace - Minimum
spacing between two step pulses (step type 0 only).
- (FLOAT) stepgen.<chan>.dirsetup - Minimum
time from a direction change to the beginning of the next step pulse
(step type 0 only).
- (FLOAT) stepgen.<chan>.dirhold - Minmum
time from the end of a step pulse to a direction change (step type
0 only).
- (S32) stepgen.<chan>.rawcounts - The raw
feedback count, updated by make_pulses().
The values of maxfreq and maxaccel are used by the internal position
loop to avoid generating step pulse trains that the motor cannot follow.
When set to values that are appropriate for the motor, even a large
instantaneous change in commanded position will result in a smooth
trapezoidal move to the new location. The algorithm works by measuring
both position error and velocity error, and calculating an acceleration
that attempts to reduce both to zero at the same time. For more details,
including the contents of the ``control equation'' box, consult
the code.
Step Types
The step generator supports 15 different ``step types''. Step
type 0 is the most familiar, standard step and direction. When configured
for step type 0, there are four extra parameters that determine the
exact timing of the step and direction signals. See figure
for the meaning of these parameters. The parameters are integers,
and represent a number of calls to make_pulses(). For example,
if make_pulses() is called every 16uS, and steplen is 2,
then the step pulses will be 2 x 16 = 32uS long. The default value
for all four of the parameters is 1. Since one step requires steplen
periods high and stepspace periods low, the maximum frequency
is the thread frequency divided by (steplen+stepspace). If
maxfreq is set higher than that limit, it will be lowered
automatically. If maxfreq is zero, it will remain zero, but the output
frequency will still be limited.
Figure:
Step and Direction Timing
|
Step type 1 has two outputs, up and down. Pulses appear on one or
the other, depending on the direction of travel. Each pulse is one
thread period long, and the pulses are separated by at least one thread
period. As a result, the maximum step frequency is half of the thread
rate. If maxfreq is set higher than the limit it will be
lowered. If maxfreq is zero, it will remain zero but the
output frequency will still be limited.
Step types 2 through 14 are state based, and have from two to five
outputs. On each step, a state counter is incremented or decremented.
Figures , , and
show the output patterns as a function of the state counter. The maximum
frequency is the same as the thread rate, and as in the other modes,
maxfreq will be lowered if it is above the limit.
Figure:
Quadrature and Three Phase Step Types
|
Figure:
Four-Phase Step Types
|
Figure:
Five-Phase Step Types
|
The component exports three functions. Each function acts on all of
the step pulse generators - running different generators in different
threads is not supported.
- (FUNCT) stepgen.make-pulses - High speed
function to generate and count pulses (no floating point).
- (FUNCT) stepgen.update-freq - Low speed
function does position to velocity conversion, scaling and limiting.
- (FUNCT) stepgen.capture-position - Low speed
function for feedback, updates latches and scales position.
The high speed function stepgen.make-pulses should be run
in a very fast thread, from 10 to 50uS depending on the capabilities
of the computer. That thread's period determines the maximum step
frequency, and is also the time unit used by the length, space, setup,
and hold parameters (step type 0). The other two functions can be
called at a much lower rate.
Freqgen
This component provides software based generation of step pulses from
a frequency or velocity command. EMC normally uses position commands,
not velocity commands, and stepgen (described in section
is more appropriate. However, there may be applications where velocity
based pulses are needed. One such application is using step type 1
as a pseudo-PWM output. Combined with a PID loop. the software encoder
counter module, and a simple H-bridge, this has been used to run small
DC servomotors, however now that the pwmgen component has been added,
it is a better choice for this purpose. Another possible use for freqgen
is to simply spin a stepper motor at a constant (or adjustable) rate,
while ignoring position. Freqgen uses the same pulse generator core
as stepgen, however it has no position loop. It is a realtime component
only, and depending on CPU speed, etc, is capable of maximum step
rates of 10kHz to perhaps 50kHz. Figure
shows three block diagrams, each is a single step pulse generator.
The first diagram is for step type '0', (step and direction). The
second is for step type '1' (up/down, or pseudo-PWM), and the third
is for step types 2 through 14 (various stepping patterns).
Figure:
Step Pulse Generator Block Diagram
|
-
- emc2$ halcmd loadrt freqgen step_type=<config-array>
<config-array> is a series of comma separated decimal integers.
Each number causes a single frequency generator to be loaded, the
value of the number determines the stepping type. For example:
-
- emc2$ halcmd loadrt freqgen step_type=0,0,2
will install three frequency generators, two with step type '0' (step
and direction) and one with step type '2' (quadrature). The default
value for <config-array> is ``0,0,0'' which
will install three type '0' (step/dir) generators. The maximum number
of frequency generators is 8 (as defined by MAX_CHAN in freqgen.c).
Each generator is independent, but all are updated by the same function(s)
at the same time. In the following descriptions, <chan> is
the number of a specific generator. The first generator is number
0.
-
- emc2$ halcmd unloadrt freqgen
Each frequency generator will have only some of these pins, depending
on the step type selected.
- (FLOAT) freqgen.<chan>.velocity - Desired
velocity, in arbitrary units.
- (BIT) freqgen.<chan>.step - Step pulse output
(step type 0 only).
- (BIT) freqgen.<chan>.dir - Direction output
(step type 0 only).
- (BIT) freqgen.<chan>.up - UP pseudo-PWM
output (step type 1 only).
- (BIT) freqgen.<chan>.down - DOWN pseudo-PWM
output (step type 1 only).
- (BIT) freqgen.<chan>.phase-A - Phase A output
(step types 2-14 only).
- (BIT) freqgen.<chan>.phase-B - Phase B output
(step types 2-14 only).
- (BIT) freqgen.<chan>.phase-C - Phase C output
(step types 3-14 only).
- (BIT) freqgen.<chan>.phase-D - Phase D output
(step types 5-14 only).
- (BIT) freqgen.<chan>.phase-E - Phase E output
(step types 11-14 only).
- (S32) freqgen.<chan>.count - Feedback position
in counts, updated by capture_position().
- (FLOAT) freqgen.<chan>.position-fb - Position
feedback in arbitrary units updated by capture_position().
- (FLOAT) freqgen.<chan>.velocity-scale -
Scaling factor to convert from velocity units to pulses per second
(Hz).
- (FLOAT) freqgen.<chan>.maxfreq - Maximum
frequency, in Hz. If 0.0, has no effect. If set higher than internal
limits, next call of update_freq() will set it to the internal
limit.
- (FLOAT) freqgen.<chan>.frequency - The current
frequency, in Hz. This is the value after scaling and limiting.
- (FLOAT) freqgen.<chan>.maxaccel - Maximum
accel/decel rate, in Hz per second. If 0.0, has no effect.
- (FLOAT) freqgen.<chan>.steplen - Length
of a step pulse (step type 0 only).
- (FLOAT) freqgen.<chan>.stepspace - Minimum
spacing between two step pulses (step type 0 only).
- (FLOAT) freqgen.<chan>.dirsetup - Minimum
time from a direction change to the beginning of the next step pulse
(step type 0 only).
- (FLOAT) freqgen.<chan>.dirhold - Minmum
time from the end of a step pulse to a direction change (step type
0 only).
- (S32) freqgen.<chan>.rawcounts - The raw
feedback count, updated by make_pulses().
- (FLOAT) freqgen.<chan>.position-scale -
The scale factor used to convert from feedback counts to position
units.
The frequency generator supports 15 different ``step types''.
Except for stepping type 1, they are identical to those generated
by the stepgen component. Refer to section
for more information.
There is one difference between stepgen and freqgen. Step type 1 has
two outputs, up and down. Pulses appear on one or the other, depending
on the direction of travel. Each pulse is one thread period long.
Stepgen assumes that you need a distinct pulse for each step, so it
limits the frequency to half of the thread rate, to allow for one
low period between pulses. However, freqgen allows higher frequencies,
up to the thread rate. This allows step type 1 to be used as a pseudo-PWM
source, or filtered to use as a D-to-A converter. At the maximum frequency
(equal to the thread rate), the up or down output will remain on constantly.
The component exports three functions. Each function acts on all of
the step pulse generators - running different generators in different
threads is not supported.
- (FUNCT) freqgen.make-pulses - High speed
function to generate and count pulses (no floating point).
- (FUNCT) freqgen.update-freq - Low speed
function to scale and limit velocity command.
- (FUNCT) freqgen.capture-position - Low speed
function for feedback, updates latches and scales position.
The high speed function freqgen.make-pulses should be run
in a very fast thread, from 10 to 50uS depending on the capabilities
of the computer. That thread's period determines the maximum step
frequency, and is also the time unit used by the length, space, setup,
and hold parameters (step type 0). The other two functions can be
called at a much lower rate.
PWMgen
This component provides software based generation of PWM (Pulse Width
Modulation) and PDM (Pulse Density Modulation) waveforms. It is a
realtime component only, and depending on CPU speed, etc, is capable
of PWM frequencies from a few hundred Hertz at pretty good resolution,
to perhaps 10KHz with limited resolution.
-
- emc2$ halcmd loadrt pwmgen output_type=<config-array>
<config-array> is a series of comma separated decimal integers.
Each number causes a single PWM generator to be loaded, the value
of the number determines the output type. For example:
-
- emc2$ halcmd loadrt pwmgen step_type=0,1,2
will install three PWM generators. The first one will use output type
'0' (PWM only), the next uses output type 1 (PWM and direction) and
the last one uses output type 2 (UP and DOWN). There is no default
value, if <config-array> is not specified, no PWM generators
will be installed. The maximum number of frequency generators is 8
(as defined by MAX_CHAN in pwmgen.c). Each generator is independent,
but all are updated by the same function(s) at the same time. In the
following descriptions, <chan> is the number of a specific
generator. The first generator is number 0.
-
- emc2$ halcmd unloadrt pwmgen
Each PWM generator will have the following pins:
- (FLOAT) pwmgen.<chan>.value - Command value,
in arbitrary units. Will be scaled by the scale parameter
(see below).
- (BIT) pwmgen.<chan>.enable - Enables or
disables the PWM generator outputs.
Each PWM generator will also have some of these pins, depending on
the output type selected:
- (BIT) pwmgen.<chan>.pwm - PWM (or PDM) output,
(output types 0 and 1 only).
- (BIT) pwmgen.<chan>.dir - Direction output
(output type 1 only).
- (BIT) pwmgen.<chan>.up - PWM/PDM output
for positive input value (output type 2 only).
- (BIT) pwmgen.<chan>.down - PWM/PDM output
for negative input value (output type 2 only).
- (FLOAT) pwmgen.<chan>.scale - Scaling factor
to convert value from arbitrary units to duty cycle.
- (FLOAT) pwmgen.<chan>.pwm-freq - Desired
PWM frequency, in Hz. If 0.0, generates PDM instead of PWM. If set
higher than internal limits, next call of update_freq()
will set it to the internal limit. If non-zero, and dither
is false, next call of update_freq() will set it to the
nearest integer multiple of the make_pulses() function period.
- (BIT) pwmgen.<chan>.dither-pwm - If true,
enables dithering to achieve average PWM frequencies or duty cycles
that are unobtainable with pure PWM. If false, both the PWM frequency
and the duty cycle will be rounded to values that can be achieved
exactly.
- (FLOAT) pwmgen.<chan>.min-dc - Minimum duty
cycle, between 0.0 and 1.0 (duty cycle will go to zero when disabled,
regardless of this setting).
- (FLOAT) pwmgen.<chan>.max-dc - Maximum duty
cycle, between 0.0 and 1.0.
- (FLOAT) pwmgen.<chan>.curr-dc - Current
duty cycle - after all limiting and rounding (read only).
The PWM generator supports three different ``output types''. Type
0 has a single output pin. Only positive commands are accepted, negative
values are treated as zero (and will be affected by min-dc
if it is non-zero). Type 1 has two output pins, one for the PWM/PDM
signal and one to indicate direction. The duty cycle on the PWM pin
is based on the absolute value of the command, so negative values
are acceptable. The direction pin is false for positive commands,
and true for negative commands. Finally, type 2 also has two outputs,
called up and down. For positive commands, the PWM signal appears
on the up output, and the down output remains false. For negative
commands, the PWM signal appears on the down output, and the up output
remains false. Output type 2 is suitable for driving most H-bridges.
The component exports two functions. Each function acts on all of
the PWM generators - running different generators in different threads
is not supported.
- (FUNCT) pwmgen.make-pulses - High speed
function to generate PWM waveforms (no floating point).
- (FUNCT) pwmgen.update - Low speed function
to scale and limit value and handle other paremeters.
The high speed function pwmgen.make-pulses should be run
in a very fast thread, from 10 to 50uS depending on the capabilities
of the computer. That thread's period determines the maximum PWM carrier
frequency, as well as the resolution of the PWM or PDM signals. The
other function can be called at a much lower rate.
Encoder
This component provides software based counting of signals from quadrature
encoders. It is a realtime component only, and depending on CPU speed,
etc, is capable of maximum count rates of 10kHz to perhaps 50kHz.
Figure is a block diagram of one channel
of encoder counter.
Figure:
Encoder Counter Block Diagram
|
-
- emc2$ halcmd loadrt encoder [num_chan=<counters>]
<counters> is the number of encoder counters that you want
to install. If numchan is not specified, three counters will
be installed. The maximum number of counters is 8 (as defined by MAX_CHAN
in encoder.c). Each counter is independent, but all are updated by
the same function(s) at the same time. In the following descriptions,
<chan> is the number of a specific counter. The first counter
is number 0.
-
- emc2$ halcmd unloadrt encoder
- (BIT) encoder.<chan>.phase-A - Phase A of
the quadrature encoder signal.
- (BIT) encoder.<chan>.phase-B - Phase B of
the quadrature encoder signal.
- (BIT) encoder.<chan>.phase-Z - Phase Z (index
pulse) of the quadrature encoder signal.
- (BIT) encoder.<chan>.reset - See canonical
encoder interface, section .
- (BIT) encoder.<chan>.velocity - Estimated
speed of the quadrature signal.
- (BIT) encoder.<chan>.index-enable - See
canonical encoder interface.
- (S32) encoder.<chan>.count - See canonical
encoder interface.
- (FLOAT) encoder.<chan>.position - See canonical
encoder interface.
- (S32) encoder.<chan>.raw-count - The raw
count value, updated by update-counters().
- (BIT) encoder.<chan>.x4-mode -
Sets encoder to 4x or 1x mode. The 1x mode is usefull for some jogwheels.
- (FLOAT) encoder.<chan>.position-scale -
See canonical encoder interface, section .
The component exports two functions. Each function acts on all of
the encoder counters - running different counters in different threads
is not supported.
- (FUNCT) encoder.update-counters - High speed
function to count pulses (no floating point).
- (FUNCT) encoder.capture-position - Low speed
function to update latches and scale position.
PID
This component provides Proportional/Integeral/Derivative control
loops. It is a realtime component only. For simplicity, this discussion
assumes that we are talking about position loops, however this component
can be used to implement other feedback loops such as speed, torch
height, temperature, etc. Figure is a block
diagram of a single PID loop.
Figure:
PID Loop Block Diagram
|
-
- emc2$ halcmd loadrt pid [num_chan=<loops>] [debug=1]
<loops> is the number of PID loops that you want to install.
If numchan is not specified, one loop will be installed.
The maximum number of loops is 16 (as defined by MAX_CHAN in pid.c).
Each loop is completely independent. In the following descriptions,
<loopnum> is the loop number of a specific loop. The first
loop is number 0.
If debug=1 is specified, the component will export a few
extra parameters that may be useful during debugging and tuning. By
default, the extra parameters are not exported, to save shared memory
space and avoid cluttering the parameter list.
-
- emc2$ halcmd unloadrt pid
The three most important pins are
- (FLOAT) pid.<loopnum>.command - The desired
position, as commanded by another system component.
- (FLOAT) pid.<loopnum>.feedback - The present
position, as measured by a feedback device such as an encoder.
- (FLOAT) pid.<loopnum>.output - A velocity
command that attempts to move from the present position to the desired
position.
For a position loop, 'command' and 'feedback' are in position units.
For a linear axis, this could be inches, mm, meters, or whatever is
relevant. Likewise, for an angular axis, it could be degrees, radians,
etc. The units of the 'output' pin represent the change needed to
make the feedback match the command. As such, for a position loop
'Output' is a velocity, in inches/sec, mm/sec, degrees/sec, etc. Time
units are always seconds, and the velocity units match the position
units. If command and feedback are in meters, then output is in meters
per second.
Each loop has two other pins which are used to monitor or control
the general operation of the component.
- (FLOAT) pid.<loopnum>.error - Equals .command
minus .feedback.
- (BIT) pid.<loopnum>.enable - A bit that
enables the loop. If .enable is false, all integrators are
reset, and the output is forced to zero. If .enable is true,
the loop operates normally.
The PID gains, limits, and other 'tunable' features of the loop are
implemented as parameters.
- (FLOAT) pid.<loopnum>.Pgain - Proportional
gain
- (FLOAT) pid.<loopnum>.Igain - Integral gain
- (FLOAT) pid.<loopnum>.Dgain - Derivative
gain
- (FLOAT) pid.<loopnum>.bias - Constant offset
on output
- (FLOAT) pid.<loopnum>.FF0 - Zeroth order
feedforward - output proportional to command (position).
- (FLOAT) pid.<loopnum>.FF1 - First order
feedforward - output proportional to derivative of command (velocity).
- (FLOAT) pid.<loopnum>.FF2 - Second order
feedforward - output proportional to 2nd derivative of command (acceleration)1.1.
- (FLOAT) pid.<loopnum>.deadband - Amount
of error that will be ignored
- (FLOAT) pid.<loopnum>.maxerror - Limit on
error
- (FLOAT) pid.<loopnum>.maxerrorI - Limit
on error integrator
- (FLOAT) pid.<loopnum>.maxerrorD - Limit
on error derivative
- (FLOAT) pid.<loopnum>.maxcmdD - Limit on
command derivative
- (FLOAT) pid.<loopnum>.maxcmdDD - Limit on
command 2nd derivative
- (FLOAT) pid.<loopnum>.maxoutput - Limit
on output value
All of the max??? limits are implemented such that if the
parameter value is zero, there is no limit.
If debug=1 was specified when the component was installed,
four additional parameters will be exported:
- (FLOAT) pid.<loopnum>.errorI - Integral
of error.
- (FLOAT) pid.<loopnum>.errorD - Derivative
of error.
- (FLOAT) pid.<loopnum>.commandD - Derivative
of the command.
- (FLOAT) pid.<loopnum>.commandDD - 2nd derivative
of the command.
The component exports one function for each PID loop. This function
performs all the calculations needed for the loop. Since each loop
has its own function, individual loops can be included in different
threads and execute at different rates.
- (FUNCT) pid.<loopnum>.do_pid_calcs - Performs
all calculations for a single PID loop.
If you want to understand the exact algorithm used to compute the
output of the PID loop, refer to figure ,
the comments at the beginning of emc2/src/hal/components/pid.c,
and of course to the code itself. The loop calculations are in the
C function calc_pid().
Simulated Encoder
The simulated encoder is exactly that. It produces quadrature pulses
with an index pulse, at a speed controlled by a HAL pin. Mostly useful
for testing.
-
- emc2$ halcmd loadrt sim-encoder num_chan=<number>
<number> is the number of encoders that you want to simulate.
If not specified, one encoder will be installed. The maximum number
is 8 (as defined by MAX_CHAN in sim_encoder.c).
-
- emc2$ halcmd unloadrt sim-encoder
- (FLOAT) sim-encoder.<chan-num>.speed - The
speed command for the simulated shaft.
- (BIT) sim-encoder.<chan-num>.phase-A - Quadrature
output.
- (BIT) sim-encoder.<chan-num>.phase-B - Quadrature
output.
- (BIT) sim-encoder.<chan-num>.phase-Z - Index
pulse output.
When .speed is positive, .phase-A leads .phase-B.
- (U32) sim-encoder.<chan-num>.ppr - Pulses
Per Revolution.
- (FLOAT) sim-encoder.<chan-num>.scale - Scale
Factor for speed. The default is 1.0, which means
that speed is in revolutions per second. Change
to 60 for RPM, to 360 for degrees per second, 6.283185 for radians
per seconed, etc.
Note that pulses per revolution is not the same as counts per revolution.
A pulse is a complete quadrature cycle. Most encoder counters will
count four times during one complete cycle.
The component exports two functions. Each function affects all simulated
encoders.
- (FUNCT) sim-encoder.make-pulses - High speed
function to generate quadrature pulses (no floating point).
- (FUNCT) sim-encoder.update-speed - Low speed
function to read speed, do scaling, and set up make-pulses.
Debounce
Debounce is a realtime component that can filter the glitches created
by mechanical switch contacts. It may also be useful in other applications
where short pulses are to be rejected.
-
- emc2$ halcmd loadrt debounce cfg=''
<config-string> is a series of space separated decimal integers.
Each number installs a group of identical debounce filters, the number
determines how many filters are in the group. For example:
-
- emc2$ halcmd loadrt debounce cfg=''1 4 2''
will install three groups of filters. Group 0 contains one filter,
group 1 contains four, and group 2 contains two filters. The default
value for <config-string> is ``1'' which will
install a single group containing a single filter. The maximum number
of groups 8 (as defined by MAX_GROUPS in debounce.c). The maximum
number of filters in a group is limited only by shared memory space.
Each group is completely independent. All filters in a single group
are identical, and they are all updated by the same function at the
same time. In the following descriptions, <G> is the group
number and <F> is the filter number within the group. The
first filter is group 0, filter 0.
-
- emc2$ halcmd unloadrt debounce
Each individual filter has two pins.
- (BIT) debounce.<G>.<F>.in - Input of filter
<F> in group <G>.
- (BIT) debounce.<G>.<F>.out - Output of filter
<F> in group <G>.
Each group of filters has one parameter1.2.
- (S32) debounce.<G>.delay - Filter delay
for all filters in group <G>.
The filter delay is in units of thread periods. The minimum delay
is zero. The output of a zero delay filter exactly follows its input
- it doesn't filter anything. As delay increases, longer
and longer glitches are rejected. If delay is 4, all glitches
less than or equal to four thread periods will be rejected.
Each group of filters has one function, which updates all the filters
in that group ``simultaneously''. Different groups of filters
can be updated from different threads at different periods.
- (FUNCT) debounce.<G> - Updates all filters
in group <G>.
Blocks
Blocks is a realtime HAL component containing a number of simple functional
blocks. They are primarily intended for testing and other offhand
uses, but may prove useful for some EMC configurations as well.
The complete list of available blocks is as follows:
- constant - makes a parameter value available on a pin
- comp - standard 2-input comparator with adjustable hysteresis
- wcomp - window comparator, output true when input is between adjustable
upper and lower limits
- sum2 - 2-input summer, output = in0 * gain0 + in1 * gain1
- mux2 - 2-input multiplexor, output = in0 if sel is false, output
= in1 if sel is true
- mux4 - 4-input multiplexor, output = in<n> based on sel0, sel1
- integ - integrator, input of +1.0 produces an output ramp of +1.0
per second
- ddt - differentiator, input ramp of +1.0 per second produces output
of +1.0
- limit1 - first order limiter (limits output)
- limit2 - second order limiter (limits output and 1st derivative)
- limit3 - third order limiter (limits ouput, 1st & 2nd derivative)
- estop - latch for estops or other faults, with reset
- not - logical inverter
- and2 - 2 input logical and
- or2 - 2 input logical or
- scale - gain/offset block (out = in * gain + offset)
- lowpass - lowpass filter (out = last_out * (1 - gain) + in *
gain
- match8 - 8 bit binary match detector (with input for cascading)
-
- emc2$ halcmd loadrt blocks <blockname>=<number>
<blockname> is the name of one of the functional blocks that
the component can provide, and <number> is the desired quantity
of that block. Multiple name/number pairs may be specified on the
command line to install a variety of different blocks. For example:
-
- emc2$ halcmd loadrt blocks wcomp=2 sum2=1 comp=3
installs two window comparators (wcomp), one two-input summer (sum2),
and three standard comparators (comp).
-
- emc2$ halcmd unloadrt blocks
The various blocks each have their own input and output pins. Each
pin begins with the block name, then the block number, and finally
the pin function.
- (FLOAT) constant.<num>.out - Output
of constant block, tracks the parameter value.
- (FLOAT) comp.<num>.in0 - Inverting input
of 2-input comparator.
- (FLOAT) comp.<num>.in1 - Non-inverting
input of 2-input comparator.
- (BIT) comp.<num>.out - Output, true if
in1 > in0.
- (FLOAT) wcomp.<num>.in -Input of window
comparator.
- (BIT) wcomp.<num>.out - Output, TRUE if
min < input < max.
- (FLOAT) sum2.<num>.in0 - First input of
2-input summer.
- (FLOAT) sum2.<num>.in1 - Second input
of 2-input summer.
- (FLOAT) sum2.<num>.out - Output, equals
in0 * gain0 + in1 * gain1.
- (FLOAT) mux2.<num>.in0 - First input of
2-input multiplexor.
- (FLOAT) mux2.<num>.in1 -Second input of
2-input multiplexor.
- (BIT) mux2.<num>.sel - Control input of
2-input multiplexor.
- (FLOAT) mux2.<num>.out - Output, equals
in0 if sel is FALSE, in1 if sel
is TRUE.
- (FLOAT) integ.<num>.in - Input of integrator.
- (FLOAT) integ.<num>.out - Output of integrator.
- (FLOAT) ddt.<num>.in - Input of differentiator.
- (FLOAT) ddt.<num>.out - Output of differentiator.
- ... and so on (too many pins to list them all here, but you can easily
see them with halcmd show pin )
Some of the blocks have parameters that control and adjust the details
of their operation. Like the pin names, they begin with the block
name and the block number, then the parameter name.
- (FLOAT) constant.<num>.value - The value
to be written to the out pin, default value is 1.0.
- (FLOAT) comp.<num>.hyst - Hystersis for
2-input comparator, default is 0.0.
- (FLOAT) wcomp.<num>.min - Minimum threshold
for window comparator, default is -1.0.
- (FLOAT) wcomp.<num>.max - Maximum threshold
for window comparator, default is +1.0.
- (FLOAT) sum2.<num>.gain0 - Value by which
in0 is multiplied, default is 1.0.
- (FLOAT) sum2.<num>.gain1 - Value by which
in1 is multiplied, default is 1.0.
Each individual block has its own function. This allows complete control
over when each block executes. In general, blocks should execute in
the order of signal flow. If the outputs of blocks A and B are connected
to inputs of block C, then the functions for A and B should be executed
before the function for C. Note that unless these functions are connected
to a realtime thread so that they execute, the blocks do nothing at
all.
- (FUNCT) constant.<num> - Writes parameter
value to pin out.
- (FUNCT) comp.<num> - Compares in0
and in1 (with hysteresis), writes result to out.
- (FUNCT) wcomp.<num> - Compares in
to min and max, writes result to out.
- (FUNCT) sum2.<num> - Computes out
= in0 * gain0 + in1 * gain1.
- (FUNCT) mux2.<num> - If sel is
TRUE, writes in1 to out, else writes in0
to out.
- (FUNCT) integ.<num> - Calculates integral
of in, writes result to out.
- (FUNCT) constant.<num> - Calculates derivative
of in, writes result to out.
Siggen
Siggen is a realtime component that generates square, triangle, and
sine waves. It is primarily used for testing.
-
- emc2$ halcmd loadrt siggen [num_chan=<chans>]
<chans> is the number of signal generators that you want
to install. If numchan is not specified, one signal generator
will be installed. The maximum number of generators is 16 (as defined
by MAX_CHAN in siggen.c). Each generator is completely independent.
In the following descriptions, <chan> is the number of a
specific signal generator (the numbers start at 0).
-
- emc2$ halcmd unloadrt siggen
Each generator has five output pins.
- (FLOAT) siggen.<chan>.sine - Sine wave output.
- (FLOAT) siggen.<chan>.cosine - Cosine output.
- (FLOAT) siggen.<chan>.sawtooth - Sawtooth
output.
- (FLOAT) siggen.<chan>.triangle - Triangle
wave output.
- (FLOAT) siggen.<chan>.square - Square wave
output.
All five outputs have the same frequency, amplitude, and offset.
In addition to the output pins, there are three control pins:
- (FLOAT) siggen.<chan>.frequency - Sets the
frequency in Hertz, default value is 1 Hz.
- (FLOAT) siggen.<chan>.amplitude - Sets the
peak amplitude of the output waveforms, default is 1.
- (FLOAT) siggen.<chan>.offset - Sets DC offset
of the output waveforms, default is 0.
For example, if siggen.0.amplitude is 1.0 and siggen.0.offset
is 0.0, the outputs will swing from -1.0 to +1.0. If siggen.0.amplitude
is 2.5 and siggen.0.offset is 10.0, then the outputs will
swing from 7.5 to 12.5.
None. 1.3
- (FUNCT) siggen.<chan>.update - Calculates
new values for all five outputs.
Footnotes
- ...1.1
- FF2 is not currently implemented, but it will be added. Consider this
note a ``FIXME'' for the code
- ... parameter1.2
- Each individual filter also has an internal state variable. There
is a compile time switch that can export that variable as a parameter.
This is intended for testing, and simply wastes shared memory under
normal circumstances.
- ...1.3
- Prior to version 2.1, frequency, amplitude, and offset were parameters.
They were changed to pins to allow control by other components.
2007-01-14