3.7 CMP - Comparator

3.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.

3.7.2 Supported Device Families

PIC12/16F150xPIC12/16F157xPIC12/16F161x
PIC12/16F184xPIC16F145xPIC16F153xx
PIC16F170xPIC16F171xPIC16F171xx
PIC16F176xPIC16F177xPIC16F178x
PIC16F180xxPIC16F181xxPIC16F183xx
PIC16F184xxPIC16F188xxPIC16F191xx
PIC16F194xPIC18F-K20PIC18F-K22
PIC18F-K40PIC18F-K42PIC18F-K50
PIC18F-K80PIC18F-K83PIC18F-K90
PIC18F-Q10PIC18F-Q24PIC18F-Q40
PIC18F-Q41PIC18F-Q43PIC18F-Q71
PIC18F-Q83PIC18F-Q84

3.7.3 Required header files:

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

3.7.4 Module Documentation

3.7.4.1 CMP1

This file contains the API prototypes for the CMP1 module.

3.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.

3.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.

3.7.5 File Documentation

3.7.5.1 source/cmp1.c File Reference

This file contains the API implementation for the CMP1 driver.

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

3.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.

3.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

3.7.5.2 source/cmp1.h File Reference

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

3.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.

3.7.5.2.2 Detailed Description

CMP1 Generated Driver API Header File.