The Use of PWM in Signal Demodulation

Pulse Width Modulation (PWM) Control / Visits:13

Pulse Width Modulation, or PWM, is one of those engineering ideas that refuses to stay in its lane. Most people first encounter it as a way to dim an LED or control the speed of a DC motor, but PWM is also a remarkably effective demodulation scheme when the “signal” you care about is encoded in the width of a pulse rather than its amplitude. Nowhere is this more tangible than in the micro servo motor, a small, affordable, and surprisingly sophisticated actuator that has become a staple of robotics, RC hobbies, camera gimbals, and DIY automation. In this post, we will unpack how PWM demodulation works in the context of micro servos, why the servo’s internal control loop is essentially a real-time demodulator, and what practical lessons you can borrow when designing your own PWM-based sensing or actuation systems.

Why PWM Is More Than a Motor Trick

The Basic Idea: Information in the Duty Cycle

PWM encodes a value in the ratio of time a signal spends high versus low during a fixed period. If the period is 20 milliseconds and the high time is 1.5 milliseconds, the duty cycle is 7.5 percent. That number can represent brightness, speed, torque, or, in the servo world, an angular position. The key insight is that PWM is a time-domain encoding. The information lives in the timing, not in the voltage level. That makes it robust against amplitude noise, supply droop, and many of the analog gremlins that plague voltage-mode signaling.

Demodulation as a Timing Problem

Demodulation, broadly defined, is the process of recovering the original information from a modulated carrier. In a PWM system, the “carrier” is the periodic pulse train, and the “modulation” is the varying pulse width. A PWM demodulator therefore needs to measure the high time, compare it to a reference, and convert that measurement into a usable output. In a micro servo, that output is a target angle for a closed-loop position controller. The servo does not simply “play back” the pulse width; it interprets the width as a setpoint and then drives its internal motor until the feedback potentiometer agrees.

Inside the Micro Servo: A Demodulator in Disguise

The Signal Chain from Pin to Horn

A typical micro servo contains four essential blocks: a small DC motor, a gear train, a position-sensing potentiometer, and a control board. The control board receives the PWM command on its signal pin, typically a 3.3 V or 5 V logic signal. The first thing the board does is demodulate that pulse train into a numeric setpoint. Most hobby servos expect a 50 Hz frame rate, with a 1.0 ms pulse corresponding to one extreme and a 2.0 ms pulse to the other, though many micro servos accept a wider 0.5 ms to 2.5 ms range for extended travel.

The demodulation step is usually implemented with a timer capture peripheral or a simple edge-timing routine. The controller measures the high time, filters it lightly, and maps it to a target position. That target is then compared against the potentiometer’s wiper voltage, which represents the actual horn angle. The error between target and actual drives the motor through an H-bridge. In this sense, the servo is a complete demodulate-compare-actuate loop running thousands of times per second.

Why the 50 Hz Frame Rate Matters

The 20 ms frame period is not arbitrary. It is slow enough to be easy to generate with cheap timers and robust enough to tolerate jitter on long signal wires, yet fast enough that a human perceives the servo response as immediate. For a micro servo, the frame rate also sets the update bandwidth of the demodulator. If you send commands faster than the frame rate, the servo will simply ignore or average them. If you send them slower, the servo will hold its last setpoint. Understanding this relationship is the first step toward using PWM demodulation deliberately rather than accidentally.

Demodulation Techniques You Can Actually Build

Edge Capture with a Microcontroller

The most straightforward way to demodulate a PWM signal is to use a microcontroller’s input capture unit. Configure a timer to record the timestamp on a rising edge and again on the falling edge, then subtract. The result is the pulse width in timer ticks, which you convert to microseconds. This method is precise, low-jitter, and works well for servo command decoding, throttle signals, and many sensor outputs. On a modern MCU, you can capture both edges with DMA and never burden the CPU.

RC Filtering and Analog Reconstruction

If you need a smooth analog voltage proportional to duty cycle, a simple RC low-pass filter followed by a buffer will do the job. The filter averages the PWM waveform, and the resulting DC level is proportional to the duty cycle. This is the classic PWM-to-analog demodulator. It is cheap and effective, but it has tradeoffs: ripple, settling time, and sensitivity to the filter’s cutoff frequency. For servo-adjacent applications like reading a PWM-based temperature sensor or a light-to-frequency converter, this approach is often good enough.

Software Timing and Interrupt-Driven Decoding

When hardware capture units are scarce, a pin-change interrupt or a tight polling loop can measure pulse widths in software. The risk is jitter from interrupt latency and other tasks. For micro servo projects on small boards, a dedicated timer interrupt is usually the sweet spot. The lesson is that demodulation quality depends as much on your timing architecture as on your math.

The Micro Servo as a Hot Topic in PWM Demodulation

Why Micro Servos Are Everywhere

Micro servos weigh a few grams, cost a few dollars, and deliver surprising torque for their size. They appear in robot arms, pan-tilt camera mounts, animatronics, drone payload mechanisms, and educational kits. Their popularity has made the 50 Hz PWM interface a de facto standard, which in turn has created a huge ecosystem of PWM generators, servo testers, and libraries. When people talk about PWM demodulation in a hobby context, they are often really talking about decoding servo commands.

Feedback, Back-EMF, and the Limits of Open-Loop Thinking

A common misconception is that a servo is an open-loop device that simply moves to the width you send. In reality, the potentiometer closes the loop. That feedback path is what makes the servo a demodulator with memory: it remembers the last valid setpoint and holds position until a new one arrives. Some advanced micro servos also expose current draw or back-EMF information, which can be used to infer load or detect stalls. Those signals are themselves often PWM-encoded, which means your controller may need a second demodulation channel just to monitor the servo’s health.

Practical Gotchas: Jitter, Range, and Power

Micro servos are sensitive to signal quality. Long ground returns, shared power rails, and noisy motor drivers can corrupt the pulse train. A demodulator with hysteresis and a sanity check on pulse width will reject glitches that would otherwise cause twitching. Also, not every micro servo honors the full 0.5 ms to 2.5 ms range; some clamp internally, and some will buzz at the extremes. Finally, power matters. A servo that browns out during a fast move will produce erratic feedback, which looks like demodulation failure but is really a supply problem.

Designing a Robust PWM Demodulation Pipeline

Timing, Filtering, and Validation

A solid demodulation pipeline starts with accurate edge timing, adds a light median or moving-average filter to reject outliers, and validates the result against expected bounds. For servo commands, reject pulses shorter than 0.3 ms or longer than 3.0 ms. For sensor PWM, validate against the datasheet’s duty cycle range. The goal is not to smooth away real changes but to discard physically impossible ones.

From Demodulated Value to Control Action

Once you have a clean pulse width, map it to engineering units. For a servo, that means converting microseconds to degrees using a calibration table. For a PWM-based sensor, it means converting duty cycle to temperature, pressure, or light level. The mapping should be explicit and documented, because the same pulse width can mean different things in different systems. This is where good demodulation becomes good system design.

Testing with a Logic Analyzer and a Script

You cannot debug what you cannot see. A cheap logic analyzer plus a script that sweeps pulse widths across the expected range will reveal dead zones, nonlinearities, and response lag. For micro servos, test small steps as well as large ones. A servo that tracks a 1.5 ms command perfectly may still overshoot on a 0.5 ms jump. The demodulator is only half the story; the actuator’s dynamics complete it.

Beyond the Hobby Bench: Where This Matters

PWM demodulation shows up far beyond servo headers. Industrial sensors often output PWM to avoid analog noise. Optical encoders and Hall-effect sensors may encode position as duty cycle. Even some audio Class-D amplifiers are, at heart, PWM systems whose demodulation is handled by the speaker and filter network. The micro servo is a friendly entry point because it makes the abstract concrete: you send a pulse, and a physical horn moves. That tangibility is why micro servos remain such a useful teaching tool for signal processing and control.

A Final Word on Pulse Widths and Precision

The elegance of PWM demodulation is that it turns a humble square wave into a carrier of precise information. In a micro servo, that information becomes motion, and the servo’s internal feedback loop becomes a live demonstration of demodulation in action. Whether you are building a robot arm, a camera gimbal, or a custom sensor interface, the principles are the same: measure the timing carefully, validate the result, and respect the dynamics of whatever comes next. Pulse widths may look simple on a scope, but they carry a surprising amount of engineering weight.

Copyright Statement:

Author: Micro Servo Motor

Link: https://microservomotor.com/pulse-width-modulation-pwm-control/pwm-signal-demodulation.htm

Source: Micro Servo Motor

The copyright of this article belongs to the author. Reproduction is not allowed without permission.

About Us

Lucas Bennett avatar
Lucas Bennett
Welcome to my blog!

Tags