Pulse width modulation, or PWM in embedded systems, controls the average power delivered to a load. It does this by switching a digital signal on and off very rapidly. Embedded developers across Bangalore and India rely on PWM to drive motors, dim LEDs, generate audio, and regulate power without expensive analog circuitry. At Microskill Lab Training Institute, our trainers teach PWM as a core skill because nearly every microcontroller project you build will use it. This guide explains how PWM works, walks through Arduino and ARM code, and shows the applications that matter most to working embedded engineers. By the end you will understand duty cycle, frequency, resolution, and how to configure timers on real hardware.
⚡ Key Takeaways
- You will understand how PWM controls power using duty cycle and frequency instead of variable voltage.
- You will learn to write PWM code for both Arduino and ARM Cortex-M microcontrollers.
- You will master the four core applications: motor control, LED dimming, power conversion, and signal generation.
- You will know how to select the right PWM frequency and resolution for your project.
- You will see how our hands-on curriculum builds job-ready embedded skills for the Bangalore hardware sector.
What Is PWM in Embedded Systems?
PWM in embedded systems is a method of encoding an analog value into a digital pulse train. Instead of producing a true analog voltage, the microcontroller rapidly toggles a pin between high and low. The proportion of time the signal stays high, called the duty cycle, determines the effective average voltage seen by the load.
Duty Cycle and Frequency Explained
Duty cycle is expressed as a percentage of the total period. A signal that is high for half of each cycle has a fifty percent duty cycle and delivers roughly half of full power. Frequency defines how many complete cycles occur per second, and choosing it correctly prevents visible flicker or audible whine in your application.
Why Developers Choose PWM
Embedded developers prefer PWM because it is efficient and cheap to implement. A switching transistor driven by PWM dissipates very little heat compared to a linear regulator handling the same load. Our trainers show students how this efficiency advantage drives its use across the automotive and IoT hardware companies clustered around Electronic City. Learners exploring this foundation benefit from our embedded systems training programme, which covers timers and PWM in depth.
How PWM Works Inside a Microcontroller
Every modern microcontroller generates PWM using dedicated timer peripherals rather than software loops. A timer counts up to a set value, and comparison registers decide when the output pin flips state. This hardware approach frees the CPU to run your main application logic while the signal continues uninterrupted.
Timers and Compare Registers
The timer holds a counter that increments with each clock tick until it reaches a top value, then resets. A compare register stores your target threshold, and whenever the counter passes it the output toggles. Adjusting this threshold changes the duty cycle without touching the frequency, which is exactly what smooth motor and LED control requires.
Resolution and Its Trade-offs
Resolution describes how many distinct duty cycle steps you can set, and it depends on the timer’s bit width and top value. An eight-bit timer gives you two hundred fifty-six steps, while a sixteen-bit timer offers far finer control. Higher resolution costs frequency, so our curriculum teaches students to balance the two based on real project needs. You can practise these trade-offs in our Arduino programming course with guided hardware labs.
PWM for Motor Control
Motor control is the most common industrial use of PWM, and it is heavily demanded by manufacturing firms across Karnataka and Tamil Nadu. By varying the duty cycle feeding a motor driver, you control speed smoothly from stop to full throttle. This approach wastes far less energy than older resistive speed controllers.
DC Motor Speed Regulation
A DC motor connected through an H-bridge responds directly to PWM duty cycle. A higher duty cycle delivers more average voltage and therefore higher speed and torque. Our trainers guide students through building a complete closed-loop speed controller as a capstone lab exercise.
Servo and BLDC Control
Servo motors read a specialised PWM signal where pulse width sets the shaft angle rather than average power. Brushless DC motors, common in drones and electric vehicles built by Bangalore startups, need synchronised PWM across three phases. Students who master these techniques through our PIC microcontroller programme become strong candidates for robotics roles.
Ready to build real embedded projects? Learn PWM, timers, and motor control hands-on with trainers who have shipped commercial hardware. Our Bangalore labs give you the practical experience employers want. Enrol in the Embedded Systems Pro Programme →
PWM for LED Dimming and Lighting
LED dimming is where most beginners first meet PWM, and it produces smooth brightness control invisible to the human eye. Because LEDs respond almost instantly to current, switching them thousands of times per second appears as steady dimmed light. This technique powers everything from smartphone screens to the smart lighting products designed in Whitefield.
Perceived Brightness and Gamma
Human vision perceives brightness non-linearly, so a fifty percent duty cycle does not look half as bright. Applying a gamma correction curve to your duty cycle values makes dimming feel smooth and natural. Our trainers teach this perceptual detail because it separates amateur projects from professional lighting products.
RGB and Colour Mixing
Driving red, green, and blue LEDs with three independent PWM channels lets you mix any colour. Adjusting each channel’s duty cycle shifts the resulting hue across the full spectrum. This principle underlies the addressable LED systems that Indian IoT product companies ship in large volumes.
Writing PWM Code on Arduino
Arduino makes PWM approachable, which is why our beginner students start here before moving to bare-metal ARM. The analogWrite function hides the timer complexity behind a single call. Understanding what happens underneath, however, is what makes you employable.
Using analogWrite
The analogWrite(pin, value) call accepts a duty cycle from zero to two hundred fifty-five on supported pins. A value of one hundred twenty-seven produces a roughly fifty percent duty cycle at the board’s default frequency. Our Arduino projects programme walks learners through dozens of these examples on real boards.
A minimal fade sketch shows how little code is required to get started:
int led = 9; // a PWM-capable pin
void setup() { pinMode(led, OUTPUT); }
void loop() {
for (int d = 0; d <= 255; d++) { analogWrite(led, d); delay(5); }
for (int d = 255; d >= 0; d--) { analogWrite(led, d); delay(5); }
}
Direct Timer Register Control
Once you outgrow analogWrite, you configure the ATmega timer registers directly for custom frequencies. Setting the waveform generation mode and prescaler bits gives you full command over the output signal. Our trainers demonstrate this transition so students understand both convenience and control.
Configuring Timer1 for fast PWM on pin nine looks like this in practice:
cppvoid setup() {
pinMode(9, OUTPUT);
TCCR1A = _BV(COM1A1) | _BV(WGM11); // non-inverting, mode 14
TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10);
ICR1 = 1599; // ~10 kHz top value
OCR1A = 800; // 50% duty cycle
}
Writing PWM Code on ARM Cortex-M
ARM Cortex-M microcontrollers dominate professional embedded work, and their timers are far more capable than an eight-bit Arduino. Configuring PWM here means working with the timer peripheral through vendor libraries or direct register access. This is the skill set that hardware companies in Manyata Tech Park actively hire for.
Configuring STM32 Timers
An STM32 timer is set up by selecting a prescaler, an auto-reload value, and a capture-compare channel. The auto-reload sets the period while the compare value sets the duty cycle. Our curriculum uses STM32 boards so students graduate with the exact experience listed in Bangalore embedded job postings.
CMSIS and HAL Approaches
Vendor HAL libraries speed up development, while CMSIS register access gives you tighter control and smaller code. Knowing both lets you read legacy firmware and still write optimised production code. Students deepen this through our embedded Linux development course when projects grow beyond bare metal.
Starting a PWM channel with the STM32 HAL takes only a couple of calls once the timer is configured:
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, 500); // set duty cycle
Choosing Frequency, Resolution, and Applications
Selecting the right PWM parameters is a design decision that depends entirely on your application. Motor drivers, LED dimmers, and power converters each demand different frequency ranges. Getting this wrong causes flicker, whine, or overheating in the field.
Application Frequency Guidelines
Different loads need different switching speeds to perform well. The table below summarises typical ranges our trainers recommend for common embedded tasks.
| Application | Typical PWM Frequency | Priority |
|---|---|---|
| DC motor control | 15–20 kHz | Silent operation above hearing range |
| LED dimming | 200 Hz–1 kHz | Flicker-free to the eye and cameras |
| Servo control | 50 Hz | Fixed standard pulse timing |
| Switching power supply | 100 kHz–1 MHz | Small components, high efficiency |
| Audio generation | 20 kHz+ | Above audible band for clean output |
Common Applications Summary
PWM appears in far more places than beginners expect once they start looking. The following list captures the applications our graduates encounter most in industry:
- Motor speed and direction control in robotics and appliances
- LED and display backlight dimming in consumer electronics
- DC-DC converters and switch-mode power supplies
- Servo positioning in automation and drones
- Audio tone and basic waveform synthesis
- Heating element and temperature regulation
Career prospects for these skills are strong across the region. Embedded developers in Bangalore earn roughly ₹4–8 LPA at entry level and ₹12–20 LPA with experience as of 2026. These figures are indicative only and should be verified against current market data before you rely on them.
Frequently Asked Questions
Is PWM an analog or digital signal?
PWM is fundamentally a digital signal that switches between two states. It only approximates an analog output when averaged over time by the load or a filter. This is why it works so efficiently on digital microcontrollers.
What frequency should I use for LED dimming?
A frequency between two hundred hertz and one kilohertz works well for most LED dimming. It stays above the flicker threshold for both human eyes and camera sensors. Higher frequencies are fine but rarely necessary for lighting.
Can any microcontroller pin output PWM?
No, only pins connected to a timer peripheral can generate hardware PWM. Other pins can produce software PWM, but it consumes CPU time and is less stable. Our trainers teach you to read the datasheet pin map to identify capable pins.
Do I need external components for PWM?
For simple LED dimming you often need only a current-limiting resistor. Motor and power applications require driver transistors or dedicated driver ICs to handle current. Our labs cover these driver circuits as part of the practical curriculum.
Ready to turn this knowledge into a career? Speak with our team about batch options and live projects through our enquiry page and start building real embedded hardware skills in Bangalore.