Top Banner
PIC16F887 PWM Lesson 13
20

PowerPoint Template

Apr 30, 2023

Download

Documents

Khang Minh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: PowerPoint Template

PIC16F887

PWM

Lesson 13

Page 2: PowerPoint Template

PIC16F887

PWM

Signals of varying frequency and duty cycle

have a wide range of application in automation.

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.

Page 3: PowerPoint Template

PIC16F887

PWM

Page 4: PowerPoint Template

PIC16F887

PWM

Page 5: PowerPoint Template

PIC16F887

PWM

The figure above shows the block diagram

of the CCP1 module set in PWM mode. In

order to generate a pulse of arbitrary form

on its output pin, it is necessary to set

pulse period (frequency) and pulse

duration.

Page 6: PowerPoint Template

PIC16F887

PWM PERIOD

The output pulse period (T) is

determined by the PR2 register of the

timer TMR2. The PWM period can be

calculated using the following equation:

Period=(PR2 +1) * 4Tosc * TMR2 Prescale

If the PWM period (T) is known, then it

is easy to determine the signal

frequency F because these two values

are related by equation F=1/T.

Page 7: PowerPoint Template

PIC16F887

PWM DUTY CYCLE

The PWM duty cycle is specified by using

in total of 10 bits: eight MSbs of the

CCPR1L register and two additional LSbs

of the CCP1CON register (DC1B1 and

DC1B0). The result is a 10-bit number

contained in the formula:

Pulse Width = (CCPR1L,DC1B1,DC1B0) *

Tosc * TMR2 Prescale Value

Page 8: PowerPoint Template

PIC16F887

PWM DUTY CYCLE

Page 9: PowerPoint Template

PIC16F887

PWM MAIN COMMANDS

setup_timer_2 (mode, period, postscale)Initializes timer 2 command with:

mode:T2_DISABLED : disable timer 2

T2_DIV_BY_1 : prescaler 1

T2_DIV_BY_4 : prescaler 4

T2_DIV_BY_16 : prescaler 16

Period: 0-255

determines when the clock value is reset

Postscale: 0-16

determines how many timer overflows

Page 10: PowerPoint Template

PIC16F887

PWM MAIN COMMANDS

setup_ccpX (CCP_PWM)

Set CCP to PWM mode with:

X: 1-2

determines which CCP used

Page 11: PowerPoint Template

PIC16F887

PWM MAIN COMMANDS

set_pwmX_duty (value)

Writes the 10-bit value to the PWM

to set the duty with:

X: 1-2

determines which CCP used

value: 10 bit number

Page 12: PowerPoint Template

PIC16F887

EXAMPLE

Control 24V DC motor speed by

PWM pulse with period = 0.8 ms

and duty cycle belong to the

voltage value read from variable

resistor connected to AN0.

Page 13: PowerPoint Template

PIC16F887

ANALYZE

Period=(PR2 +1) * 4Tosc * TMR2 Prescale

with period =0.8ms, fosc =20Mhz

Choose

TMR2 Prescale =16

PR2 = 249

Max duty cycle = (PR2+1)*4=1000

Page 14: PowerPoint Template

PIC16F887

L298

OPERATING SUPPLY VOLTAGE

UP TO 46 V .

TOTAL DC CURRENT UP TO 4 A .

LOW SATURATION VOLTAGE .

OVERTEMPERATURE

PROTECTION

LOGICAL "0" INPUT VOLTAGE

UP TO 1.5 V (HIGH NOISE

IMMUNITY)

Page 15: PowerPoint Template

PIC16F887

BLOCK DIAGRAM

Page 16: PowerPoint Template

PIC16F887

H-BRIDGE

Page 17: PowerPoint Template

PIC16F887

SCHEMATIC

Page 18: PowerPoint Template

PIC16F887

CODE

Page 19: PowerPoint Template

PIC16F887

Test the theory by simulink

Page 20: PowerPoint Template

PIC16F887

PWM

Lesson 13