CAT2 Peripheral Driver Library
LPCOMP (Low Power Comparator)

Provides access to the low-power comparators implemented using the fixed-function low-power comparator block. More...

Modules

 Macros
 
 Functions
 
 Data Structures
 
 Enumerated Types
 

Detailed Description

Provides access to the low-power comparators implemented using the fixed-function low-power comparator block.

The functions and other declarations used in this driver are in cy_lpcomp.h. You can include cy_pdl.h to get access to all the functions and declarations in the PDL.

These comparators can perform fast analog signal comparison of external analog signals in all system power modes. The low-power comparator output can be inspected by the CPU, used as an interrupt/wakeup source to the CPU when in Low-power mode (Sleep or Deep Sleep) or fed to DSI as an asynchronous or synchronous signal (level or pulse).

Configuration Considerations

To set up a comparator, configure the inputs, output, mode, interrupts, and other configuration parameters.

1) Configure the inputs and the output using the GPIO API. The high-impedance Analog drive mode is for the inputs and Strong drive mode is for the output.

a. Connecting inputs using dedicated pins:

/* Positive input (inp) to the P0[0] */
Cy_GPIO_Pin_FastInit(GPIO_PRT0, 0, CY_GPIO_DM_ANALOG, 0, HSIOM_SEL_GPIO);
/* Negative input (inn) to the P0[1] */
Cy_GPIO_Pin_FastInit(GPIO_PRT0, 1, CY_GPIO_DM_ANALOG, 0, HSIOM_SEL_GPIO);
/* Compare Output (comp) to the P2[7] */
Cy_GPIO_Pin_FastInit(GPIO_PRT2, 7, CY_GPIO_DM_STRONG_IN_OFF, 0, HSIOM_SEL_GPIO);

b. Connecting low-power comparator's inputs using AMUXBUS:

/* LPCOMP_0: positive input (inp): connect P0[0] to AMUXBUSA */
Cy_GPIO_Pin_FastInit(GPIO_PRT0, 0, CY_GPIO_DM_ANALOG, 0, HSIOM_SEL_AMUXA);
/* LPCOMP_0: negative input (inn): connect P0[1] to AMUXBUSB */
Cy_GPIO_Pin_FastInit(GPIO_PRT0, 1, CY_GPIO_DM_ANALOG, 0, HSIOM_SEL_AMUXB);
/* LPCOMP_0: compare Output (comp) to the P2[7] */
Cy_GPIO_Pin_FastInit(GPIO_PRT2, 7, CY_GPIO_DM_STRONG_IN_OFF, 0, HSIOM_SEL_GPIO);
/* LPCOMP_1: positive input (inp): connect P0[2] to AMUXBUSA */
Cy_GPIO_Pin_FastInit(GPIO_PRT0, 2, CY_GPIO_DM_ANALOG, 0, HSIOM_SEL_AMUXA);
/* LPCOMP_1: negative input (inn): connect P0[3] to AMUXBUSB */
Cy_GPIO_Pin_FastInit(GPIO_PRT0, 3, CY_GPIO_DM_ANALOG, 0, HSIOM_SEL_AMUXB);
/* LPCOMP_1: compare Output (comp) to the P3[7] */
Cy_GPIO_Pin_FastInit(GPIO_PRT3, 7, CY_GPIO_DM_STRONG_IN_OFF, 0, HSIOM_SEL_GPIO);
Note
The pins assignment is for the PSOC 4100S Plus (CY8CKIT-149). The pin numbers may differ, please refer to the device documentation for the more details.

2) Initialize and enable the driver:

cy_stc_lpcomp_context_t lpcomp_context;
Cy_LPComp_Init(LPCOMP, CY_LPCOMP_CHANNEL_0, &lpcomp_cfg, &lpcomp_context);
Cy_LPComp_Enable(LPCOMP, CY_LPCOMP_CHANNEL_0, &lpcomp_context);

3) Configure the interrupt requests if the interrupt event triggering is needed. Additionally, enable the global interrupts and initialize the referenced interrupt by setting the priority and the interrupt vector using the SysInt (System Interrupt) driver API:

/* Enable global interrupts */
__enable_irq();
/* Configure LPComp interrupt */
Cy_SysInt_SetVector(lpcomp_interrupt_IRQn, lpcomp_isr);
NVIC_ClearPendingIRQ(lpcomp_interrupt_IRQn);
NVIC_EnableIRQ(lpcomp_interrupt_IRQn);

4) The comparator output can be monitored using the Cy_LPComp_GetCompare() function, using the comparator interrupt (if the interrupt is enabled) or using GPIO pin (if routed directly through the HSIOM).

Note
The interrupt is not cleared automatically - it is the user's responsibility. The interrupt is cleared by writing "1" in the corresponding interrupt-register bit-position. The preferred way to clear interrupt sources is using the Cy_LPComp_ClearInterrupt() function.
Individual comparator interrupt outputs are ORed together as a single asynchronous interrupt source before they are sent out and used to wake up the system in Low-power mode.

Low Power Support

The driver provides the callback functions to facilitate the Low-power mode transition. The callback Cy_LPComp_DeepSleepCallback must be called during the execution of Cy_SysPm_CpuEnterDeepSleep.

To trigger the callback execution, the callback must be registered before calling the mode transition function. Refer to SysPm (System Power Management) driver for more information about low-power mode transitions.

More Information

Refer to the appropriate device technical reference manual (TRM) for a detailed description of the registers.

Changelog

VersionChangesReason for Change
1.0.1 Update the paths to the code snippets. PDL structure update.
1.0 Initial version