0% found this document useful (0 votes)
13 views37 pages

L15 PWM

Uploaded by

Sasindu Amesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views37 pages

L15 PWM

Uploaded by

Sasindu Amesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Pulse Width

Modulation(PWM)
Requirement for a PWM
• You want to control the DC motor speed
• Vary load
• Vary voltage
• Vary current

For a steady load we can vary speed using PWM.


PWM comparison
Refer to the figure in this example. Write a program to monitor the
status of the switch and perform the following.
a. If PORT.7 = 1, The DC motor moves with 25% duty cycle pulse
b. If PORT.7 = 0, The DC motor moves with 50% duty cycle pulse
Assume a function called DELAY is available
Waveform Generator of Mega32
Three modes of PWM available with Mega32

FAST PWM
PHASE CORRECT PWM Available with Timer1

PHASE AND FREQUENCY CORRECT PWM


FAST PWM

TCCR0 Register
FAST PWM – Non-inverted mode

Clear OC0 on compare match, set OC0 at TOP

OCR0 increasing => Duty cycle increases


FAST PWM – Inverted mode

Set OC0 on compare match, clear OC0 at TOP

OCR0 increasing => Duty cycle decreases


Frequency of the generated wave
Duty cycle of the generated wave
• Non inverted mode

• Inverted mode
Exercise 1
Exercise 2
Exercise 3
Exercise 4
Exercise 5
• Rewrite Exercise 4 using inverted mode
Phase correct PWM

TCCR0 Register
Phase correct PWM - non inverted mode

OC0 is cleared on compare


match when counting up and
set when counting down.
Phase correct PWM - Inverted mode

OC0 is set on compare match


when counting up and cleared
when counting down.
Frequency of the generated wave
Duty cycle of the generated wave
• Non inverted mode

• Inverted mode
Exercise 6
Exercise 7
Exercise 8
FAST PWM Vs Phase correct PWM

Vs

• Higher frequency – Fast as


name implies
• Phase is same for different
duty cycles – preferable to
• Phase is different for
drive motors
different duty cycles.
Using Timer2 for wave generation
• 8 bit timer, very similar to Timer0
• Register name, output port and prescale values are different
PWM modes in Timer1
TCCR1B
TCCR1A
Frequency of the generated wave – Fast PWM
Duty cycle of the generated wave – Fast PWM
• Non inverted mode

• Inverted mode
Exercise 9
Exercise 10
Timer1 – Options for frequency
Example application of PWM
PWM signals are generally used in embedded applications.
Motor control
Sound alarm
Radio transmission
To read
analogWrite(…) in Arduino
References
• Muhammad Ali Mazidi, Zarmad Naimi and Sepehr Naimi , AVR
Microcontroller and Embedded Systems using assembly and C,
Pearson Education, Publishing as Prentice Hall

You might also like