The Use of PWM in Signal Processing: Applications and Techniques
If you’ve ever watched a tiny robotic arm twitch to life, a camera gimbal smoothly pan across a sunset, or a 3D printer nozzle jerk its way through a calibration routine, you’ve witnessed the quiet magic of PWM. Pulse Width Modulation is not just a technical acronym you skim past in a datasheet — it’s the beating heart of how micro servo motors interpret the digital world into precise physical motion. In this post, we’ll crack open PWM, explore its signal-processing roots, and then zoom into the microscopic world of micro servo motors — where every microsecond of pulse width matters.
What PWM Really Is (And Why It’s Not “Analog”)
Let’s start with the basics, but not the boring kind. PWM is a way of encoding an analog value using a digital square wave. Instead of varying voltage continuously (true analog), we keep the voltage constant — say 3.3V or 5V — and vary the duty cycle, which is the percentage of time the signal is HIGH versus LOW over a fixed period.
The Core Math: Duty Cycle and Frequency
Duty cycle = (Ton / Tperiod) × 100%
For example, a 50% duty cycle at 1 kHz means the pin is HIGH for 0.5 ms, then LOW for 0.5 ms, repeating forever. The average voltage seen by a low-pass filter would be 50% of the supply voltage. But here’s the kicker — PWM isn’t just about average voltage. In signal processing, PWM is a form of pulse-density modulation and a cousin of delta-sigma modulation. The frequency and the duty cycle together create a rich harmonic structure that can be exploited or filtered.
Why Not Just Use a DAC?
A digital-to-analog converter (DAC) gives you a true continuous voltage, but it’s expensive, power-hungry, and requires precision resistors. PWM, on the other hand, costs nothing extra on most microcontrollers — you just need a timer and a GPIO pin. The trade-off? You need to deal with ripple, harmonics, and timing jitter. For a micro servo motor, that trade-off is not just acceptable — it’s required.
The Micro Servo Motor: A PWM Addict
Now, let’s talk about the star of the show. A micro servo motor (like the classic SG90 or MG90S) is a tiny DC motor coupled with a gear train, a position feedback potentiometer, and a control circuit. But the magic happens at the input pin — a single PWM signal tells the motor exactly where to rotate.
The 50 Hz Convention (20 ms Period)
Standard micro servos expect a PWM signal with a period of 20 ms (50 Hz). Within that window, the on-time (pulse width) determines the angle:
- 0.5 ms pulse → 0° (full counterclockwise)
- 1.5 ms pulse → 90° (neutral center)
- 2.5 ms pulse → 180° (full clockwise)
That’s it. No I2C, no SPI, no address bits. Just a simple pulse width. But wait — there’s a hidden layer of signal processing here. The servo’s internal circuit doesn’t just measure pulse width; it compares the incoming pulse to the feedback potentiometer’s voltage via a comparator. The error signal drives the motor. This is a closed-loop control system, and PWM is the reference input.
Why 50 Hz? Why Not 500 Hz?
You might think, “Hey, if I send 500 Hz, the servo will just move faster, right?” Wrong. Most analog micro servos will overheat or chatter if you exceed 50–60 Hz. Why? Because the internal control loop is tuned to sample once per 20 ms period. If you send pulses faster, the servo’s error detection circuit gets confused — it starts integrating multiple pulses into one, causing oscillation. Some digital servos handle higher frequencies (up to 330 Hz) because they have a faster internal microcontroller that samples the PWM signal more frequently. But for your classic $3 SG90, stick to 50 Hz.
Signal Processing Techniques for Smooth Servo Motion
Here’s where things get interesting. Raw PWM at 50 Hz will move a servo, but it will also cause jerky, staircase-like motion. Why? Because the servo’s mechanical inertia and the gearbox friction mean that a sudden change from 1.0 ms to 1.5 ms pulse width will cause the motor to slam into position. To get buttery-smooth motion, you need to apply signal processing techniques to the PWM stream itself.
Technique #1: Ramping (Linear Interpolation)
Instead of jumping from 1.0 ms to 1.5 ms in one step, you generate a sequence of intermediate pulse widths. For example, over 500 ms, you update the pulse width every 10 ms, incrementing by 0.01 ms each step. This is essentially digital low-pass filtering of the position command. The servo’s mechanical response then becomes a smooth first-order system.
cpp // Pseudo-code for ramping a servo int current_pulse = 1000; // microseconds int target_pulse = 1500; int step = 1; while (current_pulse != target_pulse) { if (current_pulse < target_pulse) current_pulse += step; else current_pulse -= step; servo.writeMicroseconds(current_pulse); delay(10); }
Technique #2: Acceleration and Deceleration (S-Curve Profiling)
A linear ramp still has sharp corners at the start and end. If you’re moving a heavy load, those corners translate to sudden torque changes. To fix this, you apply a sigmoid curve to the pulse width over time. This is like applying a raised-cosine filter to the control signal. The result? The servo accelerates gently, cruises, and decelerates gently — just like a professional camera operator panning a gimbal.
Technique #3: Deadband Compensation
Every micro servo has a deadband — a small range around the center where the motor won’t move because the error signal is too small to overcome static friction. For an SG90, that deadband is often ±5–10 microseconds of pulse width. If you’re trying to hold a precise angle, the servo will just sit there and hum. To fix this, you add a small dithering signal — a high-frequency, low-amplitude PWM modulation (e.g., 1% duty cycle at 200 Hz) that keeps the motor engaged without causing visible motion. This is a classic signal processing trick borrowed from audio dithering.
Advanced PWM Signal Processing: Beyond the Basics
Now let’s step up. Micro servos are cool, but they’re also a testbed for more advanced PWM techniques that are used in industrial motor drives, audio amplifiers, and power converters.
PWM with Dead-Time Insertion
In H-bridge motor drivers, you can’t turn on the high-side and low-side transistors simultaneously — that’s a short circuit. So you insert dead-time (a few nanoseconds to microseconds) between the complementary PWM signals. For micro servos, this isn’t relevant, but for the larger servo drivers that use PWM to control the motor’s speed (not just position), it’s critical. Dead-time causes distortion, but you can compensate with a technique called dead-time distortion feedforward.
Center-Aligned vs. Edge-Aligned PWM
Edge-aligned PWM is easy: the pulse starts at the beginning of the period and ends when the counter reaches the compare value. Center-aligned PWM, however, starts the pulse in the middle of the period, so the rising and falling edges are symmetric around the center. Center-aligned mode produces lower harmonic distortion because the even harmonics cancel out. For servo control, this doesn’t matter much, but for audio PWM amplifiers, it’s a godsend.
Random PWM (RPWM)
Here’s a fun one. Instead of a fixed PWM frequency, you randomly vary the period (while keeping the duty cycle constant). This spreads the harmonic energy across the spectrum, turning a sharp tonal whine into a smooth hiss. In servo applications, this reduces audible noise from the motor windings. Some high-end micro servos (like the Hitec HS-5086MH) use RPWM internally to reduce the “servo scream” at center position.
Practical Implementation: Driving a Micro Servo with PWM on an MCU
Let’s get our hands dirty. You’re using an ESP32 or an Arduino. Here’s how to do it right, not just “good enough.”
Step 1: Use a Hardware Timer, Not delay()
Never generate servo PWM with delay() and digitalWrite(). The CPU is tied up, and any interrupt will cause jitter. Instead, use a hardware timer in PWM mode. On the ESP32, you have the LEDC peripheral. On the Arduino Uno, you have Timer1 and the Servo.h library.
cpp // ESP32 Example: 50 Hz servo PWM on GPIO 18
include <esp32-hal-ledc.h>
void setup() { ledcSetup(0, 50, 16); // channel 0, 50 Hz, 16-bit resolution ledcAttachPin(18, 0); } void loop() { ledcWrite(0, 3277); // 1.5 ms pulse: (1.5ms / 20ms) * 65536 = 4915?? Let's calc: // 0.5ms -> 0 deg: (0.5/20)65536 = 1638 // 1.5ms -> 90 deg: (1.5/20)65536 = 4915 // 2.5ms -> 180 deg: (2.5/20)*65536 = 8192 delay(1000); }
Step 2: Calibrate Your Servo’s Min and Max
Not all servos are created equal. An SG90 might accept 0.5–2.5 ms, but a metal-gear MG90S might only move from 0.6–2.4 ms before hitting its mechanical stops. If you drive it to 2.5 ms, you’ll hear a loud buzzing — that’s the motor stalling against the gearbox. You should calibrate each servo by sending progressively wider pulses until the angle stops changing, then back off by 20 microseconds.
Step 3: Smooth with a Moving Average Filter on the Command
If you’re reading a joystick or a gyroscope to command the servo, the raw data will be noisy. Apply a moving average or an exponential moving average (EMA) to the pulse width before sending it to the PWM generator. This filters out sensor noise and prevents micro-jitter.
cpp float ema = 0.9; // smoothing factor int filtered_pulse = 0; int raw_pulse = read_joystick(); filtered_pulse = (int)(ema * filtered_pulse + (1 - ema) * raw_pulse);
The Hidden Gem: Using PWM for Servo Feedback (Not Just Control)
Here’s a trick that most hobbyists miss. You can use PWM in reverse to read the servo’s position. Many micro servos have the feedback potentiometer internally, but you can’t access it. However, if you have a serial bus servo (like the LX-16A), the feedback is digital. But for standard analog servos, you can hack it by measuring the back-EMF during the off-time of the PWM cycle.
Measuring Back-EMF with PWM
When the PWM goes LOW, the motor is disconnected from power. But the motor is still spinning, so it acts as a generator, producing a voltage proportional to speed. If you sample the motor terminal voltage during the LOW period (after the flyback diode stops conducting), you can estimate the motor’s velocity. Then, by integrating velocity, you get a rough position estimate. This is called sensorless position estimation and is used in some advanced servo drivers. It’s not accurate enough for closed-loop position hold, but it’s great for detecting stall conditions.
Common Pitfalls and How to Avoid Them
Let’s talk about the ugly side of PWM + micro servo motors.
Pitfall 1: Power Supply Ripple
A micro servo can draw 200–500 mA during stall. If your power supply is weak, the voltage will dip, and the PWM signal’s HIGH level will drop below the servo’s logic threshold. The result? The servo twitches erratically. Solution: use a separate 5V supply for the servo, and star-ground the circuit. Also, place a 100 µF electrolytic capacitor right at the servo’s power pins.
Pitfall 2: Signal Ground Loops
The PWM signal’s ground reference must be the same as the servo’s ground. If you drive a servo from an MCU but power the servo from a different battery, you must connect the grounds. Otherwise, the pulse width will be interpreted incorrectly, and the servo will drift.
Pitfall 3: Timer Resolution vs. Pulse Width Step Size
On an Arduino Uno with 8-bit timers, the smallest step is 4 microseconds at 50 Hz. That’s fine. But on a 16-bit timer at 1 kHz, the smallest step might be 1 microsecond. If you need to move the servo by 0.1°, you might need a step size of 0.5 microseconds. In that case, switch to a higher-resolution timer or use a dedicated servo driver board like the PCA9685, which has 12-bit resolution (0.5 microsecond steps).
Future Trends: PWM and Digital Servo Communication
The classic PWM signal is analog in nature, but the industry is moving toward digital bus servos that use half-duplex UART (like the Dynamixel protocol) or even CAN bus. These servos receive position commands as digital packets, not as pulse widths. So why are we still talking about PWM? Because even digital servos internally use PWM to drive the motor — they just generate it on-board. Moreover, PWM is still the standard for hobby servos because it’s universal, cheap, and works with any MCU that has a timer.
The Rise of PWM-over-UART
Some newer micro servos (like the Feetech STS series) accept both PWM and UART commands. In UART mode, you send a packet with the target angle, speed, and acceleration. The servo’s internal microcontroller then generates the PWM signal for the motor. This gives you smoother motion because the acceleration profile is computed in real-time on the servo, not on the host MCU. But the underlying signal is still PWM — just generated 10 mm away from the motor instead of 10 cm away.
Hands-On Project: Build a PWM-based Servo Waveform Generator
Let’s wrap this up with a mini-project. You’ll use a Raspberry Pi Pico (RP2040) to generate two synchronized PWM signals — one for a micro servo and one for an LED that mimics the servo’s pulse width visually. This is a great way to see PWM in action.
Hardware List
- Raspberry Pi Pico
- SG90 micro servo
- 100 µF capacitor
- LED + 220 Ω resistor
- Breadboard and wires
Code Snippet (MicroPython)
python from machine import Pin, PWM import time
servo = PWM(Pin(0)) # GPIO 0 servo.freq(50) # 50 Hz led = PWM(Pin(1)) led.freq(1000) # LED doesn't need 50 Hz
def setangle(angle): # angle: 0 to 180 pulsems = 0.5 + (angle / 180.0) * 2.0 duty = int(pulsems * 65536 / 20.0) servo.dutyu16(duty) led.duty_u16(int(duty / 2)) # LED brightness proportional to pulse width
while True: for angle in range(0, 181, 5): setangle(angle) time.sleepms(50) for angle in range(180, -1, -5): setangle(angle) time.sleepms(50)
You’ll see the LED brighten as the pulse width increases, even though the LED’s PWM frequency is 1 kHz. That’s the beauty of PWM — the average value is what matters, whether it’s driving a motor or an LED.
PWM is often dismissed as a “dumb” digital signal, but when you dig into how micro servo motors use it, you realize it’s a sophisticated form of time-domain signal encoding. From ramping algorithms to deadband dithering and back-EMF sensing, PWM gives you a full toolkit for precise, smooth, and reliable motion control. The next time you see a tiny servo sweep across its 180° arc, remember: it’s not just a square wave — it’s a carefully crafted stream of microseconds, shaped by signal processing techniques that turn binary pulses into graceful physics.
Copyright Statement:
Author: Micro Servo Motor
Source: Micro Servo Motor
The copyright of this article belongs to the author. Reproduction is not allowed without permission.
Recommended Blog
- The Role of PWM in Signal Modulation: Applications and Techniques
- PWM in Power Electronics: Challenges and Solutions
- The Role of PWM in Signal Reconstruction: Applications and Techniques
- The Impact of PWM on Signal Distortion: Techniques and Tools
- The Role of Duty Cycle in PWM Signals
- The Future of PWM in Emerging Technologies
- PWM Control in Temperature Regulation Systems
- PWM Control in Robotics: A Practical Guide
- PWM Control in Power Systems: Applications and Design Considerations
- How to Implement PWM in Arduino Projects
About Us
- Lucas Bennett
- Welcome to my blog!
Hot Blog
- Micro Servos with Metal vs Plastic Gears: Impacts on Drone Durability
- The Future of Micro Servo Motors in Smart Educational Systems
- Micro Servos with Minimal Dead Band
- The Role of Thermal Management in Motor Cost Reduction
- How to Build a Remote-Controlled Car with Working Headlights
- Citizen Chiba Precision's Micro Servo Motors: Trusted by Professionals
- Building a Micro Servo Robotic Arm with a Custom PCB
- How to Build a Remote-Controlled Car with LED Lights
- Exploring the SG90 Micro Servo Motor: Features and Specifications
- How to Implement Environmental Testing in Control Circuits
Latest Blog
- How to Build a Micro Servo Robotic Arm for a Robotics Workshop
- Aluminium Body Micro Servos vs Plastic Body
- How to Program an Arduino to Control Your RC Car
- Micro Servo Motors in Laboratory Automation Systems
- The Use of PWM in Signal Processing: Applications and Techniques
- The Role of Gear Materials in Servo Motor Performance Under Varying Amplitudes
- Advances in Power Density for Micro Servo Motors
- Touch-Activated Servo Gadgets: Push Plates, Pop-Out Controls
- Voltage Requirements: Micro vs Standard Servos Compared
- How to Connect a Micro Servo Motor to Arduino MKR FOX 1200
- How to Repair and Maintain Your RC Car's Chassis
- Top Micro Servo Motors for Arduino Projects
- Micro Servos with Feedback beyond Potentiometer (optical, magnetic)
- Standard Micro Servos for Model Aircraft
- The Best Micro Servo Motors for Robotics: A Brand Comparison
- How to Design PCBs for IoT Applications
- Creating a Servo-Controlled Automated Plant Watering System with Arduino
- How to Protect Motors from Thermal Expansion Damage
- The Future of Micro Servo Motors in Smart Educational Systems
- Micro Servos for Micro-Manufacturing / Micromachining Tools