Skip to content

Commit 34798b5

Browse files
committed
fix: detect stopped fan when tach count is at max value
EMC2305 returns near-max tach count (~1022) when no tach signal is detected. Added TACH_COUNT_STOPPED_THRESHOLD constant to detect this condition and return 0 RPM for stopped fans.
1 parent 6d3f02a commit 34798b5

2 files changed

Lines changed: 9 additions & 0 deletions

File tree

emc2305/driver/constants.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@
477477
TACH_COUNT_MAX = 0x1FFF
478478
"""Maximum tachometer count value (13-bit)"""
479479

480+
TACH_COUNT_STOPPED_THRESHOLD = 1000
481+
"""Tach count threshold for detecting stopped fan (after 3-bit shift).
482+
EMC2305 returns near-max values (e.g., 1022) when no tach signal is detected."""
483+
480484
# Minimum valid TACH count - fan is considered stalled below this
481485
DEFAULT_VALID_TACH_COUNT = 0x0FFF
482486
"""Default minimum valid tachometer count for stall detection"""

emc2305/driver/emc2305.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,11 @@ def get_current_rpm(self, channel: int) -> int:
12451245
raw_tach = (tach_high << const.TACH_COUNT_HIGH_SHIFT) | tach_low
12461246
tach_count = raw_tach >> const.TACH_COUNT_LOW_SHIFT
12471247

1248+
# Check for max TACH count - indicates no tach signal (fan stopped)
1249+
# EMC2305 returns 0x1FFF (or near max) when no pulses are detected
1250+
if tach_count >= const.TACH_COUNT_STOPPED_THRESHOLD:
1251+
return 0
1252+
12481253
# Convert to RPM
12491254
config = self._fan_configs.get(channel, FanConfig())
12501255
rpm = self._tach_count_to_rpm(tach_count, config.edges)

0 commit comments

Comments
 (0)