Docsity

CCP Module for PIC18F4520-Embedded System Control-Lecture Slides, Slides of Embedded Control Systems

Toggle sidebar
bg1
2
CCP Module for PIC18F4520
zCompare/Capture/PWM modules
z2 Modules available (ECCP1 and CCP2)
zRegisters involved are
z16 bit CCPRx (CCPR1, CCPR2)
zCCPxCON(CCP1CON, CCP2CON)
CCP2CON Register
DCxB<1:0>: PWM Duty Cycle bit 1 and bit 0 for CCPx Module
Capture mode:
Unused.
Compare mode:
Unused.
PWM mode:
These bits are the two LSbs (bit 1 and bit 0) of the 10-bit PWM duty cycle. The eight MSbs
(
DCxB<9:2>
)
of the dut
y
c
y
cle are found in CCPRxL
76543 2 1 0
--- --- DCxB1 DCxB0 CCPxM3 CCPxM2 CCPxM1 CCPxM0
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16

Partial preview of the text

Download CCP Module for PIC18F4520-Embedded System Control-Lecture Slides and more Slides Embedded Control Systems in PDF only on Docsity!

CCP Module for PIC18F4520 z

Compare/Capture/PWM modules z 2 Modules available (ECCP1 and CCP2) z Registers involved are z 16 bit CCPRx (CCPR1, CCPR2) z CCPxCON(CCP1CON, CCP2CON) CCP2CON Register DCxB<1:0>: PWM Duty Cycle bit 1 and bit 0 for CCPx Module Capture mode: Unused. Compare mode: Unused. PWM mode: These bits are the two LSbs (bit 1 and bit 0) of the 10-bit PWM duty cycle. The eight MSbs 7 6 5 4 3 2 1 0



DCxB DCxB CCPxM CCPxM CCPxM CCPxM docsity.com

CCP2CON Register CCPxM<3:0>:

CCPx Module Mode Select bits 0000 = Capture/Compare/PWM disabled (resets CCPx module) 0001 = Reserved 0010 = Compare mode, toggle output on match (CCPxIF bit is set) 0011 = Reserved 0100 = Capture mode, every falling edge 0101 = Capture mode, every rising edge 0110 = Capture mode, every 4th rising edge 0111 = Capture mode, every 16th rising edge 1000 = Compare mode, initialize CCPx pin low; on compare match, force CCPx pin high (CCPxIF bit is set) 1001 = Compare mode, initialize CCPx pin high; on compare match, force CCPx pin low (CCPxIF bit is set) 1010 = Compare mode, generate software interrupt on compare match (CCPxIF bit is set, CCPx pin reflects I/O state) 1011 = Compare mode, trigger special event; reset timer; CCP2 match starts A/D conversion (CCPxIF bit is set) 11xx = PWM mode docsity.com

Capture Mode z

CCPRx register pair captures the 16-bit valueof the TMR1 or TMR3 register when an eventoccurs on the corresponding CCPx pin. z An event is defined as one of the following: z every falling edge z every rising edge z every 4th rising edge z every 16th rising edge docsity.com

Capture Mode Block Diagram

docsity.com

Compare Mode z

16-bit CCPRx register value is constantlycompared against either the TMR1 or TMR3register pair value. z When a match occurs, the CCPx pin can be: z Driven high z Driven low z Toggled (high-to-low or low-to-high) z Remain unchanged (that is, reflects the state ofthe I/O latch) docsity.com

SPECIAL EVENT TRIGGER z

Both CCP modules are equipped with aSpecial Event Trigger z Special Event Trigger resets the Timerregister pair. z The Special Event Trigger for CCP2 can alsostart an A/D conversion. docsity.com

Applications of Compare Mode z

Generation of a Single pulse z Generation of multiple pulses z A periodic waveform with a certain duty cycle z Specific time delay docsity.com

PWM Mode z

Create pulses with variable widths on CCP pin. z Two factors to be considered while creatingvariable pulses z Period of Pulse z Duty Cycle z Period of Pulse

T

pwm = [(PR2) +1] 4 x N x T osc PR2 =

[

F

osc

/ F

pwm x 4 x N)- docsity.com

PWM Operation z

The CCPRxL is loaded into CCPRxH and theCCPx Pin goes HIGH to start the period z TMR2 value is compared with both PR2 andCCPRxH registers. z The TMR2 and CCPRxH are same, CCP pinis forced to low to end the duty cycle z As TMR2 matches with PR2 register, CCPpin goes high to end one period docsity.com

PWM Block diagram

Period(PR2) Duty Cycle (CCPRxL) docsity.com

ECCP Module for 18F4520 z

Register Associated with ECCP Module CCP1CON Register 7 6 5 4 3 2 1 0 P1M P1M DCxB DCxB CCPxM CCPxM CCPxM CCPxM docsity.com

Enhanced PWM Block Diagram

docsity.com

Half Bridge Mode

docsity.com

Programmable Dead-Band Delay z

PWM1CON Register is used to set the Dead-BandDelay z Dead-Band Delay is provided in terms ofMicrocontroller Instruction Cycles PWM1CON Register 7 6 5 4 3 2 1 0 PRSEN PDC PDC PDC PDC PDC PDC PDC docsity.com