Professional Documents
Culture Documents
TOPIC 5 - PWM
TOPIC 5 - PWM
TOPIC 5
HARDWARE INTERFACING
PULSE WIDTH
MODULATION
(PWM)
DC motor and speed control using
PWM
• The speed of the motor depends on the three factors
(a) load (b) voltage (c) current.
• For a given fixed load we can maintain a steady speed
by using a method called pulse width modulation
(PWM).
• By changing (modulating) the width of pulse applied to
the DC motor we can increase or decrease the amount
of power provided to the motor, thereby increasing or
decreasing the motor speed.
• Although the voltage has a fixed amplitude, it has a
variable duty cycle. That means the wider the pulse,
the higher the speed.
DC motor and speed control using
PWM
• PWM is so widely used in DC motor control that some
microcontroller come with the PWM circuitry embedded in
the chip.
• In such microcontroller, all we have to do is load the proper
register with the value of the high and low portion of the
desired pulse and the rest is taken care by the microcontroller.
DC Motor interface to control direction
with motor driver L293D
DC motor and speed control using
PWM
Example 1 Speed control using PWM
Example 1 Function InitPWM( )
cont.
Example 1 Function SetPWMDutyCycle ( )
cont.
Example 1
PWM1 = 100% duty cycle
PWM2 = 100% duty cycle
cont.
Example 1
PWM1 = 50% duty cycle
PWM2 = 50% duty cycle
cont.
Example 2 Based on example 1, write a C language program to simulate the forward-
reverse motor circuit (using motor driver) based on this condition;
Condition:
if the SW1 (RB0) is pressed, dc motor will move forward with 75% duty cycle
pulse
else if the SW2 (RB1) is pressed, dc motor will move backward with 75%
duty cycle pulse
else if the SW1 and SW2 are not pressed, dc motor will stop
Pulse Width Modulation (PWM)
• PWM is the one of the simple and most commonly used technique to
produce analog voltages from digital signals. It has a wide variety of
applications such as DC Motor Speed Control, Sine Wave Inverters,
Brightness control etc.
• PWM signals are ON – OFF signals (HIGH or LOW) (hence the name Pulse)
whose HIGH or ON duration is changed (hence Width Modulation) in
accordance with our requirements. The fraction of time period for which
the signal is ON to the total time period is termed as Duty Cycle.
• PWM waves can be easily generated using CCP modules available with
most of the PIC Microcontrollers. CCP stands for Capture / Compare /
PWM, which means that it can be used for Capture or Compare or PWM
operations
CCP – Compare/Capture/PWM
module
• Microchip’s PIC 16 microcontroller has two CCP modules,
named as CCP1 and CCP2. Each CCP module comprises of two
8 bit registers which can be operate as
– 16 bit Capture Register
– 16 bit Compare Register
– PWM Master / Slave Duty Cycle register