Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

DEC5052

EMBEDDED SYSTEM APPLICATION

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

• We only focus with PWM operation of CCP module. Using this


we can generate PWM output having resolution up to 10 bit.
Output of CCP modules are multiplexed with RC1 & RC2 of
PORTC, hence TRISC1 and TRISC2 must be cleared to make
these pins output.
PWM
• The PWM feature allows us to create pulse with variable
width. The CCP module makes the programming of PWM
much easier and less tedious
• In creating pulse with variable width for the PWM, two factors
are important: The period of the pulse and its duty cycle.
• The duty cycle is the portion of pulse that stay HIGH relative
to entire period. Very often the duty cycle is stated in the
form of percentage.

Example: a pulse with a 4ms


period that stay HIGH for
1ms has duty cycle of 25%.
The period of PWM
• The CCP module uses Timer2 and its associated register, PR2
for the PWM time base, which means that the frequency of
the PWM is the fraction of the Fosc, the crystal frequency. It
uses the PR2 register to set the PWM period.
The duty cycle of PWM

You might also like