---
import '../../styles/global.css';
---
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content={Astro.generator} />
<title>PWM Control API - PoKeys Core Library</title>
<style>
aside .sidebar-nav a {
display: block !important;
width: 100% !important;
}
aside .sidebar-nav {
display: flex !important;
flex-direction: column !important;
}
</style>
</head>
<body class="bg-gray-900 text-white">
<nav class="fixed top-0 left-0 right-0 z-50 bg-gray-900/80 backdrop-blur-md border-b border-gray-800 h-16">
<div class="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 h-full">
<div class="flex justify-between items-center h-full">
<a href="/core/" class="text-2xl font-bold bg-gradient-to-r from-blue-400 to-purple-500 bg-clip-text text-transparent">
PoKeys
</a>
<div class="hidden md:flex space-x-8">
<a href="/core/" class="text-gray-300 hover:text-white transition-colors">Home</a>
<a href="/core/getting-started" class="text-gray-300 hover:text-white transition-colors">Getting Started</a>
<a href="/core/examples/" class="text-gray-300 hover:text-white transition-colors">Examples</a>
<a href="/core/api/" class="text-white font-semibold">API Reference</a>
</div>
</div>
</div>
</nav>
<div class="flex min-h-screen pt-16">
<aside class="w-80 bg-gray-800/50 border-r border-gray-700 overflow-y-auto flex-shrink-0">
<div class="p-6">
<a href="/core/api/" class="text-blue-400 hover:text-blue-300 mb-4 inline-block">← Back to API Reference</a>
<h2 class="text-xl font-bold mb-6 text-white">API Reference</h2>
<div class="mb-6">
<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Core APIs</h3>
<div class="space-y-1 sidebar-nav">
<a href="/core/api/device" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Device Management
</a>
<a href="/core/api/connection" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Connection & Enumeration
</a>
<a href="/core/api/models" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Device Models
</a>
</div>
</div>
<div class="mb-6">
<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">I/O Operations</h3>
<div class="space-y-1 sidebar-nav">
<a href="/core/api/digital-io" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Digital I/O
</a>
<a href="/core/api/analog-io" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Analog I/O
</a>
<a href="/core/api/pin-functions" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Pin Functions
</a>
</div>
</div>
<div class="mb-6">
<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Control Systems</h3>
<div class="space-y-1 sidebar-nav">
<a href="/core/api/pwm" class="block px-3 py-2 text-white bg-gray-700/50 rounded-md transition-colors">
PWM Control
</a>
<a href="/core/api/encoders" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Encoders
</a>
<a href="/core/api/pulse-engine" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Pulse Engine v2
</a>
<a href="/core/api/servo-control" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Servo Control
</a>
</div>
</div>
<div class="mb-6">
<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Communication</h3>
<div class="space-y-1 sidebar-nav">
<a href="/core/api/spi" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
SPI Protocol
</a>
<a href="/core/api/i2c" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
I2C Protocol
</a>
<a href="/core/api/uart" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
UART Serial
</a>
<a href="/core/api/can" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
CAN Bus
</a>
<a href="/core/api/onewire" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
1-Wire Protocol
</a>
</div>
</div>
<div class="mb-6">
<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Matrix Operations</h3>
<div class="space-y-1 sidebar-nav">
<a href="/core/api/matrix-keyboard" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Matrix Keyboard
</a>
<a href="/core/api/led-matrix" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
LED Matrix
</a>
</div>
</div>
<div class="mb-6">
<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Display & Sensors</h3>
<div class="space-y-1 sidebar-nav">
<a href="/core/api/lcd" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
LCD Display
</a>
<a href="/core/api/sensors" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
EasySensors
</a>
<a href="/core/api/rtc" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Real-Time Clock
</a>
</div>
</div>
<div class="mb-6">
<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Error Handling</h3>
<div class="space-y-1 sidebar-nav">
<a href="/core/api/errors" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Error Types
</a>
<a href="/core/api/result-handling" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Result Handling
</a>
</div>
</div>
<div class="mb-6">
<h3 class="text-sm font-semibold text-gray-400 uppercase tracking-wider mb-3">Types & Utilities</h3>
<div class="space-y-1 sidebar-nav">
<a href="/core/api/types" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Core Types
</a>
<a href="/core/api/constants" class="block px-3 py-2 text-gray-300 hover:text-white hover:bg-gray-700/50 rounded-md transition-colors">
Constants
</a>
</div>
</div>
</div>
</aside>
<main class="flex-1 p-8 min-h-screen">
<div class="max-w-4xl">
<div class="mb-12">
<div class="flex items-center gap-4 mb-6">
<span class="px-3 py-1 bg-purple-600/20 text-purple-300 text-sm rounded-full">PWM Control</span>
</div>
<h1 class="text-4xl font-bold mb-4 bg-gradient-to-r from-purple-400 to-pink-500 bg-clip-text text-transparent">
PWM Control API
</h1>
<p class="text-xl text-gray-400">
High-precision PWM generation with 25MHz clock for servo positioning and motor control
</p>
</div>
<section class="mb-12">
<h2 class="text-2xl font-bold mb-4 text-white">Overview</h2>
<div class="bg-gray-800 rounded-lg p-6">
<p class="text-gray-300 mb-4">
The PWM Control API provides high-precision pulse width modulation with a 25MHz clock frequency.
This enables accurate servo control, LED dimming, and motor speed control with microsecond precision.
</p>
<div class="grid md:grid-cols-2 gap-6">
<div>
<h3 class="text-lg font-semibold mb-2 text-purple-400">Key Features</h3>
<ul class="text-gray-300 space-y-1 text-sm">
<li>• 25MHz clock precision (40ns resolution)</li>
<li>• 6 hardware PWM channels (pins 17-22)</li>
<li>• Servo control with position and speed modes</li>
<li>• Configurable period and duty cycle</li>
<li>• Percentage-based duty cycle control</li>
</ul>
</div>
<div>
<h3 class="text-lg font-semibold mb-2 text-blue-400">Supported Pins</h3>
<ul class="text-gray-300 space-y-1 text-sm font-mono">
<li>• Pin 17 - PWM Channel 0</li>
<li>• Pin 18 - PWM Channel 1</li>
<li>• Pin 19 - PWM Channel 2</li>
<li>• Pin 20 - PWM Channel 3</li>
<li>• Pin 21 - PWM Channel 4</li>
<li>• Pin 22 - PWM Channel 5</li>
</ul>
</div>
</div>
</div>
</section>
<section id="basic-pwm" class="mb-12">
<h2 class="text-2xl font-bold mb-6 text-white">Basic PWM Functions</h2>
<div class="bg-gray-800 rounded-lg p-6 mb-6">
<h3 class="text-xl font-semibold mb-4 text-purple-400">set_pwm_period</h3>
<div class="mb-4">
<pre class="bg-gray-900 rounded p-4 overflow-x-auto"><code class="text-gray-300">pub fn set_pwm_period(&mut self, period: u32) -> Result<()></code></pre>
</div>
<p class="text-gray-300 mb-4">
Sets the PWM period in clock cycles (25MHz clock). The period is shared across all PWM channels.
</p>
<div class="grid md:grid-cols-2 gap-4 mb-4">
<div>
<h4 class="font-semibold text-blue-400 mb-2">Parameters</h4>
<ul class="text-gray-300 text-sm space-y-1">
<li>• <code>period</code> - Period in 25MHz clock cycles</li>
</ul>
</div>
<div>
<h4 class="font-semibold text-green-400 mb-2">Common Values</h4>
<ul class="text-gray-300 text-sm space-y-1">
<li>• <code>500,000</code> - 20ms (servo control)</li>
<li>• <code>25,000</code> - 1ms (1kHz PWM)</li>
<li>• <code>2,500</code> - 0.1ms (10kHz PWM)</li>
</ul>
</div>
</div>
<div class="bg-gray-900 rounded p-4">
<h4 class="font-semibold text-yellow-400 mb-2">Example</h4>
<pre class="text-gray-300"><code>// Set 20ms period for servo control
device.set_pwm_period(500000)?;</code></pre>
</div>
</div>
<div class="bg-gray-800 rounded-lg p-6 mb-6">
<h3 class="text-xl font-semibold mb-4 text-purple-400">set_pwm_duty_cycle_for_pin</h3>
<div class="mb-4">
<pre class="bg-gray-900 rounded p-4 overflow-x-auto"><code class="text-gray-300">pub fn set_pwm_duty_cycle_for_pin(&mut self, pin: u8, duty: u32) -> Result<()></code></pre>
</div>
<p class="text-gray-300 mb-4">
Sets the PWM duty cycle for a specific pin in clock cycles.
</p>
<div class="grid md:grid-cols-2 gap-4 mb-4">
<div>
<h4 class="font-semibold text-blue-400 mb-2">Parameters</h4>
<ul class="text-gray-300 text-sm space-y-1">
<li>• <code>pin</code> - PWM pin number (17-22)</li>
<li>• <code>duty</code> - Duty cycle in clock cycles</li>
</ul>
</div>
<div>
<h4 class="font-semibold text-red-400 mb-2">Errors</h4>
<ul class="text-gray-300 text-sm space-y-1">
<li>• <code>PoKeysError::InvalidPin</code> - Pin not PWM capable</li>
<li>• <code>PoKeysError::Parameter</code> - Duty > period</li>
</ul>
</div>
</div>
<div class="bg-gray-900 rounded p-4">
<h4 class="font-semibold text-yellow-400 mb-2">Example</h4>
<pre class="text-gray-300"><code>// Set 1.5ms pulse width (servo center position)
device.set_pwm_duty_cycle_for_pin(22, 37500)?;</code></pre>
</div>
</div>
<div class="bg-gray-800 rounded-lg p-6 mb-6">
<h3 class="text-xl font-semibold mb-4 text-purple-400">enable_pwm_for_pin</h3>
<div class="mb-4">
<pre class="bg-gray-900 rounded p-4 overflow-x-auto"><code class="text-gray-300">pub fn enable_pwm_for_pin(&mut self, pin: u8, enabled: bool) -> Result<()></code></pre>
</div>
<p class="text-gray-300 mb-4">
Enables or disables PWM output for a specific pin.
</p>
<div class="bg-gray-900 rounded p-4">
<h4 class="font-semibold text-yellow-400 mb-2">Example</h4>
<pre class="text-gray-300"><code>// Enable PWM on pin 22
device.enable_pwm_for_pin(22, true)?;
// Disable PWM on pin 22
device.enable_pwm_for_pin(22, false)?;</code></pre>
</div>
</div>
<div class="bg-gray-800 rounded-lg p-6 mb-6">
<h3 class="text-xl font-semibold mb-4 text-purple-400">set_pwm_duty_cycle_percent_for_pin</h3>
<div class="mb-4">
<pre class="bg-gray-900 rounded p-4 overflow-x-auto"><code class="text-gray-300">pub fn set_pwm_duty_cycle_percent_for_pin(&mut self, pin: u8, percent: f32) -> Result<()></code></pre>
</div>
<p class="text-gray-300 mb-4">
Sets the PWM duty cycle as a percentage (0.0 to 100.0) for easier control.
</p>
<div class="bg-gray-900 rounded p-4">
<h4 class="font-semibold text-yellow-400 mb-2">Example</h4>
<pre class="text-gray-300"><code>// Set 50% duty cycle for LED dimming
device.set_pwm_duty_cycle_percent_for_pin(22, 50.0)?;</code></pre>
</div>
</div>
</section>
<section id="servo-control" class="mb-12">
<h2 class="text-2xl font-bold mb-6 text-white">Servo Control</h2>
<div class="bg-gray-800 rounded-lg p-6 mb-6">
<h3 class="text-xl font-semibold mb-4 text-purple-400">configure_servo</h3>
<div class="mb-4">
<pre class="bg-gray-900 rounded p-4 overflow-x-auto"><code class="text-gray-300">pub fn configure_servo(&mut self, config: ServoConfig) -> Result<()></code></pre>
</div>
<p class="text-gray-300 mb-4">
Configures a servo motor with the specified configuration. Automatically sets the PWM period to 20ms if not already set.
</p>
<div class="bg-gray-900 rounded p-4">
<h4 class="font-semibold text-yellow-400 mb-2">Example</h4>
<pre class="text-gray-300"><code>// Configure 180-degree servo on pin 22
let servo = ServoConfig::one_eighty(22, 25000, 50000);
device.configure_servo(servo)?;</code></pre>
</div>
</div>
<div class="bg-gray-800 rounded-lg p-6 mb-6">
<h3 class="text-xl font-semibold mb-4 text-purple-400">set_servo_angle</h3>
<div class="mb-4">
<pre class="bg-gray-900 rounded p-4 overflow-x-auto"><code class="text-gray-300">pub fn set_servo_angle(&mut self, config: &ServoConfig, angle: f32) -> Result<()></code></pre>
</div>
<p class="text-gray-300 mb-4">
Sets the servo to a specific angle. Range depends on servo type (0-180° or 0-360°).
</p>
<div class="bg-gray-900 rounded p-4">
<h4 class="font-semibold text-yellow-400 mb-2">Example</h4>
<pre class="text-gray-300"><code>// Move servo to 90 degrees
device.set_servo_angle(&servo_config, 90.0)?;</code></pre>
</div>
</div>
<div class="bg-gray-800 rounded-lg p-6 mb-6">
<h3 class="text-xl font-semibold mb-4 text-purple-400">set_servo_speed</h3>
<div class="mb-4">
<pre class="bg-gray-900 rounded p-4 overflow-x-auto"><code class="text-gray-300">pub fn set_servo_speed(&mut self, config: &ServoConfig, speed: f32) -> Result<()></code></pre>
</div>
<p class="text-gray-300 mb-4">
Sets the speed for continuous rotation servos. Range: -100.0 to 100.0 (negative = counterclockwise, positive = clockwise).
</p>
<div class="bg-gray-900 rounded p-4">
<h4 class="font-semibold text-yellow-400 mb-2">Example</h4>
<pre class="text-gray-300"><code>// Set 50% clockwise speed
device.set_servo_speed(&speed_servo_config, 50.0)?;</code></pre>
</div>
</div>
<div class="bg-gray-800 rounded-lg p-6 mb-6">
<h3 class="text-xl font-semibold mb-4 text-purple-400">stop_servo</h3>
<div class="mb-4">
<pre class="bg-gray-900 rounded p-4 overflow-x-auto"><code class="text-gray-300">pub fn stop_servo(&mut self, config: &ServoConfig) -> Result<()></code></pre>
</div>
<p class="text-gray-300 mb-4">
Stops a continuous rotation servo by setting it to the neutral position.
</p>
<div class="bg-gray-900 rounded p-4">
<h4 class="font-semibold text-yellow-400 mb-2">Example</h4>
<pre class="text-gray-300"><code>// Stop the servo
device.stop_servo(&speed_servo_config)?;</code></pre>
</div>
</div>
</section>
<section id="servo-config" class="mb-12">
<h2 class="text-2xl font-bold mb-6 text-white">ServoConfig API</h2>
<div class="bg-gray-800 rounded-lg p-6 mb-6">
<h3 class="text-xl font-semibold mb-4 text-purple-400">ServoConfig::one_eighty</h3>
<div class="mb-4">
<pre class="bg-gray-900 rounded p-4 overflow-x-auto"><code class="text-gray-300">pub fn one_eighty(pin: u8, pos_0: u32, pos_180: u32) -> Self</code></pre>
</div>
<p class="text-gray-300 mb-4">
Creates configuration for a standard 180-degree position servo.
</p>
<div class="grid md:grid-cols-2 gap-4 mb-4">
<div>
<h4 class="font-semibold text-blue-400 mb-2">Parameters</h4>
<ul class="text-gray-300 text-sm space-y-1">
<li>• <code>pin</code> - PWM pin number (17-22)</li>
<li>• <code>pos_0</code> - Duty cycle for 0° position</li>
<li>• <code>pos_180</code> - Duty cycle for 180° position</li>
</ul>
</div>
<div>
<h4 class="font-semibold text-green-400 mb-2">Typical Values</h4>
<ul class="text-gray-300 text-sm space-y-1">
<li>• <code>pos_0</code>: 25,000 (1ms)</li>
<li>• <code>pos_180</code>: 50,000 (2ms)</li>
</ul>
</div>
</div>
<div class="bg-gray-900 rounded p-4">
<h4 class="font-semibold text-yellow-400 mb-2">Example</h4>
<pre class="text-gray-300"><code>let servo = ServoConfig::one_eighty(22, 25000, 50000);</code></pre>
</div>
</div>
<div class="bg-gray-800 rounded-lg p-6 mb-6">
<h3 class="text-xl font-semibold mb-4 text-purple-400">ServoConfig::three_sixty_speed</h3>
<div class="mb-4">
<pre class="bg-gray-900 rounded p-4 overflow-x-auto"><code class="text-gray-300">pub fn three_sixty_speed(pin: u8, stop: u32, clockwise: u32, anti_clockwise: u32) -> Self</code></pre>
</div>
<p class="text-gray-300 mb-4">
Creates configuration for a continuous rotation speed servo.
</p>
<div class="grid md:grid-cols-2 gap-4 mb-4">
<div>
<h4 class="font-semibold text-blue-400 mb-2">Parameters</h4>
<ul class="text-gray-300 text-sm space-y-1">
<li>• <code>pin</code> - PWM pin number (17-22)</li>
<li>• <code>stop</code> - Duty cycle for stop position</li>
<li>• <code>clockwise</code> - Duty cycle for max clockwise</li>
<li>• <code>anti_clockwise</code> - Duty cycle for max counterclockwise</li>
</ul>
</div>
<div>
<h4 class="font-semibold text-green-400 mb-2">Typical Values</h4>
<ul class="text-gray-300 text-sm space-y-1">
<li>• <code>stop</code>: 37,500 (1.5ms)</li>
<li>• <code>clockwise</code>: 50,000 (2ms)</li>
<li>• <code>anti_clockwise</code>: 25,000 (1ms)</li>
</ul>
</div>
</div>
<div class="bg-gray-900 rounded p-4">
<h4 class="font-semibold text-yellow-400 mb-2">Example</h4>
<pre class="text-gray-300"><code>// Based on datasheet: Counterclockwise 1-1.5ms, Stop 1.5ms, Clockwise 1.5-2ms
let servo = ServoConfig::three_sixty_speed(21, 37500, 50000, 25000);</code></pre>
</div>
</div>
</section>
<section id="timing-calculations" class="mb-12">
<h2 class="text-2xl font-bold mb-6 text-white">Timing Calculations</h2>
<div class="bg-gray-800 rounded-lg p-6">
<p class="text-gray-300 mb-4">
The PoKeys PWM system operates at 25MHz, providing 40ns resolution. Here are common timing calculations:
</p>
<div class="grid md:grid-cols-2 gap-6">
<div>
<h3 class="text-lg font-semibold mb-2 text-blue-400">Time to Cycles</h3>
<ul class="text-gray-300 space-y-1 font-mono text-sm">
<li>• 1ms = 25,000 cycles</li>
<li>• 1.5ms = 37,500 cycles</li>
<li>• 2ms = 50,000 cycles</li>
<li>• 20ms = 500,000 cycles</li>
</ul>
</div>
<div>
<h3 class="text-lg font-semibold mb-2 text-purple-400">Formula</h3>
<div class="bg-gray-900 rounded p-3">
<code class="text-gray-300">cycles = time_ms × 25,000</code>
</div>
</div>
</div>
<div class="mt-6 bg-blue-900/20 border border-blue-500/30 rounded p-4">
<h4 class="text-blue-400 font-semibold mb-2">Servo Timing Standards</h4>
<ul class="text-gray-300 text-sm space-y-1">
<li>• <strong>Standard Servo:</strong> 1ms (0°) to 2ms (180°) with 20ms period</li>
<li>• <strong>Speed Servo:</strong> 1ms (full reverse) to 2ms (full forward), 1.5ms (stop)</li>
<li>• <strong>High-Resolution:</strong> Some servos use 0.5ms to 2.5ms range</li>
</ul>
</div>
</div>
</section>
<section id="advanced-features" class="mb-12">
<h2 class="text-2xl font-bold mb-6 text-white">Advanced Features</h2>
<div class="grid md:grid-cols-2 gap-6">
<div class="bg-gray-800 rounded-lg p-6">
<h3 class="text-lg font-semibold mb-3 text-green-400">Multi-Channel Control</h3>
<p class="text-gray-300 text-sm mb-3">
All 6 PWM channels share the same period but can have independent duty cycles and enable states.
</p>
<pre class="bg-gray-900 rounded p-3 text-xs"><code class="text-gray-300">// Control multiple servos
device.set_pwm_period(500000)?;
device.enable_pwm_for_pin(17, true)?;
device.enable_pwm_for_pin(18, true)?;
device.set_pwm_duty_cycle_for_pin(17, 25000)?;
device.set_pwm_duty_cycle_for_pin(18, 37500)?;</code></pre>
</div>
<div class="bg-gray-800 rounded-lg p-6">
<h3 class="text-lg font-semibold mb-3 text-yellow-400">Performance Optimization</h3>
<p class="text-gray-300 text-sm mb-3">
Use bulk updates when controlling multiple channels simultaneously for better performance.
</p>
<pre class="bg-gray-900 rounded p-3 text-xs"><code class="text-gray-300">// Batch update duty cycles
device.pwm.set_duty_cycle(0, 25000)?;
device.pwm.set_duty_cycle(1, 37500)?;
device.pwm.update_pwm_duty_values()?;</code></pre>
</div>
</div>
</section>
<section class="mb-12">
<h2 class="text-2xl font-bold mb-4 text-white">Best Practices</h2>
<div class="bg-gray-800 rounded-lg p-6">
<div class="space-y-4">
<div>
<h3 class="text-lg font-semibold mb-2 text-green-400">Servo Control</h3>
<ul class="text-gray-300 space-y-1 text-sm">
<li>• Always set PWM period to 500,000 cycles (20ms) for servo control</li>
<li>• Calibrate servo positions by testing actual movement ranges</li>
<li>• Use ServoConfig for type-safe servo operations</li>
<li>• Disable PWM when not in use to save power</li>
</ul>
</div>
<div>
<h3 class="text-lg font-semibold mb-2 text-blue-400">Performance</h3>
<ul class="text-gray-300 space-y-1 text-sm">
<li>• Use percentage-based control for LED dimming applications</li>
<li>• Batch duty cycle updates for smooth multi-servo animations</li>
<li>• Validate pin capabilities before PWM configuration</li>
</ul>
</div>
<div>
<h3 class="text-lg font-semibold mb-2 text-purple-400">Safety</h3>
<ul class="text-gray-300 space-y-1 text-sm">
<li>• Never exceed servo manufacturer's pulse width specifications</li>
<li>• Implement soft start/stop for mechanical systems</li>
<li>• Monitor servo current draw for overload protection</li>
</ul>
</div>
</div>
</div>
</section>
</div>
</main>
</div>
</body>
</html>