SlideShare uma empresa Scribd logo
1 de 16
Baixar para ler offline
Using Timer1/3/5 and the
Capture-Compare-PWM Circuit
Corrado Santoro
ARSLAB - Autonomous and Robotic Systems Laboratory
Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy
santoro@dmi.unict.it
L.A.P. 1 Course
Corrado Santoro Using Timer1/3/5 and CCP
The other timers of of PIC18
In addition to TIMER0, PIC18 Family has other 6 timers, subdivided in
two families
First family includes TIMER1, TIMER3 and TIMER5
Second family includes TIMER2, TIMER4 and TIMER6
Timers of the same family have the same structure and working scheme
Corrado Santoro Using Timer1/3/5 and CCP
The timers 1/3/5 of of PIC18
These timers are more versatile than the others and, therefore,
are a little bit more complex:
16-bit timers
Clock source selectable from:
FOSC
FOSC/4
External input
Secondary oscillator module
Prescaler with division by 1, 2, 4, 8;
Overflow (0xFFFF → 0) triggers an interrupt.
Gated timers, i.e. counting can be enabled by:
Bit TMRxON (as in other timers)
External input TxG
Specific event source coming from other peripherals
Corrado Santoro Using Timer1/3/5 and CCP
The timers 1/3/5 of of PIC18
Corrado Santoro Using Timer1/3/5 and CCP
Control Register of timers 1/3/5
TMRxCS: Clock source select
00, FOSC/4
01, FOSC
10 & TxSOSCEN = 0, External clock from TxCKI pin
11 & TxSOSCEN = 1, Clock from external crystal
TxCKPS: Prescaler setup
00 = 1:1 prescaler
01 = 1:2 prescaler
10 = 1:4 prescaler
11 = 1:8 prescaler
TxRD16: 16-bit R/W Operations
TMRxON: Timer On/Off control
Corrado Santoro Using Timer1/3/5 and CCP
Gate Control Register of timers 1/3/5
TMRxGE: Gate Enable bit
0, Gate is disabled
1, Gate is enabled and gate function is controlled by other bits
Corrado Santoro Using Timer1/3/5 and CCP
Interrupt flags of timers 1/3/5
Interrupt (overflow) flags of timers 1/3/5 belong to various
special function registers:
TMR1IF ⇒ PIR1bits.TMR1IF
TMR1IE ⇒ PIE1bits.TMR1IE
TMR3IF ⇒ PIR2bits.TMR3IF
TMR3IE ⇒ PIE2bits.TMR3IE
TMR5IF ⇒ PIR5bits.TMR5IF
TMR5IE ⇒ PIE5bits.TMR5IE
Corrado Santoro Using Timer1/3/5 and CCP
The Capture-Compare-PWM Circuit (CCP)
The CCP is a special circuit which performs certain signal manipulation
and measurement functions. It has 3 working modes:
Capture: at the occurrence of a pre-programmed edge in an input
signal, it takes a snapshot of the value of a timer
Compare: when the value of a timer matches a pre-programmed
constant, the circuit generates a specific output signal
PWM: it generates a PWM signal totally in hardware
Capture/Compare events can drive a proper interrupt
The 18F25K22 has 5 CCP modules
Each one can be programmed to work in one of the three modes above
Each CCP module has its specific input/output pin
Corrado Santoro Using Timer1/3/5 and CCP
Capture Mode
Input signal is taken from CCPx pin (which is multiplexed with a digital I/O port)
The edge detector is able to identify a falling- or rising-edge in the input signal,
according to the value of bits CCPxM (CCP Mode)
The programmable prescaler is able to identify each edge, each 4th edge or
each 16th edge
When the (programmed) edge is detected, the value of TIMER1/3/5 is copied
into the CCPRx register and (optionally) an interrupt is generated
All the process occurs in hardware
Corrado Santoro Using Timer1/3/5 and CCP
Compare Mode
CCPx pin acts as output
The software can program a value in the CCPRx register
When the value of TIMER1/3/5 matches the value in CCPRx one of the
following programmed events occurs:
The output is set to 0
The output is set to 1
The output is toggled (0 → 1, 1 → 0)
An optional interrupt is also generated
All the process occurs in hardware
Corrado Santoro Using Timer1/3/5 and CCP
PWM Mode
CCPx pin acts as output
One of the TIMER2/4/6 is used
The PWM period is programmed into the PRx register (timer period register)
The duty cycle is programmed into the CCPRx register
All the process occurs in hardware
Corrado Santoro Using Timer1/3/5 and CCP
CCP Control Register
DCxB: duty cycle bits 8 and 9 (used in PWM Mode)
CCPxM: CCP Mode
0000, circuit is off
0010, Compare mode, toggle output on match
1000, Compare mode, “set” output on match
1001, Compare mode, “clear” output on match
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
11xx, PWM mode
Corrado Santoro Using Timer1/3/5 and CCP
CCP Timer Selection
CCPTMRS0 and CCPTMRS1 registers are used to select the
timer to use in each CCP circuit.
CxTSEL: Timer selection
00, Capture/compare uses Timer1, PWM uses Timer2
01, Capture/compare uses Timer3, PWM uses Timer4
10, Capture/compare uses Timer5, PWM uses Timer6
Corrado Santoro Using Timer1/3/5 and CCP
Interrupt flags of CCP 1–5
Interrupt (event) flags of CCP circuits from 1 to 5 belong to
various special function registers:
CCP1IF ⇒ PIR1bits.CCP1IF
CCP1IE ⇒ PIE1bits.CCP1IE
CCP2IF ⇒ PIR2bits.CCP2IF
CCP2IE ⇒ PIE2bits.CCP2IE
CCP3IF ⇒ PIR4bits.CCP3IF
CCP3IE ⇒ PIE4bits.CCP3IE
CCP4IF ⇒ PIR4bits.CCP4IF
CCP4IE ⇒ PIE4bits.CCP4IE
CCP5IF ⇒ PIR4bits.CCP5IF
CCP5IE ⇒ PIE4bits.CCP5IE
Corrado Santoro Using Timer1/3/5 and CCP
CCP Circuit PIN Assignment in PIC18F25K22
CCP1 ⇒ RC2
CCP2 ⇒ RC1 or RB3 (settable through a configuration register)
CCP3 ⇒ RC6 or RB5 (settable through a configuration register)
CCP4 ⇒ RB0
CCP5 ⇒ RA4
Corrado Santoro Using Timer1/3/5 and CCP
Using Timer1/3/5 and the
Capture-Compare-PWM Circuit
Corrado Santoro
ARSLAB - Autonomous and Robotic Systems Laboratory
Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy
santoro@dmi.unict.it
L.A.P. 1 Course
Corrado Santoro Using Timer1/3/5 and CCP

Mais conteúdo relacionado

Mais procurados

PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programmingAkash Puri
 
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND CPIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C raosandy11
 
AVR_Course_Day7 timers counters and interrupt programming
AVR_Course_Day7 timers counters and  interrupt programmingAVR_Course_Day7 timers counters and  interrupt programming
AVR_Course_Day7 timers counters and interrupt programmingMohamed Ali
 
Timer & Interrupt Atmega16
Timer & Interrupt Atmega16Timer & Interrupt Atmega16
Timer & Interrupt Atmega16Ramadan Ramadan
 
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
AVR_Course_Day6 external hardware  interrupts and analogue to digital converterAVR_Course_Day6 external hardware  interrupts and analogue to digital converter
AVR_Course_Day6 external hardware interrupts and analogue to digital converterMohamed Ali
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051logesh waran
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / CountersPatricio Lima
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
Pt 51 kit - Peripheral self-test
Pt 51 kit - Peripheral self-testPt 51 kit - Peripheral self-test
Pt 51 kit - Peripheral self-testrajbabureliance
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and CountersShreyans Pathak
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counterankit3991
 

Mais procurados (20)

PIC timer programming
PIC timer programmingPIC timer programming
PIC timer programming
 
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND CPIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
PIC18 TIMER PROGRAMMING IN ASSEMBLY AND C
 
Class9
Class9Class9
Class9
 
AVR_Course_Day7 timers counters and interrupt programming
AVR_Course_Day7 timers counters and  interrupt programmingAVR_Course_Day7 timers counters and  interrupt programming
AVR_Course_Day7 timers counters and interrupt programming
 
Ec8791 lpc2148 timer unit
Ec8791 lpc2148 timer unitEc8791 lpc2148 timer unit
Ec8791 lpc2148 timer unit
 
Timer & Interrupt Atmega16
Timer & Interrupt Atmega16Timer & Interrupt Atmega16
Timer & Interrupt Atmega16
 
Avr timers
Avr timersAvr timers
Avr timers
 
9 timer programming
9 timer programming9 timer programming
9 timer programming
 
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
AVR_Course_Day6 external hardware  interrupts and analogue to digital converterAVR_Course_Day6 external hardware  interrupts and analogue to digital converter
AVR_Course_Day6 external hardware interrupts and analogue to digital converter
 
8051 ch9-950217
8051 ch9-9502178051 ch9-950217
8051 ch9-950217
 
Timers
TimersTimers
Timers
 
Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051Addressing mode and instruction set using 8051
Addressing mode and instruction set using 8051
 
Microcontroller part 3
Microcontroller part 3Microcontroller part 3
Microcontroller part 3
 
8051 Timers / Counters
8051 Timers / Counters8051 Timers / Counters
8051 Timers / Counters
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
Pt 51 kit - Peripheral self-test
Pt 51 kit - Peripheral self-testPt 51 kit - Peripheral self-test
Pt 51 kit - Peripheral self-test
 
microprocessors
microprocessorsmicroprocessors
microprocessors
 
8051 Timers and Counters
8051 Timers and Counters8051 Timers and Counters
8051 Timers and Counters
 
Lecture7
Lecture7Lecture7
Lecture7
 
8051 timer counter
8051 timer counter8051 timer counter
8051 timer counter
 

Destaque

Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converterCorrado Santoro
 
245521697 123529254-curso-microcontrolador-pic18f
245521697 123529254-curso-microcontrolador-pic18f245521697 123529254-curso-microcontrolador-pic18f
245521697 123529254-curso-microcontrolador-pic18fDaniel Henrique
 
Pulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsPulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsCorrado Santoro
 
How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...Corrado Santoro
 
Módulos ccp pic 16f887
Módulos ccp pic 16f887Módulos ccp pic 16f887
Módulos ccp pic 16f887whendygarcia
 

Destaque (7)

Analog to digital converter
Analog to digital converterAnalog to digital converter
Analog to digital converter
 
245521697 123529254-curso-microcontrolador-pic18f
245521697 123529254-curso-microcontrolador-pic18f245521697 123529254-curso-microcontrolador-pic18f
245521697 123529254-curso-microcontrolador-pic18f
 
Pulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUsPulse Width Modulation Signal Generation with MCUs
Pulse Width Modulation Signal Generation with MCUs
 
The I2C Interface
The I2C InterfaceThe I2C Interface
The I2C Interface
 
Quadcopter Technology
Quadcopter TechnologyQuadcopter Technology
Quadcopter Technology
 
How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...How does a Quadrotor fly? A journey from physics, mathematics, control system...
How does a Quadrotor fly? A journey from physics, mathematics, control system...
 
Módulos ccp pic 16f887
Módulos ccp pic 16f887Módulos ccp pic 16f887
Módulos ccp pic 16f887
 

Semelhante a Using Timer1 and CCP

Introduction to PIC18FX6J Series MCUs
Introduction to PIC18FX6J Series MCUsIntroduction to PIC18FX6J Series MCUs
Introduction to PIC18FX6J Series MCUsPremier Farnell
 
moving message display of lcd
 moving message display of lcd moving message display of lcd
moving message display of lcdabhishek upadhyay
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming IIOmar Sanchez
 
L15 timers-counters-in-atmega328 p
L15 timers-counters-in-atmega328 pL15 timers-counters-in-atmega328 p
L15 timers-counters-in-atmega328 prsamurti
 
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxUnit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxnaveen088888
 
EE6008 MCBSD - Introduction to PIC Micro controller
EE6008 MCBSD - Introduction to PIC Micro controller EE6008 MCBSD - Introduction to PIC Micro controller
EE6008 MCBSD - Introduction to PIC Micro controller pavihari
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptxSujalKumar73
 
Advanced Embedded Automatic Car Parking System
	Advanced Embedded Automatic Car Parking System	Advanced Embedded Automatic Car Parking System
Advanced Embedded Automatic Car Parking Systemtheijes
 
Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]gauravholani
 
What isn’t told about timers in stm32 application
What isn’t told about timers in stm32 applicationWhat isn’t told about timers in stm32 application
What isn’t told about timers in stm32 applicationOmar BOUZOURRAA
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Aarav Soni
 

Semelhante a Using Timer1 and CCP (20)

Introduction to PIC18FX6J Series MCUs
Introduction to PIC18FX6J Series MCUsIntroduction to PIC18FX6J Series MCUs
Introduction to PIC18FX6J Series MCUs
 
moving message display of lcd
 moving message display of lcd moving message display of lcd
moving message display of lcd
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
Assembly programming II
Assembly programming IIAssembly programming II
Assembly programming II
 
L15 timers-counters-in-atmega328 p
L15 timers-counters-in-atmega328 pL15 timers-counters-in-atmega328 p
L15 timers-counters-in-atmega328 p
 
Arduino 101
Arduino 101Arduino 101
Arduino 101
 
Timers and Endge-aligned PWM
Timers and Endge-aligned PWMTimers and Endge-aligned PWM
Timers and Endge-aligned PWM
 
Ee6008 mcbsd notes
Ee6008 mcbsd notesEe6008 mcbsd notes
Ee6008 mcbsd notes
 
Unit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptxUnit 3 timer and counter and there application .pptx
Unit 3 timer and counter and there application .pptx
 
EE6008 MCBSD - Introduction to PIC Micro controller
EE6008 MCBSD - Introduction to PIC Micro controller EE6008 MCBSD - Introduction to PIC Micro controller
EE6008 MCBSD - Introduction to PIC Micro controller
 
EE6008 MBSD
EE6008  MBSDEE6008  MBSD
EE6008 MBSD
 
timer counter (1).pptx
timer counter (1).pptxtimer counter (1).pptx
timer counter (1).pptx
 
8051e
8051e8051e
8051e
 
Advanced Embedded Automatic Car Parking System
	Advanced Embedded Automatic Car Parking System	Advanced Embedded Automatic Car Parking System
Advanced Embedded Automatic Car Parking System
 
Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]Pic microcontroller [autosaved] [autosaved]
Pic microcontroller [autosaved] [autosaved]
 
What isn’t told about timers in stm32 application
What isn’t told about timers in stm32 applicationWhat isn’t told about timers in stm32 application
What isn’t told about timers in stm32 application
 
Timers and pwm
Timers and pwmTimers and pwm
Timers and pwm
 
Lecture 2 timers, pwm, state machine IN PIC
Lecture 2   timers, pwm, state machine IN PIC Lecture 2   timers, pwm, state machine IN PIC
Lecture 2 timers, pwm, state machine IN PIC
 
Timer 2 concept
Timer 2 conceptTimer 2 concept
Timer 2 concept
 
Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)Timer counter in arm7(lpc2148)
Timer counter in arm7(lpc2148)
 

Mais de Corrado Santoro

Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Corrado Santoro
 
Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Corrado Santoro
 
Presentation @ WOA 2015
Presentation @ WOA 2015 Presentation @ WOA 2015
Presentation @ WOA 2015 Corrado Santoro
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scriptingCorrado Santoro
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerCorrado Santoro
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollersCorrado Santoro
 
Integrating Cloud Services in Behaviour Programming for Autonomous Robots
Integrating Cloud Services in Behaviour  Programming for Autonomous RobotsIntegrating Cloud Services in Behaviour  Programming for Autonomous Robots
Integrating Cloud Services in Behaviour Programming for Autonomous RobotsCorrado Santoro
 
Reactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA toolReactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA toolCorrado Santoro
 

Mais de Corrado Santoro (11)

Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
Physical Flying Agents: Ummanned Aerial Vehicles Control, Coordination and Em...
 
Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015Presentation @ Miniscuola WOA 2015
Presentation @ Miniscuola WOA 2015
 
Presentation @ WOA 2015
Presentation @ WOA 2015 Presentation @ WOA 2015
Presentation @ WOA 2015
 
Soc
SocSoc
Soc
 
Introduction to Erlang
Introduction to ErlangIntroduction to Erlang
Introduction to Erlang
 
Introduction to shell scripting
Introduction to shell scriptingIntroduction to shell scripting
Introduction to shell scripting
 
Pillole di C++
Pillole di C++Pillole di C++
Pillole di C++
 
Programming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontrollerProgramming the Digital I/O Interface of a PIC microcontroller
Programming the Digital I/O Interface of a PIC microcontroller
 
Introduction to microcontrollers
Introduction to microcontrollersIntroduction to microcontrollers
Introduction to microcontrollers
 
Integrating Cloud Services in Behaviour Programming for Autonomous Robots
Integrating Cloud Services in Behaviour  Programming for Autonomous RobotsIntegrating Cloud Services in Behaviour  Programming for Autonomous Robots
Integrating Cloud Services in Behaviour Programming for Autonomous Robots
 
Reactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA toolReactive Autonomous System Programming using the PROFETA tool
Reactive Autonomous System Programming using the PROFETA tool
 

Using Timer1 and CCP

  • 1. Using Timer1/3/5 and the Capture-Compare-PWM Circuit Corrado Santoro ARSLAB - Autonomous and Robotic Systems Laboratory Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy santoro@dmi.unict.it L.A.P. 1 Course Corrado Santoro Using Timer1/3/5 and CCP
  • 2. The other timers of of PIC18 In addition to TIMER0, PIC18 Family has other 6 timers, subdivided in two families First family includes TIMER1, TIMER3 and TIMER5 Second family includes TIMER2, TIMER4 and TIMER6 Timers of the same family have the same structure and working scheme Corrado Santoro Using Timer1/3/5 and CCP
  • 3. The timers 1/3/5 of of PIC18 These timers are more versatile than the others and, therefore, are a little bit more complex: 16-bit timers Clock source selectable from: FOSC FOSC/4 External input Secondary oscillator module Prescaler with division by 1, 2, 4, 8; Overflow (0xFFFF → 0) triggers an interrupt. Gated timers, i.e. counting can be enabled by: Bit TMRxON (as in other timers) External input TxG Specific event source coming from other peripherals Corrado Santoro Using Timer1/3/5 and CCP
  • 4. The timers 1/3/5 of of PIC18 Corrado Santoro Using Timer1/3/5 and CCP
  • 5. Control Register of timers 1/3/5 TMRxCS: Clock source select 00, FOSC/4 01, FOSC 10 & TxSOSCEN = 0, External clock from TxCKI pin 11 & TxSOSCEN = 1, Clock from external crystal TxCKPS: Prescaler setup 00 = 1:1 prescaler 01 = 1:2 prescaler 10 = 1:4 prescaler 11 = 1:8 prescaler TxRD16: 16-bit R/W Operations TMRxON: Timer On/Off control Corrado Santoro Using Timer1/3/5 and CCP
  • 6. Gate Control Register of timers 1/3/5 TMRxGE: Gate Enable bit 0, Gate is disabled 1, Gate is enabled and gate function is controlled by other bits Corrado Santoro Using Timer1/3/5 and CCP
  • 7. Interrupt flags of timers 1/3/5 Interrupt (overflow) flags of timers 1/3/5 belong to various special function registers: TMR1IF ⇒ PIR1bits.TMR1IF TMR1IE ⇒ PIE1bits.TMR1IE TMR3IF ⇒ PIR2bits.TMR3IF TMR3IE ⇒ PIE2bits.TMR3IE TMR5IF ⇒ PIR5bits.TMR5IF TMR5IE ⇒ PIE5bits.TMR5IE Corrado Santoro Using Timer1/3/5 and CCP
  • 8. The Capture-Compare-PWM Circuit (CCP) The CCP is a special circuit which performs certain signal manipulation and measurement functions. It has 3 working modes: Capture: at the occurrence of a pre-programmed edge in an input signal, it takes a snapshot of the value of a timer Compare: when the value of a timer matches a pre-programmed constant, the circuit generates a specific output signal PWM: it generates a PWM signal totally in hardware Capture/Compare events can drive a proper interrupt The 18F25K22 has 5 CCP modules Each one can be programmed to work in one of the three modes above Each CCP module has its specific input/output pin Corrado Santoro Using Timer1/3/5 and CCP
  • 9. Capture Mode Input signal is taken from CCPx pin (which is multiplexed with a digital I/O port) The edge detector is able to identify a falling- or rising-edge in the input signal, according to the value of bits CCPxM (CCP Mode) The programmable prescaler is able to identify each edge, each 4th edge or each 16th edge When the (programmed) edge is detected, the value of TIMER1/3/5 is copied into the CCPRx register and (optionally) an interrupt is generated All the process occurs in hardware Corrado Santoro Using Timer1/3/5 and CCP
  • 10. Compare Mode CCPx pin acts as output The software can program a value in the CCPRx register When the value of TIMER1/3/5 matches the value in CCPRx one of the following programmed events occurs: The output is set to 0 The output is set to 1 The output is toggled (0 → 1, 1 → 0) An optional interrupt is also generated All the process occurs in hardware Corrado Santoro Using Timer1/3/5 and CCP
  • 11. PWM Mode CCPx pin acts as output One of the TIMER2/4/6 is used The PWM period is programmed into the PRx register (timer period register) The duty cycle is programmed into the CCPRx register All the process occurs in hardware Corrado Santoro Using Timer1/3/5 and CCP
  • 12. CCP Control Register DCxB: duty cycle bits 8 and 9 (used in PWM Mode) CCPxM: CCP Mode 0000, circuit is off 0010, Compare mode, toggle output on match 1000, Compare mode, “set” output on match 1001, Compare mode, “clear” output on match 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 11xx, PWM mode Corrado Santoro Using Timer1/3/5 and CCP
  • 13. CCP Timer Selection CCPTMRS0 and CCPTMRS1 registers are used to select the timer to use in each CCP circuit. CxTSEL: Timer selection 00, Capture/compare uses Timer1, PWM uses Timer2 01, Capture/compare uses Timer3, PWM uses Timer4 10, Capture/compare uses Timer5, PWM uses Timer6 Corrado Santoro Using Timer1/3/5 and CCP
  • 14. Interrupt flags of CCP 1–5 Interrupt (event) flags of CCP circuits from 1 to 5 belong to various special function registers: CCP1IF ⇒ PIR1bits.CCP1IF CCP1IE ⇒ PIE1bits.CCP1IE CCP2IF ⇒ PIR2bits.CCP2IF CCP2IE ⇒ PIE2bits.CCP2IE CCP3IF ⇒ PIR4bits.CCP3IF CCP3IE ⇒ PIE4bits.CCP3IE CCP4IF ⇒ PIR4bits.CCP4IF CCP4IE ⇒ PIE4bits.CCP4IE CCP5IF ⇒ PIR4bits.CCP5IF CCP5IE ⇒ PIE4bits.CCP5IE Corrado Santoro Using Timer1/3/5 and CCP
  • 15. CCP Circuit PIN Assignment in PIC18F25K22 CCP1 ⇒ RC2 CCP2 ⇒ RC1 or RB3 (settable through a configuration register) CCP3 ⇒ RC6 or RB5 (settable through a configuration register) CCP4 ⇒ RB0 CCP5 ⇒ RA4 Corrado Santoro Using Timer1/3/5 and CCP
  • 16. Using Timer1/3/5 and the Capture-Compare-PWM Circuit Corrado Santoro ARSLAB - Autonomous and Robotic Systems Laboratory Dipartimento di Matematica e Informatica - Universit`a di Catania, Italy santoro@dmi.unict.it L.A.P. 1 Course Corrado Santoro Using Timer1/3/5 and CCP