|
Aquarium Cooling Controller
ESP32 firmware for aquarium cooling fan control, monitoring, telemetry, and fault handling.
|
Measures fan speed from tachometer pulses. More...
#include <rpm_monitor.h>
Public Member Functions | |
| RpmMonitor (const RpmMonitorConfig &config=kDefaultRpmMonitorConfig) | |
| Creates an RPM monitor with the supplied tachometer configuration. | |
| bool | begin () |
| Initializes the tachometer pin and attaches the interrupt handler. | |
| void | update (uint32_t nowMs) |
| Updates the measured RPM after the configured sample window elapses. | |
| uint16_t | rpm () const |
| Returns the most recently calculated fan speed. | |
| uint32_t | pulseCount () const |
| Returns the number of pulses accumulated in the current sample. | |
| uint32_t | sampleAgeMs (uint32_t nowMs) const |
| Calculates the age of the current RPM sample. | |
Measures fan speed from tachometer pulses.
The monitor attaches an interrupt to the tachometer pin, counts falling edges, and converts each completed sample window to revolutions per minute. Only one active instance is supported because the interrupt trampoline is shared.
RPM is rounded to the nearest integer over the elapsed sample window. Reading and clearing the volatile pulse counter is protected by temporarily disabling interrupts, keeping the ISR simple and the sampling result consistent.
|
explicit |
Creates an RPM monitor with the supplied tachometer configuration.
| config | Tachometer pin, pulses-per-revolution, and sample window. |
| bool RpmMonitor::begin | ( | ) |
Initializes the tachometer pin and attaches the interrupt handler.
| uint32_t RpmMonitor::pulseCount | ( | ) | const |
Returns the number of pulses accumulated in the current sample.
| uint16_t RpmMonitor::rpm | ( | ) | const |
Returns the most recently calculated fan speed.
| uint32_t RpmMonitor::sampleAgeMs | ( | uint32_t | nowMs | ) | const |
Calculates the age of the current RPM sample.
| nowMs | Current monotonic timestamp in milliseconds. |
| void RpmMonitor::update | ( | uint32_t | nowMs | ) |
Updates the measured RPM after the configured sample window elapses.
Call this regularly from the main loop with the current millis() value.
| nowMs | Current monotonic timestamp in milliseconds. |