Implementing Pulse Width Modulation Using the PIC | ECE 480, Study notes of Principles of Theater Design

Material Type: Notes; Professor: Goodman; Class: Senior Design; Subject: Electrical & Computer Egr; University: Michigan State University; Term: Fall 2007;

Typology: Study notes

Pre 2010

Uploaded on 07/23/2009

koofers-user-4wu-1
koofers-user-4wu-1 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
Implementing Pulse Width Modulation using the PIC18F4520
Bryan Thomas
A35345102
October 28
th
, 2007
Keywords: Pulse Width Modulation, Voltage Levels, Duty Cycle, Analog Control
Table of Contents:
Abstract…………………Page 1
Introduction……………..Page 1
PWM Implementation……Page1
PWM Application…………Page 2
Summary………………….Page 3
Useful Figures…………….Page 3
References………………….Page 6
Abstract
The technique of pulse width modulation
(PWM) is used to regulate the output
voltage in a circuit. By changing the
duty cycle, the average output power can
be adjusted even though the output pulse
remains the same throughout the
different duty cycles. The uses of PWM
are many. For our project, PWM will be
implemented to create variable
frequencies to operate our speaker at.
One of the requirements of the sponsor
is that the frequency of the sound
coming from the base be different than
the frequency of the sound coming from
the ball. Keeping this in mind, we have
decided to make the frequency of the
base be under 1 kHz.
Introduction
Pulse width modulation is a technique
used to manipulate the average power
seen at a load. By using the formula*:
The average value of a waveform can be
calculated. By changing the length of
time in which the signal is considered
“high”, also known as the duty cycle, the
area under the signal can be
manipulated. Without changing the
period, changing the area under the
signal will thereby change the average
value of the signal during one period.
The microcontroller that we are using,
the PIC18F4520, comes with an onboard
PWM module. Using this module and
the appropriate registers, we will be able
to manipulate our signal going to the
speaker using PWM.
PWM Implementation
To properly implement PWM into our
design, a reference of the PIC18F4520
datasheet had to be made**. Upon
pf3
pf4
pf5

Partial preview of the text

Download Implementing Pulse Width Modulation Using the PIC | ECE 480 and more Study notes Principles of Theater Design in PDF only on Docsity!

Implementing Pulse Width Modulation using the PIC18F

Bryan Thomas A October 28th, 2007

Keywords: Pulse Width Modulation, Voltage Levels, Duty Cycle, Analog Control

Table of Contents:

Abstract…………………Page 1 Introduction……………..Page 1 PWM Implementation……Page PWM Application…………Page 2 Summary………………….Page 3 Useful Figures…………….Page 3 References………………….Page 6

Abstract

The technique of pulse width modulation (PWM) is used to regulate the output voltage in a circuit. By changing the duty cycle, the average output power can be adjusted even though the output pulse remains the same throughout the different duty cycles. The uses of PWM are many. For our project, PWM will be implemented to create variable frequencies to operate our speaker at. One of the requirements of the sponsor is that the frequency of the sound coming from the base be different than the frequency of the sound coming from the ball. Keeping this in mind, we have decided to make the frequency of the base be under 1 kHz.

Introduction

Pulse width modulation is a technique used to manipulate the average power seen at a load. By using the formula*:

The average value of a waveform can be calculated. By changing the length of time in which the signal is considered “high”, also known as the duty cycle, the area under the signal can be manipulated. Without changing the period, changing the area under the signal will thereby change the average value of the signal during one period. The microcontroller that we are using, the PIC18F4520, comes with an onboard PWM module. Using this module and the appropriate registers, we will be able to manipulate our signal going to the speaker using PWM.

PWM Implementation

To properly implement PWM into our design, a reference of the PIC18F datasheet had to be made**. Upon

viewing the block diagram of the PWM module:

It can be seen that the PWM relies upon the comparison between the CCPR registers (High/Low), TMR2 (Timer 2), and the PR2 register. CCPR1L and CCPR1H are the two registers used to set the duty cycle. Additionally, the PWM duty cycle can also be manipulated by setting the Timer 2 prescaler bits. The formula, specific to the PIC18F4520, for the duty cycle is as follows:

Another aspect of the PWM module which must be taken into consideration is the period of the signal. Similarly to the duty cycle calculation, the calculation for signal period relies on the PR2 register, Timer 2 prescaler value, and the period of the oscillator (Tosc). The formula for the PWM period is as follows:

Using the PWM period, taking the inverse will give you the frequency of your signal.

In order to properly utilize the PWM module on the PIC18F4520, the following steps should be taken:

  1. Configure the period of the PWM by writing the appropriate value to the PR2 register
  2. Configure the duty cycle of the PWM by writing the appropriate value to the CCP1CON<5:4> bits as well as the CCPR1L register (and possibly the CCPR1H register if necessary)
  3. Set the CCP1 pin as an output by manipulating the appropriate TRIS register
  4. Set the Timer 2 prescale value
  5. Enable Timer 2 by writing to the T2CON register
  6. Write to the CCP1 register to enable PWM operation

PWM Application

PWM can be used in a variety of settings. Looking at Figure 3, we can see a generic load being driven by PWM output from a PIC microcontroller. In our specific case, we will be driving the Piezo buzzer with one of the four PWM outputs on the 18F4520. As you can see by looking at Figure 6, we have chosen to drive the Piezo element using port P1C. In most applications, the PIC will probably not be able to source enough current to power a load. When this is the case, a transistor can be placed in between the PIC output pin and the load in order to boost the current. For our setup, the 18F4520 can source up to

Figure 3: Example circuit: Full bridge output with 4 PWM outputs

from PIC driving the load

Figure 4: Direction change with regards to the four PWM outputs

(possible operation: running a motor)

Figure 5: PWM Output pin locations on the PIC 18F

Figure 6: Our specific application of driving a Piezo buzzer with PWM