Search topics...
Timers & PWMMotor Controlfoundational

What is one-pulse mode (OPM), and when would you use it?

0 upvotes
Practice with AISoon
Study the fundamentals first — Timers & PWM topic page

One-pulse mode configures the timer to generate a single pulse of precise duration in response to a trigger event, then stop automatically. When triggered (by software, an external signal, or another timer), the counter starts from zero. The output remains inactive until the counter reaches CCR (this is the configurable delay before the pulse), then goes active. When the counter reaches ARR, the output deactivates and the counter stops — the OPM bit in CR1 prevents the counter from restarting. The result is one pulse with a programmable delay of CCR ticks and a width of (ARR - CCR) ticks, all generated entirely in hardware.

This is useful for generating precise one-shot timing events without continuous CPU involvement: producing an exact-width reset pulse for an external IC, triggering a camera shutter or strobe light for a measured duration, controlling solenoid activation time, or creating a programmable monostable (one-shot) multivibrator. The advantage over software timing (delay loops or timer ISRs) is that the pulse width is cycle-accurate and independent of CPU load or interrupt latency. The trigger source flexibility is also valuable — you can chain one-pulse mode with input capture so that a specific external event automatically produces a hardware-timed response pulse with zero software latency.

One subtlety: after the pulse completes, the timer is stopped and must be re-armed before it can generate another pulse. This means OPM is not suitable for repetitive pulse generation — use standard PWM for that. For retriggerable one-shot behavior (restart the pulse if a new trigger arrives before the current pulse finishes), you need to configure the slave mode controller to reset the counter on each trigger, combined with OPM.

Source: Timers & PWM Q&A