Motor Control Peripherals: Encoder Interface and Dead Time
What You'll Learn
- 1Decode quadrature encoder signals in hardware
- 2Generate complementary PWM with safe dead time
- 3Synchronize ADC sampling with the PWM period
- 4Use break inputs for overcurrent protection
Motor control is where timer peripherals stop being conveniences and become safety components. The same timer block that generates PWM also decodes a quadrature encoder, triggers current sampling at the right instant, and asserts a break output the moment a fault appears. Complementary outputs with programmable dead time drive the two halves of a half bridge safely, and center aligned counting keeps sampling symmetric. Getting the timer architecture right is most of the battle in a field oriented control implementation.
Quadrature Encoder Interface
An incremental encoder produces two square waves in quadrature, and the timer encoder mode counts edges on one input while sampling the other to determine direction, giving four times the pulse count in the highest resolution mode. A third index channel can reset the counter to establish an absolute mechanical position once per revolution. Hardware decoding removes the jitter and missed edges that plague interrupt driven counting at high speed.
Position resolution then depends on counts per revolution and gear ratio, while speed is measured by counting counts over a fixed window or by timing between index pulses. Choosing the window is a trade-off: short windows respond fast but are noisy, long windows are smooth but lag.
Complementary PWM and Dead Time
A half bridge needs the high side and low side switches driven in opposition, but both conducting at once creates a shoot through short across the DC bus. Programmable dead time inserts a short blanking interval after each turn off before the complementary device turns on, and the timer inserts it in hardware for both edges. Output compare mode also defines the idle state of each channel while the timer is stopped, which matters at power up.
Center aligned counting is preferred because current sampling and control updates can be placed symmetrically around the counter peak or valley, away from switching edges. The break input then forces the outputs into their safe inactive state within a few cycles when a hardware fault signal arrives, independent of any software.
Synchronized Sensing and Control Timing
The timer update event can trigger the analog to digital converter so that phase current sampling happens away from switching transitions, which is essential for clean field oriented control. Injection priority lets current conversion preempt a background scan of temperatures and bus voltage. DMA then delivers the results to a buffer that the control task reads at the start of the next period.
The whole timing chain should be documented as a single diagram: counter direction, compare match, break window, trigger edge, conversion time, and interrupt entry. When the loop misbehaves, that diagram usually reveals a sample landing on a switching edge or an interrupt arriving after the duty update.
Motor Control Timer Features
| Feature | Purpose | Why It Matters |
|---|---|---|
| Encoder mode | Hardware quadrature counting | Lossless position and speed feedback |
| Center aligned counting | Symmetric PWM generation | Clean sampling and control points |
| Complementary outputs | Drive both bridge halves | Enables half bridge topologies |
| Programmable dead time | Blanking after turn off | Prevents shoot through damage |
| Break input | Hardware fault shutdown | Protection without software latency |
| Trigger output | Start ADC conversions | Synchronized current sensing |
Real-World Examples
- Decode a rotary encoder â Select encoder mode on both channels at maximum resolution and read the count once per control tick.
- Drive a half bridge â Configure complementary outputs with dead time sized from the transistor switching data sheet.
- Sample phase current â Trigger the ADC from the timer update event away from switching edges and read results with DMA.
- Trip on overcurrent â Wire the comparator or protection signal to the break input so outputs shut down in hardware.
â ī¸Dead Time Is Set From Device Data, Not From Guesswork
Common Mistakes
Sampling current on a switching edge
Fix: Conversion triggered at the wrong counter position returns switching noise instead of the phase current.
Letting software handle overcurrent
Fix: Software latency is too slow for shoot through events; the break input must act in hardware.
Forgetting the idle state of PWM outputs
Fix: Unconfigured outputs can enable a bridge at reset or during update, so define the inactive level explicitly.
Key Takeaways
- Hardware encoder decoding gives jitter free position and speed data.
- Complementary PWM with dead time is mandatory for half bridge stages.
- Timer events should trigger ADC conversion away from switching edges.
- Break inputs provide fault protection faster than any interrupt path.
Frequently Asked Questions
Why center aligned PWM for motors?
It produces symmetric pulses and gives clean sampling points that align naturally with the control period.
How is dead time calculated?
From the switching time parameters of the transistors and drivers plus margin, converted into timer ticks at the timer clock.
Can the same timer do encoder and PWM?
Usually not on one timer; a typical design dedicates one advanced timer to PWM and a general purpose timer to encoder input.
Interview Questions
Q1: Explain the control loop timing chain.
The timer counts, the compare match updates the duty, the update event triggers ADC sampling, DMA delivers results, and the control interrupt computes the next duty before the next period starts.
Q2: Why must break input be hardware based?
A fault such as shoot through or overcurrent develops faster than software can respond, so the timer forces outputs to their safe state directly.
Extended Learning: Beyond the Basics
Key Concepts Summary
This lesson covers fundamental concepts that serve as building blocks for more advanced topics. Master these basics before moving to intermediate and advanced material.
Prerequisite Knowledge
Before studying this topic in depth, ensure you understand:
- Basic definitions and terminology
- Core formulas and their derivations
- Common applications in real-world scenarios
- Typical pitfalls and misconceptions
Step-by-Step Walkthrough
Let us work through a complete example to solidify understanding:
Step 1: Identify the problem type. Determine which category this problem falls into and which approach is most appropriate.
Step 2: Apply the relevant formula. Substitute known values into the appropriate equation, paying attention to units and constraints.
Step 3: Simplify and solve. Work through the algebra step by step, checking each intermediate result.
Step 4: Verify the answer. Check that the solution satisfies the original conditions and makes logical sense.
Common Mistakes to Avoid
- Misidentifying the problem type â Always start by categorizing the problem
- Incorrect formula application â Verify the formula applies to your specific case
- Unit errors â Always check units are consistent throughout
- Sign errors â Pay careful attention to positive and negative values
- Rounding too early â Keep full precision until the final answer
- Forgetting constraints â Check that solutions satisfy all given conditions
Real-World Applications
Understanding this concept is essential for:
- Advanced problem solving in examinations
- Building intuition for more complex topics
- Developing analytical thinking skills
- Applying mathematical reasoning to practical situations
Practice Exercises
- Basic: Solve 5 problems of increasing difficulty using the core concept.
- Intermediate: Apply the concept to word problems with multiple steps.
- Advanced: Combine this concept with 2-3 other topics in a comprehensive problem.
- Challenge: Create your own problem that requires this concept plus additional knowledge.
Interview and Exam Tips
- Common question patterns: Identify which exam or interview formats test this topic
- Time management: Practice completing problems within time constraints
- Common traps: Know the typical mistakes examiners set as distractors
- Verification strategy: Develop a quick method to check your answer
Related Topics
- Previous Topic â Build on the foundation laid here
- Next Topic â See how this concept extends to more advanced material
- Practice Problems â Additional exercises with solutions
- Video Explanation â Visual walkthrough of key concepts
Quick Reference Card
| Concept | Formula/Rule | Key Insight | Common Use |
|---|---|---|---|
| Core Definition | See main text | Understand the intuition | Foundation for all applications |
| Key Formula | See main text | Memorize the derivation | Direct problem solving |
| Special Case | See main text | Recognize when it applies | Simplifies complex problems |
| Edge Case | See main text | Know the limitations | Avoids errors |
Further Reading
For students who want to go deeper:
- Standard textbooks on the subject
- Research papers applying this concept
- Online courses with video explanations
- Practice problem collections with detailed solutions