32
PIC Peripheral Interface Controllers CCP and ECCP programming Amit Kulkarni

PIC_12

Embed Size (px)

DESCRIPTION

microcontroller

Citation preview

Page 1: PIC_12

PIC Peripheral Interface Controllers

CCP and ECCP

programming

Amit Kulkarni

Page 2: PIC_12

Objectives

Page 3: PIC_12

CCP/ECCP/PWM Modules

� CCP: compare/capture module

� ECCP: Enhanced CCP

� PWM: Pulse width module

� Depending upon the family PIC18 may have

0 to 5 CCP modules.

� PWM is the feature of CCP

� CCP are enhanced in the recent years and

are termed as ECCP

Page 4: PIC_12

Number of CCP modules

� Depends on the PIC family

� A given family member can have 2 standard CCP

modules and 1 or more ECCPs.modules and 1 or more ECCPs.

� Following table lists the various CCPs and ECCPs:

Page 5: PIC_12

CCP programming

� PIC18 timers are used as follows:

� Usage of timers is different for different CCP

features.

� T3CON register is used to chose the timer for

CCP modes.

Page 6: PIC_12

CCP registers

� Each CCP has three registers associated

with it.

CCPxCON: 8-bit control register� CCPxCON: 8-bit control register

� CCPRxL and CCPRxH: Can be used as

– low and high byte of 16-bit register

– 16-bit compare register

– 16-bit capture resigter

– 8-bit duty cycle register by PWM.

** but not all at the same time.

Page 7: PIC_12

CCPxCON register

Page 8: PIC_12

CCPxCON register contd..

Page 9: PIC_12

CCPR1H and CCPR1L: data register

� CCP1 high and low byte registers

– low and high byte of 16-bit register

– 16-bit compare register

– 16-bit capture register

– 8-bit duty cycle register by PWM.

Page 10: PIC_12

CCP pins: PIC18F4520 has 2 CCPs

Page 11: PIC_12

Interaction for timer resources

Page 12: PIC_12

� This mode can be selected using the select

bit of CCPxCON register.

This mode can cause an event out side the

Compare mode programming

� This mode can cause an event out side the

controller such as turning on the device

connected to CCP pin, or starting the ADC

conversion.

� This happens when the TMR1 or TMR3

values matches with the CCPR1H and

CCPR1L

Page 13: PIC_12

Compare mode programming

� In Compare mode, the 16-bit CCPRx register

value is constantly compared against either

the TMR1 or TMR3 register pair value.the TMR1 or TMR3 register pair value.

� When a match occurs, the CCPx pin can be:

– driven high

– driven low

– toggled (high-to-low or low-to-high)

– remain unchanged (that is, reflects the state of

the I/O latch)

Page 14: PIC_12

� Notice for the above first 3 options CCP pin

must be configured as an output.

Once the match is detected the CCP1IF bit of

Compare mode programming

� Once the match is detected the CCP1IF bit of

PIR1 register is set.

� T3CON register is used to select TMR1 and

TMR3.

Page 15: PIC_12

T3CON register

Page 16: PIC_12

T3CON register

Page 17: PIC_12

Example

Page 18: PIC_12

Compare mode steps for programming

Page 19: PIC_12

Program 15-1

Page 20: PIC_12

Capture mode programming

� In Capture mode, the CCPRxH:CCPRxL

register pair captures the 16-bit value of the

TMR1 or TMR3 registers when an eventTMR1 or TMR3 registers when an event

occurs on the corresponding CCPx pin.

� An event is defined as one of the following:

– every falling edge

– every rising edge

– every 4th rising edge

– every 16th rising edge

Page 21: PIC_12

Capture mode programming

� The event is selected by the mode select

bits, CCPxM3:CCPxM0 (CCPxCON<3:0>).

When a capture is made, the interrupt� When a capture is made, the interrupt

request flag bit, CCPxIF, is set;

� It must be cleared in software. If another

capture occurs before the value in register

CCPRx is read, the old captured value is

overwritten by the new captured value.

Page 22: PIC_12

PIR1 register

Page 23: PIC_12

PIR1 register

Page 24: PIC_12

Steps for capture mode programming

Page 25: PIC_12

Program 15-2

Page 26: PIC_12

Compare mode operation

Page 27: PIC_12

PWM

� PWM: Pulse-width modulation (PWM), or pulse-

duration modulation(PDM), is a modulation

technique that conforms the width of the pulse,technique that conforms the width of the pulse,

formally the pulse duration, based on modulator

signal information.

� Its main use is to allow the control of the power

supplied to electrical devices, especially to inertial

loads such as motors.

Page 28: PIC_12

PWM mode

� Allows us to create pulses with variable

widths.

In Pulse Width Modulation (PWM) mode, the� In Pulse Width Modulation (PWM) mode, the

CCPx pin produces up to a 10-bit resolution

PWM output.

� Since the CCP2 pin is multiplexed with a

PORTB or PORTC data latch, the

appropriate TRIS bit must be cleared to

make the CCP2 pin an output.

Page 29: PIC_12

The period of PWM

� The CCP module uses Timer2 and its

associated registers, PR2 for PWM time

base.base.

� PR2 register is used to set the period of

PWM.

� Tosc=1/Fosc, N=pre-scaler(1,4 or 16)

Page 30: PIC_12

The period of PWM

Page 31: PIC_12

PWM duty cycle

� Duty cycle of PWM is the period of the pulse

for which it stays high relative to entire

period.period.

� To set the duty cycle CCP module uses 10-

bit register of DC1B9:DC1B0.

� Upper 8-bits come from CCPR1L and

remaining lower 2 bits come from CCP1CON

register.

Page 32: PIC_12

Set-up for PWM