4.7 CMP - Comparator

4.7.1 Introduction

The MPLAB® Code Configurator (MCC) Melody Comparator Peripheral Library (PLIBs) drivers generates APIs to support CMP-specific peripheral functionality on target MCUs.

The Comparator (CMP) is used to interface analog circuits to a digital circuit by comparing two analog voltages and providing a digital indication of their relative magnitudes. Comparators are very useful mixed signal building blocks because they provide analog functionality independent of program execution.

4.7.2 Supported Device Families

PIC12/16F150x PIC12/16F157x PIC12/16F161x
PIC12/16F184x PIC16F145x PIC16F153xx
PIC16F170x PIC16F171x PIC16F171xx
PIC16F176x PIC16F177x PIC16F178x
PIC16F180xx PIC16F181xx PIC16F183xx
PIC16F184xx PIC16F188xx PIC16F191xx
PIC16F194x PIC18F-K20 PIC18F-K22
PIC18F-K40 PIC18F-K42 PIC18F-K50
PIC18F-K80 PIC18F-K83 PIC18F-K90
PIC18F-Q10 PIC18F-Q24 PIC18F-Q40
PIC18F-Q41 PIC18F-Q43 PIC18F-Q71
PIC18F-Q83 PIC18F-Q84

4.7.3 Required header files:

#include "mcc_generated_files/comparator/cmp[x].h"
Note: Replace [X] with instance number of selected CMP module

4.7.4 Module Documentation

4.7.4.1 CMP1

This file contains the API prototypes for the CMP1 module.

4.7.4.1.1 Module description

This file contains the API prototypes for the CMP1 module.

Version: CMP1 Driver Version 2.12.0
Functions
  • void CMPx_Initialize (void)

    Initializes the CMP1 module. This is called only once during system initialization, and before calling other CMP1 APIs.

  • bool CMPx_GetOutputStatus (void)

    Returns the CMP1 output status.

  • void CMPx_ISR (void)

    Implements the Interrupt Service Routine (ISR) for the CMP interrupt.

4.7.4.1.2 Function Documentation

CMPx_GetOutputStatus()

bool CMPx_GetOutputStatus (void )

Returns the CMP1 output status.

Precondition:

CMPx_Initialize() is already called.

Parameters:
None.
Return values:
True

- CMP1 output is high.

False

- CMP1 output is low.

CMPx_Initialize()

void CMPx_Initialize (void )

Initializes the CMP1 module. This is called only once during system initialization, and before calling other CMP1 APIs.

Section: Included FilesSection: CMP1 APIs

Parameters:
None.
Returns:

None.

Section: Included FilesSection: CMP1 APIs

CMPx_ISR()

void CMPx_ISR (void )

Implements the Interrupt Service Routine (ISR) for the CMP interrupt.

Parameters:
None.
Returns:

None.

4.7.5 File Documentation

4.7.5.1 source/cmp1.c File Reference

This file contains the API implementation for the CMP1 driver.

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

4.7.5.1.1 Functions

  • void CMPx_Initialize (void)

    Initializes the CMP1 module. This is called only once during system initialization, and before calling other CMP1 APIs.

  • bool CMPx_GetOutputStatus (void)

    Returns the CMP1 output status.

  • void CMPx_ISR (void)

    Implements the Interrupt Service Routine (ISR) for the CMP interrupt.

4.7.5.1.2 Detailed Description

This file contains the API implementation for the CMP1 driver.

CMP1 Generated Driver File.

Version: CMP1 Driver Version 2.12.0

4.7.5.2 source/cmp1.h File Reference

#include <stdint.h>
#include <stdbool.h>

4.7.5.2.1 Functions

  • void CMPx_Initialize (void)

    Initializes the CMP1 module. This is called only once during system initialization, and before calling other CMP1 APIs.

  • bool CMPx_GetOutputStatus (void)

    Returns the CMP1 output status.

  • void CMPx_ISR (void)

    Implements the Interrupt Service Routine (ISR) for the CMP interrupt.

4.7.5.2.2 Detailed Description

CMP1 Generated Driver API Header File.