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/16F161xPIC16F151xPIC16F152x
PIC16F152xxPIC16F153xxPIC16F170x
PIC16F171xPIC16F171xxPIC16F176x
PIC16F177xPIC16F178xPIC16F180xx
PIC16F181xxPIC16F183xPIC16F184xx
PIC16F188xxPIC16F191xxPIC16F194x
PIC18F-K20PIC18F-K22PIC18F-K40
PIC18F-K42PIC18F-K50PIC18F-K80
PIC18F-K83PIC18F-K90PIC18F-Q20
PIC18F-Q24PIC18F-Q40PIC18F-Q41
PIC18F-Q43PIC18F-Q71PIC18F-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"
Note: Replace [X] with instance number of selected CCP module

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.

Version: CCP1 Driver Version 2.0.1
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.

Parameters:
None.
Returns:

None.

CCP1_CaptureRead()

uint16_t CCP1_CaptureRead (void )

Reads the 16-bit capture value.

Precondition:

CCP1_Initialize() and CCP1_IsCapturedDataReady() are already called.

Parameters:
None.
Returns:

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

Parameters:
None.
Returns:

None.

Section: Capture Module APIs

CCP1_IsCapturedDataReady()

bool CCP1_IsCapturedDataReady (void )

Determines if the data capture is complete or not.

Precondition:

CCP1_Initialize() is already called.

Parameters:
None.
Return values:
True

- CCP1 data capture is complete.

False

- CCP1 data capture is not yet complete.

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.

Version: CCP1 Driver Version 2.0.1
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.

Parameters:
None.
Returns:

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

Parameters:
None.
Returns:

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.

Precondition:

CCPx_Initialize() is already called.

Parameters:
None.
Return values:
True

- CCP1 if data comparison is complete.

False

- CCP1 if data comparison is not yet complete.

CCPx_OutputStatusGet()

bool CCPx_OutputStatusGet (void )

Returns the Compare output status.

Precondition:

CCPx_Initialize() is already called.

Parameters:
None.
Return values:
True

- Compare output is high.

False

- Compare output is low.

CCPx_SetCompareCount()

void CCPx_SetCompareCount (uint16_t compareCount)

Sets the 16-bit Compare value.

Precondition:

CCPx_Initialize() is already called.

Parameters:
compareCount

- 16-bit unsigned value.

Returns:

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.

Version: PWM1 Driver Version 2.0.1
Functions

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

Parameters:
None.
Returns:

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.

Precondition:

CCPx_Initialize() is already called.

Parameters:
dutyValue

- 16-bit duty cycle value.

Returns:

None.

CCPx_OutputStatusGet()

bool CCPx_OutputStatusGet (void )

Returns the PWM output status.

Precondition:

CCPx_Initialize() is already called.

Parameters:
None.
Return values:
True

- CCP1 PWM output is high

False

- CCP1 PWM output is low

Returns the PWM output status.

Precondition:

CCPx_Initialize() is already called.

Parameters:
None.
Return values:
True

- Compare output is high.

False

- Compare output is low.

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/

ccp1-capture.h

3.4.1.5.2 CCPR1Reg_tag Union Reference

#include <ccp1-capture.h>

Member Data Documentation

The documentation for this union was generated from the following files:

source/

ccp1-capture.h

source/

ccp1-compare.h

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.

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>

Functions

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>

3.4.1.6.5 source/ccp1-pwm.c File Reference

#include <xc.h>
#include "../ccp1.h"

Functions

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