3.4.1 CCP - Capture/Compare/PWM
3.4.1.1 Introduction
The Capture/Compare/PWM module is a peripheral that allows the user to time and control different events, and to generate Pulse-Width Modulation (PWM) signals. In Capture mode, the peripheral allows the timing of the duration of an event. The Compare mode allows the user to trigger an external event when a predetermined amount of time has expired. The PWM mode can generate Pulse-Width Modulated signals of varying frequency and duty cycle.
3.4.1.2 Supported Device Families
PIC12/16F161x | PIC16F151x | PIC16F152x |
PIC16F152xx | PIC16F153xx | PIC16F170x |
PIC16F171x | PIC16F171xx | PIC16F176x |
PIC16F177x | PIC16F178x | PIC16F180xx |
PIC16F181xx | PIC16F183x | PIC16F184xx |
PIC16F188xx | PIC16F191xx | PIC16F194x |
PIC18F-K20 | PIC18F-K22 | PIC18F-K40 |
PIC18F-K42 | PIC18F-K50 | PIC18F-K80 |
PIC18F-K83 | PIC18F-K90 | PIC18F-Q20 |
PIC18F-Q24 | PIC18F-Q40 | PIC18F-Q41 |
PIC18F-Q43 | PIC18F-Q71 | PIC18F-Q84 |
3.4.1.3 Required Header Files:
#include "mcc_generated_files/capture/ccp[x].h" or
#include "mcc_generated_files/compare/ccp[x].h" or
#include "mcc_generated_files/pwm/ccp[x].h"
3.4.1.4 Module Documentation
3.4.1.4.1 CAPTURE1
This file contains the API prototypes and other data types for the CCP1 module.
Module description
This file contains the API prototypes and other data types for the CCP1 module.
Data structures
union CCPR1_PERIOD_REG_T
Custom data type to hold the low byte, high byte, and 16-bit values of the period register.
Functions
void __interrupt (irq(CCP1), base(8))
Implements the ISR for capture interrupt when vectored interrupt is enabled.
void CCP1_Initialize (void)
Initializes the CCP1 module. This is called only once before calling other CCP1 APIs.
bool CCP1_IsCapturedDataReady (void)
Determines if the data capture is complete or not.
uint16_t CCP1_CaptureRead (void)
Reads the 16-bit capture value.
Function Documentation
__interrupt()
void __interrupt (irq(CCP1) , base(8) )
Implements the ISR for capture interrupt when vectored interrupt is enabled.
|
None. |
CCP1_CaptureRead()
uint16_t CCP1_CaptureRead (void )
Reads the 16-bit capture value.
CCP1_Initialize() and CCP1_IsCapturedDataReady() are already called. |
|
uint16_t - 16-bit captured value. |
CCP1_Initialize()
void CCP1_Initialize (void )
Initializes the CCP1 module. This is called only once before calling other CCP1 APIs.
Section: CCP1 Capture Module APIs
|
None. |
Section: Capture Module APIs
CCP1_IsCapturedDataReady()
bool CCP1_IsCapturedDataReady (void )
Determines if the data capture is complete or not.
CCP1_Initialize() is already called. |
|
|
3.4.1.4.2 COMPARE1
This file contains the API prototypes and other data types for the CCP1 module.
Module description
This file contains the API prototypes and other data types for the CCP1 module.
Data structures
union CCPR1_PERIOD_REG_T
Custom data type to hold the low byte, high byte, and 16-bit values of the period register.
Functions
void __interrupt (irq(CCP1), base(8))
Implements the ISR for compare interrupt when vectored interrupt is enabled.
void CCPx_Initialize (void)
Initializes the CCP1 module. This is called only once before calling other CCP1 APIs.
void CCPx_SetCompareCount (uint16_t compareCount)
Sets the 16-bit Compare value.
bool CCPx_OutputStatusGet (void)
Returns the Compare output status.
bool CCPx_IsCompareComplete (void)
Determines if the data comparison is complete or not.
Function Documentation
__interrupt()
void __interrupt (irq(CCP1) , base(8) )
Implements the ISR for compare interrupt when vectored interrupt is enabled.
|
None. |
CCPx_Initialize()
void CCPx_Initialize (void )
Initializes the CCP1 module. This is called only once before calling other CCP1 APIs.
Section: Compare Module APIs
|
None. |
Section: Included FilesSection: Compare Module APIs
Section: PWM1 Module APIs
CCPx_IsCompareComplete()
bool CCPx_IsCompareComplete (void )
Determines if the data comparison is complete or not.
CCPx_Initialize() is already called. |
|
|
CCPx_OutputStatusGet()
bool CCPx_OutputStatusGet (void )
Returns the Compare output status.
CCPx_Initialize() is already called. |
|
|
CCPx_SetCompareCount()
void CCPx_SetCompareCount (uint16_t compareCount)
Sets the 16-bit Compare value.
CCPx_Initialize() is already called. |
|
None. |
3.4.1.4.3 PWM1
This file contains the API prototypes for the PWM1 module.
Module description
This file contains the API prototypes for the PWM1 module.
Functions
void CCPx_Initialize (void)
Initializes the CCP1 module. This is called only once before calling other CCP1 APIs.
void CCPx_LoadDutyValue (uint16_t dutyValue)
Loads the 16-bit duty cycle value.
bool CCPx_OutputStatusGet (void)
Returns the PWM output status.
Function Documentation
CCPx_Initialize()
void CCPx_Initialize (void )
Initializes the CCP1 module. This is called only once before calling other CCP1 APIs.
Section: Included Files
|
None. |
Section: Included FilesSection: Compare Module APIs
Section: PWM1 Module APIs
CCPx_LoadDutyValue()
void CCPx_LoadDutyValue (uint16_t dutyValue)
Loads the 16-bit duty cycle value.
CCPx_Initialize() is already called. |
|
None. |
CCPx_OutputStatusGet()
bool CCPx_OutputStatusGet (void )
Returns the PWM output status.
CCPx_Initialize() is already called. |
|
|
Returns the PWM output status.
CCPx_Initialize() is already called. |
|
|
3.4.1.5 Class Documentation
3.4.1.5.1 CCPR1_PERIOD_REG_T Union Reference
Custom data type to hold the low byte, high byte, and 16-bit values of the period register.
Detailed Description
Custom data type to hold the low byte, high byte, and 16-bit values of the period register.
Section: Included FilesSection: Data Type Definition
#include <ccp1-capture.h>
The documentation for this union was generated from the following file:
source/
3.4.1.5.2 CCPR1Reg_tag Union Reference
#include <ccp1-capture.h>
Public Attributes
struct {
uint8_t ccpr1l
uint8_t ccpr1h
};
struct {
uint16_t ccpr1_16Bit
};
struct {
uint8_t ccpr1l
uint8_t ccpr1h
};
struct {
uint16_t ccpr1_16Bit
};
Member Data Documentation
The documentation for this union was generated from the following files:
source/
source/
ccpr1_16Bit
uint16_t CCPR1Reg_tag::ccpr1_16Bit
CCPR1 16-bit.
ccpr1h
uint8_t CCPR1Reg_tag::ccpr1h
CCPR1H high byte.
ccpr1l
uint8_t CCPR1Reg_tag::ccpr1l
CCPR1L low byte.
3.4.1.6 File Documentation
3.4.1.6.1 source/ccp1-capture.c File Reference
#include <xc.h> #include "../ccp1.h" #include "../../system/interrupt.h"
Functions
void CCP1_Initialize (void)
Initializes the CCP1 module. This is called only once before calling other CCP1 APIs.
bool CCP1_IsCapturedDataReady (void)
Determines if the data capture is complete or not.
uint16_t CCP1_CaptureRead (void)
Reads the 16-bit capture value.
void __interrupt (irq(CCP1), base(8))
Implements the ISR for capture interrupt when vectored interrupt is enabled.
Variables
static void(* CCP1_CallBack )(uint16_t)
Variable Documentation
CCP1_CallBack
void(* CCP1_CallBack) (uint16_t)[static]
Section: Included Files
3.4.1.6.2 source/ccp1-capture.h File Reference
#include <xc.h> #include <stdint.h> #include <stdbool.h>
Data structures
union CCPR1Reg_tag
Functions
void CCP1_Initialize (void)
Initializes the CCP1 module. This is called only once before calling other CCP1 APIs.
bool CCP1_IsCapturedDataReady (void)
Determines if the data capture is complete or not.
uint16_t CCP1_CaptureRead (void)
Reads the 16-bit capture value.
Typedefs
typedef union CCPR1Reg_tag CCPR1_PERIOD_REG_T
Typedef Documentation
CCPR1_PERIOD_REG_T
typedef union CCPR1Reg_tag CCPR1_PERIOD_REG_T
3.4.1.6.3 source/ccp1-compare.c File Reference
#include <xc.h> #include "../ccp1.h" #include "../../system/interrupt.h"
Functions
void CCPx_Initialize (void)
Initializes the CCP1 module. This is called only once before calling other CCP1 APIs.
void CCPx_SetCompareCount (uint16_t compareCount)
Sets the 16-bit Compare value.
bool CCPx_OutputStatusGet (void)
Returns the Compare output status.
bool CCPx_IsCompareComplete (void)
Determines if the data comparison is complete or not.
void __interrupt (irq(CCP1), base(8))
Implements the ISR for compare interrupt when vectored interrupt is enabled.
3.4.1.6.4 source/ccp1-compare.h File Reference
#include <xc.h> #include <stdint.h> #include <stdbool.h>
Data structures
union CCPR1Reg_tag
Functions
void CCPx_Initialize (void)
Initializes the CCP1 module. This is called only once before calling other CCP1 APIs.
void CCPx_SetCompareCount (uint16_t compareCount)
Sets the 16-bit Compare value.
bool CCPx_OutputStatusGet (void)
Returns the Compare output status.
bool CCPx_IsCompareComplete (void)
Determines if the data comparison is complete or not.
Typedefs
typedef union CCPR1Reg_tag CCPR1_PERIOD_REG_T
Typedef Documentation
CCPR1_PERIOD_REG_T
typedef union CCPR1Reg_tag CCPR1_PERIOD_REG_T
3.4.1.6.5 source/ccp1-pwm.c File Reference
#include <xc.h> #include "../ccp1.h"
Functions
void CCPx_Initialize (void)
Initializes the CCP1 module. This is called only once before calling other CCP1 APIs.
void CCPx_LoadDutyValue (uint16_t dutyValue)
Loads the 16-bit duty cycle value.
bool CCPx_OutputStatusGet (void)
Returns the Compare output status.
Macros
#define PWM1_INITIALIZE_DUTY_VALUE 0
Macro Definition Documentation
PWM1_INITIALIZE_DUTY_VALUE
#define PWM1_INITIALIZE_DUTY_VALUE 0
Section: Included FilesSection: Macro Declarations
3.4.1.6.6 source/ccp1-pwm.h File Reference
#include <xc.h> #include <stdint.h> #include <stdbool.h>
Functions
void CCPx_Initialize (void)
Initializes the CCP1 module. This is called only once before calling other CCP1 APIs.
void CCPx_LoadDutyValue (uint16_t dutyValue)
Loads the 16-bit duty cycle value.
bool CCPx_OutputStatusGet (void)
Returns the PWM output status.