Upload
amitk25
View
7
Download
0
Tags:
Embed Size (px)
DESCRIPTION
microcontroller
Citation preview
PIC Peripheral Interface Controllers
CCP and ECCP
programming
Amit Kulkarni
Objectives
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
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:
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.
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.
CCPxCON register
CCPxCON register contd..
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.
CCP pins: PIC18F4520 has 2 CCPs
Interaction for timer resources
� 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
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)
� 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.
T3CON register
T3CON register
Example
Compare mode steps for programming
Program 15-1
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
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.
PIR1 register
PIR1 register
Steps for capture mode programming
Program 15-2
Compare mode operation
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.
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.
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)
The period of PWM
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.
Set-up for PWM