Motor Control & PWM Techniques

iLabTek Team
April 2025
40 min read
Advanced

1. Introduction to Motor Control

Motor control refers to controlling:

  • Speed
  • Direction
  • Torque
  • Position
  • Acceleration

of electric motors using electronic circuits and embedded software.

Motor control systems are widely used in:

  • Robotics
  • Electric vehicles
  • Drones
  • CNC machines
  • Industrial automation
  • Smart appliances
  • Medical devices

2. Types of Motors

Different applications use different motor types.

Motor Type Applications
DC Motor Robots, toys, conveyors
Servo Motor Position control
Stepper Motor CNC, 3D printers
BLDC Motor Drones, EVs
AC Induction Motor Industrial systems

3. What is PWM?

PWM stands for Pulse Width Modulation.

PWM controls average voltage delivered to a motor by rapidly switching power ON and OFF.

Instead of changing analog voltage directly, PWM changes:

  • Pulse width
  • Duty cycle

4. PWM Fundamentals

PWM waveform consists of:

  • ON time
  • OFF time
  • Period
  • Frequency

PWM Duty Cycle

Duty cycle determines motor power.

Duty\ Cycle = \frac{T_{ON}}{T_{TOTAL}} \times 100\%

Where:

  • TON = ON duration
  • TTOTAL = Total PWM period
Duty Cycle Motor Speed
0% Motor OFF
25% Low speed
50% Medium speed
100% Full speed

5. PWM Frequency

PWM frequency affects:

  • Motor smoothness
  • Noise
  • Efficiency
  • Heating

Typical PWM frequencies:

Application Frequency
DC Motor 1–20 kHz
Servo Motor 50 Hz
BLDC Motor 10–50 kHz

6. PWM Generation in Microcontrollers

PWM is generated using hardware timers.

Popular PWM-capable MCUs:

  • STMicroelectronics STM32
  • Espressif Systems ESP32
  • Microchip Technology AVR/PIC
  • NXP Semiconductors LPC Series

7. PWM Using STM32 Timers

STM32 timers are widely used for PWM generation.

Features:

  • Multiple channels
  • Complementary outputs
  • Dead-time insertion
  • Center-aligned PWM
  • Encoder support

8. Basic PWM Generation Example (STM32 HAL)

Timer PWM Initialization

TIM_HandleTypeDef htim2; void MX_TIM2_Init(void) { TIM_OC_InitTypeDef sConfigOC = {0}; htim2.Instance = TIM2; htim2.Init.Prescaler = 83; htim2.Init.Period = 999; htim2.Init.CounterMode = TIM_COUNTERMODE_UP; HAL_TIM_PWM_Init(&htim2); sConfigOC.OCMode = TIM_OCMODE_PWM1; sConfigOC.Pulse = 500; HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_1); HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1); }

9. Understanding PWM Timer Calculation

PWM frequency formula:

PWM\ Frequency = \frac{Timer\ Clock}{(Prescaler+1)(Period+1)}

Duty Cycle Calculation

Duty\ Cycle = \frac{Pulse}{Period+1} \times 100\%

10. DC Motor Control

DC motors are commonly controlled using:

  • H-Bridge drivers
  • PWM speed control
  • Direction pins

Popular drivers:

  • L298N
  • BTS7960
  • DRV8871
  • TB6612FNG

11. H-Bridge Motor Driver

An H-Bridge controls:

  • Forward rotation
  • Reverse rotation
  • Braking
IN1 IN2 Motor Direction
1 0 Forward
0 1 Reverse
0 0 Stop
1 1 Brake

12. DC Motor PWM Speed Control Example

__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, 750);

This sets:

  • 75% duty cycle
  • Higher motor speed

13. Servo Motor Control

Servo motors use PWM pulses for angle control.

Typical servo signal:

Parameter Value
Frequency 50 Hz
Pulse Width 1–2 ms
Pulse Width Angle
1 ms
1.5 ms 90°
2 ms 180°

Servo PWM Example

__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, 75);

14. Stepper Motor Control

Stepper motors move in discrete steps.

Applications:

  • CNC machines
  • 3D printers
  • Robotics
  • Precision positioning

15. Stepper Motor Types

Type Description
Unipolar Simple control
Bipolar Higher torque

16. Stepper Motor Driving Methods

Method Feature
Full Step Maximum torque
Half Step Smoother movement
Microstepping High precision

17. BLDC Motor Control

BLDC motors are highly efficient and widely used in:

  • Drones
  • Electric vehicles
  • Industrial systems

Advantages:

  • High efficiency
  • Low maintenance
  • High speed
  • Long life

18. BLDC Motor Control Methods

  • Six-Step Commutation: Simple method using Hall sensors
  • Sensorless Control: Uses back-EMF detection
  • Field-Oriented Control (FOC): Advanced high-performance control technique

19. Field-Oriented Control (FOC)

FOC provides:

  • Smooth torque
  • High efficiency
  • Precise speed control

Used in:

  • EVs
  • Drones
  • Industrial robotics

FOC Mathematical Concept

FOC transforms motor currents into rotating reference frames.

Common transforms:

  • Clarke Transform
  • Park Transform

Clarke Transform

i_\alpha = i_a
i_\beta = \frac{1}{\sqrt{3}}(i_a + 2i_b)

Park Transform

i_d = i_\alpha \cos\theta + i_\beta \sin\theta
i_q = -i_\alpha \sin\theta + i_\beta \cos\theta

20. PID Motor Speed Control

PID control is widely used in motor systems.

PID stands for:

  • Proportional
  • Integral
  • Derivative

PID Control Equation

u(t) = K_p e(t) + K_i \int e(t)dt + K_d \frac{de(t)}{dt}

21. Motor Feedback Systems

Feedback devices include:

Sensor Purpose
Encoder Position/speed
Hall Sensor BLDC commutation
Current Sensor Torque/current
IMU Robot balancing

22. Encoder-Based Speed Control

Encoders provide pulses proportional to rotation.

Speed formula:

RPM = \frac{Pulses \times 60}{PPR \times Time}

23. PWM Dead Time

Dead time prevents shoot-through in MOSFET drivers.

Important in:

  • Inverters
  • BLDC drivers
  • Power electronics

24. Center-Aligned PWM

Advantages:

  • Reduced harmonics
  • Lower EMI
  • Better motor smoothness

Widely used in advanced motor control systems.

25. Current Control Techniques

Motor current control protects:

  • Motors
  • Drivers
  • Power supplies

Methods:

  • Current sensing resistor
  • Hall current sensor
  • Hardware comparators

26. Robotics Motor Control Applications

Motor control is essential in robotics.

Differential Drive Robots

Uses two independently controlled motors.

Applications:

  • Line followers
  • Autonomous robots

Robotic Arm Control

Uses:

  • Servo motors
  • Stepper motors
  • PID positioning

Drone Motor Control

Uses high-speed BLDC motors and ESCs.

27. PWM in Embedded Robotics

PWM controls:

  • Motor speed
  • LED brightness
  • Servo positioning
  • Audio generation

28. Real-Time Motor Control Challenges

Challenges include:

  • Timing precision
  • Interrupt latency
  • EMI noise
  • Thermal management
  • Power efficiency

29. Motor Driver Protection Features

Important protections:

Protection Purpose
Overcurrent Prevent damage
Thermal shutdown Avoid overheating
Undervoltage lockout Stable operation
Reverse polarity Hardware safety

30. Advanced Motor Control Features in STM32

Advanced timers support:

  • Complementary PWM
  • Dead-time insertion
  • Encoder mode
  • Break input
  • Synchronization

STM32 is widely used in industrial motor control applications.

31. ESP32 PWM Features

ESP32 provides LEDC PWM module.

Features:

  • Multiple channels
  • Variable resolution
  • High frequency support

ESP32 PWM Example

ledcSetup(0, 5000, 8); ledcAttachPin(18, 0); ledcWrite(0, 128);

32. Motor Control Communication Interfaces

Industrial motor systems often use:

  • CAN Bus
  • RS485
  • EtherCAT
  • Modbus
  • UART

33. AI and Smart Motor Control

Modern systems use AI for:

  • Predictive maintenance
  • Vibration analysis
  • Fault detection
  • Adaptive control

34. Industrial Applications

Factory Automation

  • Conveyor systems
  • CNC machines
  • Packaging systems

Automotive

  • Electric steering
  • EV traction motors
  • Cooling systems

Medical Devices

  • Surgical robots
  • Precision pumps

Consumer Electronics

  • Washing machines
  • Drones
  • Smart fans

35. Common Motor Control Problems

Problem Cause
Motor jitter Poor PWM timing
Overheating Excess current
Noise Wrong PWM frequency
Vibration PID tuning issue

36. Best Practices for Motor Control Design

  • Use hardware PWM
  • Add flyback diodes
  • Use proper grounding
  • Implement current limiting
  • Tune PID carefully
  • Use EMI filtering

37. Recommended Development Tools

Hardware

  • STM32 Discovery Boards
  • ESP32 Dev Boards
  • Motor Driver Modules
  • Oscilloscope
  • Logic Analyzer

Software

  • STM32CubeIDE
  • Keil MDK
  • Arduino IDE
  • MATLAB

Emerging trends:

  • AI-based control
  • Sensorless FOC
  • Wide-bandgap semiconductors
  • Smart predictive diagnostics
  • High-efficiency EV systems

39. Conclusion

PWM and motor control techniques form the foundation of modern robotics, industrial automation, electric vehicles, and embedded control systems.

By understanding:

  • PWM generation
  • H-Bridge control
  • PID algorithms
  • BLDC commutation
  • Field-Oriented Control (FOC)

developers can design advanced and efficient motor control systems.

Microcontrollers like STM32 and ESP32 provide powerful hardware peripherals that simplify implementation of real-time motor control applications.

Mastering these concepts enables engineers to build:

  • Autonomous robots
  • Smart industrial machines
  • Electric mobility systems
  • Precision automation platforms
  • High-performance embedded control systems
Next Steps

Ready to implement motor control in your project? Start with basic DC motor PWM control and gradually move to advanced BLDC FOC algorithms. Check out our STM32 GPIO tutorial for hardware setup basics.

+91 9773864270 /home/embchips/website/iLabTek/release-1.0.0/ilab-website/tutorial-motor-control-pwm.html