Specialist Supplier of Crystals & Frequency Control Componentssales@mecxtal.com.cn0755-26500570
MERLIN home / Rednote / System Validation and Replacement

The 32.768 kHz crystal is running. Why does STM32 LPTIM still miss external pulses?

A sleeping device must count events from a contact, flow sensor, or rotary sensor. It wakes only occasionally. Seeing a steady LSE oscillator does not prove the timer accepts every pulse. One arrangement counts external edges as its clock. Another uses a running internal timer clock to synchronize and detect external edges. Their low-power, pulse-width and input-rate conditions differ.

Establish who samples the input

ST AN4865 describes synchronous and asynchronous arrangements. In asynchronous mode, external pulses on LPTIM Input1 can drive counting while the core clock stops. ST shows an STM32L476RG Stop 2 example. Synchronous mode uses an internal clock to synchronize the input. The application note calls for at least twice the external frequency for one active edge and four times for both edges. Verify the device reference manual for the instance, input pin, filtering, and sleep domain. One example does not establish support on every timer or Stop mode.

With 32.768 kHz LSE in the synchronous arrangement, the basic ratios give theoretical external ceilings of 16.384 kHz for one edge and 8.192 kHz for both. A 12 kHz square wave meets the one-edge ratio and exceeds the both-edge ratio. Duty cycle matters as well. A 1 kHz signal can have just 10 µs high, shorter than LSE's approximately 30.52 µs clock period. That high can fall entirely between samples. Filters can further change the minimum detectable duration. Specify both high and low widths as well as frequency limits.

Verify the power domain that owns counting

Check whether the sensor output and any pull-up remain powered. A lost pull-up can keep the input low while LPTIM otherwise operates. An analog or unselected pin configuration can also block the path. Capture the actual input at the MCU through power transitions and compare it with counter values after wake. A second waveform at the sensor cannot establish which edges reached the MCU pin.

Set counter width and polling together. A 16-bit full-range counter receiving 3,000 valid edges per second wraps in about 21.85 s. Two samples 30 s apart cannot unambiguously reconstruct all 90,000 edges without tracking overflow. Design for the maximum burst arrival rate. If an interrupt counts rollovers, verify it wakes in the chosen sleep mode without waking for every input edge and defeating standby power.

Distinguish missed edges from a reporting error

Start in Run mode with a known sequence such as 100 rising edges and confirm the selected polarity. Sweep phases with short highs and short lows. Then repeat while the system enters its real Stop mode, and read at the intended wake point. Test across a rollover as well. Record synchronous and direct external clock settings separately. Intermittent short-pulse losses across phase point to input sampling and filtering. A failure only in sleep also calls for checking sensor power, clocks and power configuration.

Preserve edge definition, minimum pulse width, standby supply, LPTIM mode, overflow strategy and measured sleep current. A crystal can be selected against the low-frequency timebase specification. Counting acceptance requires known pulse totals in the appropriate power state. A replacement sensor or duty-cycle change can then be evaluated against the same timing window.

For a reported flow rate, record actual start and end timestamps for the counting window. Counting continues while the CPU sleeps, but a late wake changes the elapsed denominator. Dividing three seconds of pulses by a nominal two seconds overreports the rate even with no lost edges. Inject a fixed pulse rate and deliberately delay wakeup to verify that the count and elapsed time advance together.

References

WeChat

MERLIN · TIMING COMPONENTS

Scan with WeChat to contact Sales

Add our WeCom contacts from your usual WeChat app.

On desktop, scan with your phone. On mobile, save the QR image and select it from your album in WeChat Scan.