ENCODER(9)
β¨ NAME β¨
okay bestie, welcome to ENCODER(9) from the HAL Component fam! This page is literally about encoder β software counting of quadrature encoder signals. No cap. π
π SYNOPSIS π
loadrt encoder [num_chan=num | names=name1[,name2...]]
πΈ DESCRIPTION πΈ
okay so encoder is your software bestie for measuring position by counting the pulses that a quadrature encoder spits out. Because it's a software-based implementation, it's much less expensive than hardware, but it has a limited maximum count rate. That limit is in the range of 10 kHz to 50 kHz, depending on computer speed and other factors. If you need better performance, a hardware encoder counter is a better choice β some hardware-based systems can count at MHz rates. π
encoder supports a maximum of eight channels. The number of channels actually loaded is set by the num_chan argument when the module is loaded. Alternatively, specify names= and unique names separated by commas.
The num_chan= and names= specifiers are mutually exclusive. If neither num_chan= nor names= are specified, or if num_chan=0 is specified, the default value is three.
encoder has a one-phase, unidirectional mode called counter. In this mode, the phase-B input is ignored; the counts increase on each rising edge of phase-A. This mode may be useful for counting a unidirectional spindle with a single input line, though the noise-resistant characteristics of quadrature are lost. π
If used in counter-mode it is also possible to enable the missing-teeth index mode, where a gap in the pulse train of one or more teeth is used as an index marker. This system is used extensively for automotive crank position sensors. vroom vroom ποΈ
π₯ FUNCTIONS π₯
encoder.update-counters(no floating-point) β Does the actual counting, by sampling the encoder signals and decoding the quadrature waveforms. Must be called as frequently as possible, preferably twice as fast as the maximum desired count rate. Operates on all channels at once.encoder.capture-position(uses floating point) β Captures the raw counts fromupdate-countersand performs scaling and other necessary conversion, handles counter rollover, etc. Can (and should) be called less frequently thanupdate-counters. Operates on all channels at once.
π NAMING π
The names for pins and parameters are prefixed as:
encoder.N.forN=0,1,...,num-1when usingnum_chan=numnameN.fornameN=name1,name2,...when usingnames=name1,name2,...
The encoder.N. format is shown in the following descriptions. iykyk β¨
π PINS π
encoder.N.counter-mode bit i/oβ Enables counter mode. When true, the counter counts each rising edge of the phase-A input, ignoring the value on phase-B. This is useful for counting the output of a single channel (non-quadrature) sensor. When false (the default), it counts in quadrature mode.encoder.N.counts s32 outβ Position in encoder counts.encoder.N.index-enable bit i/oβ When true, counts and position are reset to zero on the next rising edge of Phase-Z. At the same time,index-enableis reset to zero to indicate that the rising edge has occurred.encoder.N.min-speed-estimate float in (default: 1.0)β Determine the minimum speed at which velocity will be estimated as nonzero and postition-interpolated will be interpolated. The units ofmin-speed-estimateare the same as the units ofvelocity. Setting this parameter too low will cause it to take a long time for velocity to go to 0 after encoder pulses have stopped arriving. don't set it too low, bestie πencoder.N.phase-A bit inβ Quadrature input for encoder channel N.encoder.N.phase-B bit inβ Quadrature input.encoder.N.phase-Z bit inβ Index pulse input.encoder.N.position float outβ Position in scaled units (seeposition-scale).encoder.N.position-interpolated float outβ Position in scaled units, interpolated between encoder counts. Only valid when velocity is approximately constant and abovemin-speed-estimate. Do not use for position control. periodt.encoder.N.position-scale float i/oβ Scale factor, in counts per length unit. For example, ifposition-scaleis500, then1000counts of the encoder will be reported as a position of2.0units.encoder.N.missing-teeth s32 inβ The number of teeth missing from the index gap. For example a60tooth gear with two teeth shortened to form an index so that there are58pulses per revolution would use aposition-scaleof60and amissing-teethof2.encoder.N.rawcounts s32 outβ The raw count, as determined byupdate-counters. This value is updated more frequently thancountsandposition. It is also unaffected by reset or the index pulse.encoder.N.reset bit inβ When true, counts and position are reset to zero immediately.encoder.N.velocity float outβ Velocity in scaled units per second.encoderuses an algorithm that greatly reduces quantization noise as compared to simply differentiating the position output. When the magnitude of the true velocity is belowmin-speed-estimate, the velocity output is0.encoder.N.velocity-rpm float outβ Velocity in scaled units per minute. Simplyencoder.N.velocityscaled by a factor of60for convenience.encoder.N.x4-mode bit i/oβ Enables times-4 mode. When true (the default), the counter counts each edge of the quadrature waveform (four counts per full cycle). When false, it only counts once per full cycle. In counter-mode, this parameter is ignored.
For the latch crew, update counts-latched and position-latched on the rising and/or falling edges of latch-input as indicated by latch-rising and latch-falling.
encoder.N.latch-input bit inencoder.N.latch-falling bit in (default: TRUE)encoder.N.latch-rising bit in (default: TRUE)encoder.N.counts-latched s32 outencoder.N.position-latched float outencoder.N.counter-mode bit rwβ Enables counter mode. When true, the counter counts each rising edge of the phase-A input, ignoring the value on phase-B. This is useful for counting the output of a single channel (non-quadrature) sensor. When false (the default), it counts in quadrature mode.encoder.N.capture-position.tmax s32 rwβ Maximum number of CPU cycles it took to execute this function.
π¦ PARAMETERS π¦
The encoder component has no HAL Parameters. Zero. None. That's it. π
That's the whole vibe, bestie! This page was brought to you by LinuxCNC Documentation, dated 2009-04-15, for ENCODER(9). Go count some edges, slay, and remember: quadrature is iconic. πβ¨π¦
π¦ where this page comes from
- debian bookworm: linuxcnc-uspace 2.9.0~pre1+git20230208.f1270d6ed7-1+deb12u2 Β· GFDL-1.1-or-later
- 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