Pulse Width Modulation (PWM) in Microcontroller Technology: A Comprehensive Guide, Lecture notes of Microcontrollers

Microcontroller is a best subject to learn. Feel free to explore them.

Typology: Lecture notes

2019/2020

Uploaded on 06/24/2020

unknown user
unknown user 🇲🇾

1 / 43

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
BEEZ 2404
Microcontroller Technology
Chapter 4: Pulse Width Modulation
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b

Partial preview of the text

Download Pulse Width Modulation (PWM) in Microcontroller Technology: A Comprehensive Guide and more Lecture notes Microcontrollers in PDF only on Docsity!

BEEZ 2404

Microcontroller Technology

Chapter 4: Pulse Width Modulation

At the end of the class, you will be able:

2

To understand the concept of PWM.

to understand the PWM module of PIC.

to identify important Specification/Features Motors.

What is PWM…?

4 Another example, common in practice, is the use of PWM signals in the circuit for generating signals of arbitrary waveforms such as sinusoidal waveform. See figure below:

What is PWM…?

5 A typical example is a power control circuit. Refer to figure below. ◦ If a logic zero ( 0 ) indicates the switch-off and a logic one ( 1 ) indicates the switch-on, the electrical power that load consumers will be directly proportional to the pulse duration. ◦ This ratio is often called Duty Cycle.

Example of duty cycle; Pulse time = 50 μs Period = 200 μs Duty cycle = 50 / 200 * 100 = 25 % Pulse time = 50μs

PWM Signal

Period = 200 μs

When the duty cycle is 25%, the speed of the motor is actually

25% of the full speed

Average voltage (area under graph)

= (5 V *50μs)/ 200μs

= 1.25 Volts or 25% full speed

Amplitude = 5 Volts Period = 200 μs Pulse time = 50 μs

PWM Signal

PWM module in the 16F877A is accessed through CCP module

( Capture/Compare/PWM )

Two PWM outputs are available from the CCP1 and CCP2 modules,

i.e. two PWM sources to external devices, DC motor drivers

PWM Module in PIC

CCP pins are multiplexed with PORTC, thus TRISC<1>, TRISC<2>

must be cleared

PWM freq which can be set

TRISC = 0b

PWM Module in PIC

PWM Module in PIC

13 PIC16F877A microcontroller has two independent CCP(Capture/Compare/PWM) modules, named as CCP1 and CCP2. Each CCP module has two 8-bit resistors(CCPxH,CCPxL) that can be use as:  16 bit Capture Register  16 bit Compare Register  10 - bit PWM Register. PWM frequency is limited from the PR 2 (Timer 2 module has an 8 - bit period register) register value. PR 2 value is limited from 0 to 255 only.

PWM Period is affected by three values;

  1. PR2 register,
  2. TMR2 prescale value
  3. Tosc

PR2  8 bit register that limits the period of the PWM

TMR2 prescaler  scale the output, from 1:1until 1:

Tosc  1/oscillator frequency

PWM Module in PIC ( Period )

PWM period = [(PR2)+1] * 4 * Tosc * (TMR2 prescaler)

PWM Module in PIC ( Period )

16 For 20MHz oscillator frequency: From above table, you can know available PWM frequency from Prescaler value. You should decide PR2 value and prescaler value at this point.

PWM Module in PIC ( Period )

17 As example, please calculate PR2 value for the following table shows how to generate PWM signals of varying frequency if the microcontroller uses 20MHz quartz-crystal.

PWM Signal (Duty Cycle)

19 Let say for PWM frequency=2kHz, Prescale = 16, OSC frequency = 20MHz: TO CALCULATE IN CLASS!!!! IMPORTANT

  1. PR2 value is required to CALCULATE PWM PERIOD
  2. CCPRxL:CCPxCON<5:4> is required to DETERMINE DUTY CYCLE

PWM Signal (Duty Cycle)

20 Example (ONLY USE 8BIT CCPR1L)