The Role of Duty Cycle in PWM Signals

Pulse Width Modulation (PWM) Control / Visits:4

In the world of robotics, automation, and hobbyist electronics, few components are as ubiquitous and essential as the micro servo motor. These small, lightweight actuators form the backbone of countless projects, from robotic arms and camera gimbals to animatronics and RC vehicles. At the heart of every micro servo’s operation lies a seemingly simple yet profoundly important concept: the Pulse Width Modulation (PWM) signal. And within that signal, the duty cycle plays the starring role.

Understanding the duty cycle is not merely an academic exercise; it is the key to unlocking the full potential of your micro servo motors. Whether you are a seasoned engineer or a curious maker, grasping how duty cycle translates into angular position, torque, and speed will elevate your control strategies from guesswork to precision engineering. This article delves deep into the mechanics, mathematics, and practical applications of duty cycles in PWM signals, specifically as they relate to the nuanced world of micro servo motors.

The Anatomy of a PWM Signal

Before we can appreciate the duty cycle, we must first understand the signal that carries it. A PWM signal is a square wave—a periodic signal that alternates between a high voltage (typically 5V or 3.3V for logic levels) and a low voltage (0V). This is not a continuous analog voltage; it is a digital pulse train.

The signal is characterized by two fundamental parameters:

  • Frequency (f): The number of complete cycles (on-off-on) per second, measured in Hertz (Hz). For standard micro servo motors, the industry standard frequency is 50 Hz, meaning one complete cycle occurs every 20 milliseconds (ms).
  • Period (T): The duration of one complete cycle. Since ( T = 1/f ), a 50 Hz signal has a period of ( T = 1/50 = 0.02 ) seconds, or 20 ms.

Within each 20 ms window, the signal is high for a portion of the time and low for the remainder. This is where the duty cycle enters the stage.

What Exactly is Duty Cycle?

The duty cycle is the percentage of one period in which a signal is active or “high.” It is calculated as:

[ \text{Duty Cycle (\%)} = \left( \frac{\text{Pulse Width (on time)}}{\text{Period (total time)}} \right) \times 100\% ]

For micro servo motors, the pulse width (the “on” time) is the critical variable. While the period remains constant at 20 ms, the pulse width varies typically between 1 ms and 2 ms. This small window of time is the language through which we command the servo’s position.

Let’s break down the math:

  • 1 ms pulse width: Duty cycle = (1 ms / 20 ms) * 100% = 5%
  • 1.5 ms pulse width: Duty cycle = (1.5 ms / 20 ms) * 100% = 7.5%
  • 2 ms pulse width: Duty cycle = (2 ms / 20 ms) * 100% = 10%

So, the entire operational range of a standard micro servo—from 0 degrees to 180 degrees—is mapped onto a duty cycle range of just 5% to 10%. This narrow window makes precision critical.

Why Not a Wider Range?

You might wonder why we don’t use a wider range, say 0% to 100%. The answer lies in the internal electronics of the servo. The servo’s control circuit interprets the pulse width, not the duty cycle percentage directly. It compares the incoming pulse width to an internal potentiometer reading that indicates the current shaft position. If the pulse width is too short (below 0.5 ms) or too long (above 2.5 ms), the servo may enter an undefined state, jitter, or attempt to rotate beyond its mechanical limits, potentially damaging the gears.

The Direct Relationship: Duty Cycle to Angular Position

The most intuitive application of duty cycle in a micro servo is controlling the shaft angle. The relationship is linear within the operating range.

Consider a standard micro servo like the SG90 or MG90S:

| Pulse Width (ms) | Duty Cycle (%) | Approximate Angle (degrees) | | :--------------- | :------------- | :-------------------------- | | 1.0 | 5.0% | 0° (full left) | | 1.25 | 6.25% | 45° | | 1.5 | 7.5% | 90° (center) | | 1.75 | 8.75% | 135° | | 2.0 | 10.0% | 180° (full right) |

This table demonstrates a clear, proportional relationship. A change of 0.25 ms in pulse width corresponds to a 45° rotation. In duty cycle terms, a 1.25% change in duty cycle results in a 45° change in angle.

Practical Implication for Programmers

If you are coding a microcontroller (e.g., Arduino, ESP32, Raspberry Pi Pico), you rarely think in terms of duty cycle percentage. Instead, you work with pulse width values. However, the underlying hardware—the timer and the PWM peripheral—operates on duty cycle.

For example, on an Arduino, you might use the Servo.h library, which abstracts away the PWM details. But if you are using bare-metal PWM, you must set a compare register value. If your timer is set to a resolution of 20,000 counts for a 20 ms period (at 50 Hz), then:

  • 1 ms pulse = 1000 counts → Duty cycle = 1000/20000 = 5%
  • 1.5 ms pulse = 1500 counts → Duty cycle = 1500/20000 = 7.5%
  • 2 ms pulse = 2000 counts → Duty cycle = 2000/20000 = 10%

This mapping is crucial. A single count error can shift the servo by 0.18 degrees (180° / 1000 counts), which is imperceptible in many applications but catastrophic in precision tasks like camera stabilization or surgical robotics.

Beyond Position: Duty Cycle and Torque

While angle control is the headline feature, the duty cycle also influences the torque output of a micro servo, albeit indirectly. The relationship is governed by the average voltage delivered to the motor.

The average voltage of a PWM signal is:

[ V{avg} = V{high} \times \text{Duty Cycle} ]

For a 5V signal with a 7.5% duty cycle (center position), the average voltage is only 0.375V. This low average voltage is sufficient to maintain position against light loads because the servo’s internal H-bridge and control loop continuously adjust the power to the DC motor.

However, when the servo is commanded to move to a new position, the control circuit temporarily applies full power (100% duty cycle) to the motor to overcome inertia. Once the target position is reached, the duty cycle drops back to the holding value (5-10%).

The Stall Condition

If you load the servo heavily, the control circuit will increase the duty cycle to the motor to maintain position. If the load exceeds the motor’s stall torque, the servo will draw maximum current, and the duty cycle will saturate at 100% (or near it) as the motor tries desperately to reach the commanded position. This is why you hear a high-pitched whine from a stalled servo—the PWM frequency is audible through the motor windings.

Understanding this behavior is vital for battery-powered projects. A stalled servo can drain a battery in minutes. By monitoring the duty cycle command sent to the motor (not the input signal), you can implement software-based stall detection and protection.

Duty Cycle and Speed Control

Standard micro servo motors are designed for position control, not continuous rotation. However, many servos can be modified for continuous rotation (often called “360° servos”). In this mode, the duty cycle no longer controls angle; it controls speed and direction.

  • 1.5 ms (7.5% duty cycle): Stop (neutral).
  • 1.0 ms (5.0% duty cycle): Full speed clockwise.
  • 2.0 ms (10.0% duty cycle): Full speed counter-clockwise.

The duty cycle now maps linearly to rotational speed. A duty cycle of 6.25% might give 50% speed clockwise, while 8.75% gives 50% speed counter-clockwise. This is a powerful feature for building differential drive robots or winches.

The Nonlinear Reality

In practice, the speed-to-duty-cycle relationship is not perfectly linear, especially near the neutral point. There is often a dead band around 7.5% duty cycle where the motor does not move. This is due to mechanical friction and the internal dead zone in the control circuit. You may need to calibrate your servo by experimentally determining the minimum pulse width that causes rotation.

The Impact of PWM Frequency on Micro Servos

We have focused on the standard 50 Hz (20 ms period) frequency, but what happens if you change the frequency? This is a common pitfall for beginners.

Most micro servos expect a refresh rate of 50 Hz. If you use a higher frequency, such as 200 Hz (5 ms period), the servo’s control circuit becomes confused. It expects a pulse every 20 ms, but it receives one every 5 ms. The internal timing fails, and the servo will jitter, overheat, or fail to hold position.

Why? The servo’s control IC uses the pulse width to set the position, but it also uses the time between pulses to reset its internal state. With a higher frequency, the pulse width itself might be correct (e.g., 1.5 ms), but the circuit interprets the rapid succession of pulses as a constant high signal, effectively seeing a 100% duty cycle. This drives the motor to full power, causing violent oscillation.

Rule of Thumb: Always use 50 Hz for standard analog micro servos. Digital servos can handle higher frequencies (up to 333 Hz or more), but always check the datasheet.

Duty Cycle Resolution: The 8-bit vs. 16-bit Debate

The precision with which you can set the duty cycle depends on the resolution of your PWM hardware.

  • 8-bit PWM: Offers 256 discrete steps (0 to 255). For a 20 ms period, each step represents 78.125 µs (20 ms / 256). This gives a pulse width resolution of about 78 µs. Over the 1 ms to 2 ms range (1000 µs span), you have only about 12.8 usable steps. That translates to roughly 14° per step—far too coarse for smooth motion.
  • 16-bit PWM: Offers 65,536 steps. Each step represents 0.305 µs (20 ms / 65536). Over the same 1 ms to 2 ms range, you have 3277 steps, giving a resolution of 0.055° per step. This is exceptionally smooth.

Most microcontrollers (e.g., Arduino Uno) use 8-bit PWM on their standard analogWrite() pins, which is why you should never use analogWrite() to control a servo. Instead, use dedicated timer-based libraries (like Servo.h) that leverage 16-bit timers to achieve the necessary resolution.

Practical Advice for High-Resolution Control

If you are building a project that requires ultra-smooth movement, such as a pan-tilt camera mount, consider using a microcontroller with hardware 16-bit PWM timers, like the ESP32 or Teensy. These allow you to set the duty cycle with microsecond precision directly.

For example, on an ESP32 using the LEDC PWM library, you can set the duty cycle to 3000 out of 65535 for a 1.5 ms pulse, giving you the fine control needed to eliminate visible stepping.

Temperature Drift and Duty Cycle Stability

Micro servo motors are not precision instruments. Their internal components—the potentiometer, the control IC, and the motor—are all susceptible to temperature changes.

As the servo warms up during operation, the resistance of the potentiometer can change slightly. This causes the feedback voltage to drift, and the control circuit compensates by adjusting the duty cycle. You may observe that a servo commanded to the center position (1.5 ms) slowly drifts a few degrees over 30 minutes of operation.

This is not a failure of the duty cycle concept but a limitation of the hardware. For applications requiring long-term stability (e.g., a telescope focuser), you can implement external feedback using a separate absolute encoder and a PID loop that adjusts the PWM duty cycle dynamically.

Mitigation Strategies

  • Use digital servos with higher-quality potentiometers and better temperature compensation.
  • Implement a periodic recalibration routine in your code.
  • Use a heatsink on the servo if it operates under continuous load.

Duty Cycle in Advanced Control: The PID Loop

In sophisticated robotics projects, the duty cycle is not set directly by the user. Instead, it is the output of a PID (Proportional-Integral-Derivative) controller.

Consider a robotic arm joint. The user commands a target angle of 90°. The microcontroller reads the current angle from a sensor (or the servo’s feedback wire). The PID controller calculates the error (target - current) and outputs a correction value. This correction value is then mapped to a pulse width (and thus a duty cycle) that drives the servo toward the target.

The duty cycle in this scenario is dynamic. It starts high to achieve fast movement, then decreases as the servo approaches the target to prevent overshoot. The integral term accumulates over time to eliminate steady-state error, effectively fine-tuning the duty cycle to the exact value needed to hold position against a constant load.

This is where a deep understanding of duty cycle pays off. If your PID output saturates at the 5% or 10% duty cycle limits, your controller will become ineffective. You must scale the PID output to fit within the 1 ms to 2 ms pulse width window, and you must handle the case where the output exceeds those bounds (anti-windup).

Common Pitfalls and Debugging Duty Cycle Issues

Even experienced engineers can fall into traps when working with servo duty cycles. Here are the most common issues and how to diagnose them.

Problem 1: Servo Jitters at Center Position

Symptoms: The servo oscillates rapidly around the commanded position, making a buzzing sound.

Causes: - PWM frequency is not 50 Hz. - Power supply is inadequate (voltage drops below 4.8V under load). - The duty cycle is set to a value in the servo’s dead band (rare, but possible with low-quality servos).

Solution: Verify your PWM frequency with an oscilloscope. Ensure your power supply can deliver at least 1A for a single micro servo. Add a 470 µF capacitor across the servo power pins to smooth out voltage spikes.

Problem 2: Servo Does Not Reach Full Range

Symptoms: The servo only rotates 90° instead of 180°.

Causes: - The minimum and maximum pulse widths are not calibrated to the servo. - Some servos have a mechanical stop that limits rotation to less than 180°.

Solution: Experimentally determine the pulse width limits for your specific servo. Start with 0.5 ms and 2.5 ms, but be cautious not to exceed the mechanical limits. Most hobby servos safely operate between 0.6 ms and 2.4 ms.

Problem 3: Servo Moves in the Wrong Direction

Symptoms: Commanding 0° moves the servo to 180°.

Causes: - The pulse width mapping is inverted in software. - The servo is a reverse-rotation variant (less common).

Solution: Invert your mapping function. Instead of mapping angle to pulse width linearly, use: ( pulseWidth = 2.0 - (angle / 180.0) ).

The Future: Duty Cycle in Smart Servos

The landscape of micro servos is evolving. Smart servos (e.g., Dynamixel, FEETECH) use a digital communication protocol (like TTL serial or I2C) instead of PWM. In these servos, the duty cycle is handled internally by the servo’s own microcontroller. The user sends a position command as a digital value (e.g., 0 to 1023), and the servo’s internal PID loop generates the PWM signal to the motor.

This offloads the timing precision from the main controller and allows for features like temperature monitoring, load sensing, and daisy-chaining multiple servos. However, the fundamental principle remains the same: the motor inside the smart servo is still driven by PWM, and the duty cycle determines its behavior.

For the foreseeable future, PWM and duty cycle will remain the lingua franca of servo control. Understanding them deeply gives you the ability to debug, optimize, and innovate beyond what library abstractions can offer.

Final Thoughts on Mastering Duty Cycle

The duty cycle is a small percentage—a sliver of time in a repeating waveform—but it carries immense power. It is the translator between the digital world of microcontrollers and the physical world of motion. For micro servo motors, mastering the duty cycle means mastering control over angle, speed, torque, and stability.

Whether you are fine-tuning a robotic gripper, building a weather station wind vane, or creating a lifelike animatronic eye, the principles outlined here will serve you. Remember to respect the narrow operating window (5% to 10%), maintain the correct frequency (50 Hz), and choose your hardware resolution wisely.

The next time you see a servo snap to attention with a crisp 90° turn, take a moment to appreciate the invisible dance of electrons that made it happen—a dance choreographed entirely by the duty cycle.

Copyright Statement:

Author: Micro Servo Motor

Link: https://microservomotor.com/pulse-width-modulation-pwm-control/duty-cycle-in-pwm-signals.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