Provides access to low-power comparators implemented using the fixed-function, LP comparator block.
The functions and other declarations used in this driver are in the cy_lpcomp.h file. You can include the cy_pdl.h to get access to all functions and declarations in the PDL.
Such comparators can perform a fast analog signal comparison of internal and 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 in Low-power mode (Sleep, Low-power Sleep or Deep-Sleep), used as a wakeup source to system resources in Hibernate mode, or fed to DSI as an asynchronous or synchronous signal (level or pulse).
Configuration Considerations
To set up a low-power comparator, the inputs, output, mode, interrupts and the other configuration parameters are configured. Power the low-power comparator to start it operate.
The sequence recommended for the low-power comparator operation:
1) To initialize the driver, call the Cy_LPComp_Init() function providing the filled cy_stc_lpcomp_config_t structure, the low-power comparator channel number and the low-power comparator registers structure pointer.
2) Optionally, configure the interrupt requests if the interrupt event triggering is needed. Use the Cy_LPComp_SetInterruptMask() function with the parameter for the mask available in the configuration file. Additionally, enable the Global interrupts and initialize the referenced interrupt by setting the priority and the interrupt vector using the Cy_SysInt_Init() function of the sysint driver.
3) Configure the inputs and the output using the Cy_GPIO_Pin_Init() functions of the GPIO driver. High Impedance Analog drive mode is for the inputs and Strong drive mode - for the output. Use the Cy_LPComp_SetInputs() function to connect the comparator inputs to the dedicated IO pins or Vref:
4) Power on the comparator using the Cy_LPComp_Enable() function.
5) The comparator output can be monitored using the Cy_LPComp_GetCompare() function or using the low-power comparator interrupt (if the interrupt is enabled).
- Note
- The interrupt is not cleared automatically. It is the user's responsibility to do that. 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 it is sent out and used to wake up the system in the low-power mode. The individual comparator interrupt is masked by the INTR_MASK register. The masked result is captured in the INTR_MASKED register. Writing "1" to the INTR register bit will clear the interrupt.
Low Power Support
The low-power comparator provides callback functions to facilitate the low-power mode transition. Call Cy_LPComp_DeepSleepCallback during execution of Cy_SysPm_CpuEnterDeepSleep. Call Cy_LPComp_HibernateCallback during execution of Cy_SysPm_SystemEnterHibernate. To trigger callback execution, register the callback before calling the mode transition function. Refer to SysPm (System Power Management) driver for more information about low-power mode transition.
The example below shows the entering Hibernate mode. The positive low-power comparator input connects to the dedicated GPIO pin and the negative low-power comparator input connects to the local reference. The LED blinks twice after a device reset and goes into Hibernate mode. When the voltage on the positive input is greater than the local reference voltage (0.45V - 0.75V), the device wakes up and the LED starts blinking.
Section of declarations:
#define MYLPCOMP_HW LPCOMP
#define MYLPCOMP_CHANNEL CY_LPCOMP_CHANNEL_0
#define LED_RED_PORT GPIO_PRT0
#define LED_RED_PIN 3U
{
};
{
MYLPCOMP_HW,
NULL
};
{
0u,
&LPCompHibernateCallbackParams,
NULL,
NULL,
0
};
cy_en_lpcomp_out_t outputMode
The low-power comparator outputMode: Direct output, Synchronized output or Pulse output.
Definition: cy_lpcomp.h:329
The low-power comparator configuration structure.
Definition: cy_lpcomp.h:328
The low-power comparator context structure, used to improve thread-safe implementation of the PDL.
Definition: cy_lpcomp.h:345
@ CY_LPCOMP_MODE_ULP
The low-power comparator channel ULP mode.
Definition: cy_lpcomp.h:266
@ CY_LPCOMP_INTR_DISABLE
The low-power comparator interrupt is disabled, no interrupt will be detected.
Definition: cy_lpcomp.h:256
@ CY_LPCOMP_OUT_DIRECT
The low-power comparator Bypass mode, the direct output of a comparator.
Definition: cy_lpcomp.h:234
@ CY_LPCOMP_HYST_ENABLE
The low-power comparator enable hysteresis.
Definition: cy_lpcomp.h:242
cy_en_syspm_status_t Cy_LPComp_HibernateCallback(cy_stc_syspm_callback_params_t *callbackParams, cy_en_syspm_callback_mode_t mode)
This function checks the current low-power comparator power mode and disables the low-power comparato...
Definition: cy_lpcomp.c:658
@ CY_SYSPM_HIBERNATE
The Hibernate enum callback type.
Definition: cy_syspm.h:1389
The structure contains syspm callback parameters.
Definition: cy_syspm.h:1923
Structure with syspm callback configuration elements.
Definition: cy_syspm.h:1937
Section of application code:
if(Cy_SysPm_IoIsFrozen())
{
Cy_SysPm_IoUnfreeze();
}
(void)
Cy_LPComp_Init(MYLPCOMP_HW, MYLPCOMP_CHANNEL, &MYLPCOMP_config, &lpcomp_context);
for (uint32 i = 1UL; i <= 4UL; i++)
{
}
(void)Cy_SysPm_RegisterCallback(&LPCompHibernateCallback);
Cy_SysPm_SystemEnterHibernate();
#define CY_GPIO_DM_STRONG_IN_OFF
Strong Drive.
Definition: cy_gpio.h:512
__STATIC_FORCEINLINE void Cy_GPIO_Inv(GPIO_PRT_Type *base, uint32_t pinNum)
Set a pin output logic state to the inverse of the current output logic state.
Definition: cy_gpio.h:1249
__STATIC_INLINE void Cy_GPIO_SetDrivemode(GPIO_PRT_Type *base, uint32_t pinNum, uint32_t value)
Configures the pin output buffer drive mode and input buffer enable.
Definition: cy_gpio.h:1284
@ CY_LPCOMP_SW_LOCAL_VREF
The low-power comparator input connects to local VREF.
Definition: cy_lpcomp.h:277
@ CY_LPCOMP_SW_GPIO
The low-power comparator input connects to GPIO pin.
Definition: cy_lpcomp.h:276
cy_en_lpcomp_status_t Cy_LPComp_Init(LPCOMP_Type *base, cy_en_lpcomp_channel_t channel, const cy_stc_lpcomp_config_t *config, cy_stc_lpcomp_context_t *context)
This function initializes the low-power comparator and returns the status of the initialization.
Definition: cy_lpcomp.c:85
void Cy_LPComp_SetInputs(LPCOMP_Type *base, cy_en_lpcomp_channel_t channel, cy_en_lpcomp_inputs_t inputP, cy_en_lpcomp_inputs_t inputN)
Sets the comparator input sources.
Definition: cy_lpcomp.c:432
__STATIC_INLINE void Cy_LPComp_ConnectULPReference(LPCOMP_Type *base, cy_en_lpcomp_channel_t channel)
Connects the local reference generator output to the comparator negative input.
Definition: cy_lpcomp.h:700
__STATIC_INLINE void Cy_LPComp_UlpReferenceEnable(LPCOMP_Type *base)
Enables the local reference generator circuit to generate the local Vref and Ibias.
Definition: cy_lpcomp.h:485
void Cy_LPComp_Enable(LPCOMP_Type *base, cy_en_lpcomp_channel_t channel, cy_stc_lpcomp_context_t *context)
This function enables the low-power comparator and sets interrupt edge-detect and drive power modes.
Definition: cy_lpcomp.c:160
void Cy_SysLib_Delay(uint32_t milliseconds)
The function delays by the specified number of milliseconds.
Definition: cy_syslib.c:104
@ CY_SYSPM_HIBERNATE_LPCOMP0_HIGH
Wake on a high logic level for the LPComp0.
Definition: cy_syspm.h:1254
More Information
For a detailed description of the registers, refer to the appropriate device technical reference manual (TRM).