Skip to main content
Explore ERDILRF

Press ↑↓ to move, Enter to open, Esc to close.

LRF50H: Reduce Threshold Chatter with Hysteresis

LRF50H: Reduce Threshold Chatter with Hysteresis

For an LRF50H distance indicator that flickers between “near” and “far,” use separate entry and release thresholds. Keep the previous state between them, but clear that memory when the input becomes unusable or expires. This host-side rule can reduce repeated switching around one boundary without changing the reported distance.

Define the indicator before choosing a gap

Consider a stationary industrial distance display with a proximity indicator. It provides an operator with an advisory status; this example does not define a machine stopping function. A single rule such as “near when distance is at most 200 cm” changes state whenever readings cross that one boundary. Small variations around it can therefore produce repeated changes even when the scene appears steady.

Hysteresis adds memory. The official Texas Instruments comparator note explains how separate upper and lower switching levels address repeated output changes caused by noise around a comparison threshold. We apply that principle to a host-side distance indicator: smaller distance means near. The equality handling and additional unknown state below are explicit choices for this example, not properties attributed to the analog circuit or sensor firmware.

Keep the model-specific validity check first

ERDI’s documentation review on 3 October 2026 checked the LRF50H protocol: the distance value is expressed in centimetres, and raw 65535 indicates out of range. It must not enter the comparison as a large, valid distance. Confirm the delivered output format before applying this interpretation.

The existing invalid-value handling note explains validity and expiry before averaging. Here those checks protect a discrete status instead. Assume the parser has checked a complete report, decoded the distance and applied the application’s plausibility checks. “Usable” also requires the observation to meet an application-defined freshness limit. Neither a good checksum nor a far-looking number establishes that condition by itself.

A three-state rule with explicit boundaries

Use illustrative thresholds L = 200 cm and U = 220 cm, with L < U. The hysteresis width is H = U − L = 220 − 200 = 20 cm, or 0.20 m. These are invented host settings chosen to explain the logic, not product settings, measured noise limits or recommended installation distances. All following inputs are synthetic decoded values; no measurement frequency or real-device performance is assumed.

  1. Start at UNKNOWN. Do this at application startup, restart and after a configuration change that invalidates the previous comparison.
  2. Handle unusable input first. For this example, an explicit unusable report or detected transport failure immediately sets UNKNOWN and clears the previous near/far state. Independently check expiry during silence; expiry does the same. A partial read still awaiting completion does not itself constitute a failure.
  3. On a fresh usable distance d ≤ L, set NEAR. Equality at the lower boundary enters near.
  4. On a fresh usable distance d ≥ U, set FAR. Equality at the upper boundary releases near.
  5. For L < d < U, retain the current state. This includes retaining UNKNOWN when no usable state remains. Do not recover an earlier far indication from a separate saved variable.

NEAR and FAR describe this indicator’s history-dependent threshold result. FAR is not a declaration that a machine can move. Store status separately from any historical distance shown in the interface, and make UNKNOWN visible rather than mapping it to FAR.

Replay a sequence that exposes hidden state

Start at UNKNOWN and process the rows below in order. Each numeric row is fresh and otherwise usable except the documented marker. The expiry row is a test-clock event that exceeds the application’s chosen age limit; it is not an additional sensor report.

Input, cm Expected state Reason
230 FAR Above the upper threshold
201 FAR Inside the band; retain FAR
199 NEAR Below the lower threshold
201 NEAR Same distance as before, different retained state
220 FAR Exactly at the release threshold
65535 UNKNOWN Out-of-range marker clears state
210 UNKNOWN Inside the band after state was cleared
200 NEAR Exactly at the entry threshold
Expiry event UNKNOWN No fresh usable observation remains

The two 201 cm rows are the essential check: a stateless comparison cannot produce both expected results. Also repeat the 210 cm case immediately after startup and after a detected transport failure; both must remain UNKNOWN. Then supply 220 cm and expect FAR. Exercise expiry without receive callbacks, so a silent connection cannot preserve a current-looking status indefinitely.

Choose the band from the application, then verify it

Record the unfiltered distances and status transitions around both proposed boundaries under the intended mounting and surface conditions. Choose the entry point from the display requirement and the release point from the acceptable return behavior. Examine observed variation without treating a short record as a guaranteed noise bound. Do not derive a universal band from an accuracy entry alone.

A wider gap makes release occur at a greater distance; it does not improve measurement accuracy. Hysteresis also does not reject an isolated excursion that crosses a boundary, or stop switching when the input repeatedly crosses both boundaries. If persistence checks or filtering are needed, specify and evaluate their added delay separately. Keep the raw record so a steady indicator cannot hide offset or lost observations.

These replay cases are proposed software acceptance checks, not a report of hardware testing. For a focused documentation discussion, contact ERDILRF with the model, output format, intended entry and release distances, and a short trace including validity and timestamps.