Hall-effect tachometer with an STM32
Measure rotational speed by counting Hall sensor edges and verify the pulses-per-revolution setting.
Get a clean logic pulse
Use a digital Hall sensor with an output suitable for the STM32 input. For an open-drain output, use a pull-up to 3.3 V and a common ground. Check the sensor's own supply range and output type. Rotate the shaft by hand before running the motor and verify the pulse count and polarity at the input.
Count one selected edge per magnet passage. If you use a latching sensor, check its required pole sequence. Secure the magnets and keep loose parts clear of the rotating assembly.
Convert pulses or periods to RPM
For a counting window, RPM = 60 × count / (window_seconds × pulses_per_revolution). At two pulses per revolution, 50 counts in one second give 1500 RPM. In Arduino, an attachInterrupt() callback can increment a volatile counter. Take a consistent snapshot, or use a timer's external clock mode for higher pulse rates.
At low speed, capture the timer difference between consecutive like edges and calculate RPM = 60 × timer_hz / (period_ticks × pulses_per_revolution). Use a timeout to report zero when the shaft stops, and handle counter rollover in the same width as the timer. Reject pulse intervals shorter than the maximum speed would permit.
