Provides access to low-power comparators implemented using the fixed-function, LP comparator block that is present in the CAT1A and CAT1D devices.
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).
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_Ext() 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, AMUXBUSA/AMUXBUSB or Vref:
4) Power on the comparator using the Cy_LPComp_Enable_Ext() 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).
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:
Section of application code:
For a detailed description of the registers, refer to the appropriate device technical reference manual (TRM).
Version | Changes | Reason for Change |
---|---|---|
1.70 | Added support for CAT1B and CAT1D devices. | Support of new IP version. |
1.60 | Fix in hibernate callback function. | The low power comparator was unable to wake-up the system from hibernate state. |
Documentation update and clarification. | The code snippet in chapter Low Power Support was updated after validation. | |
1.50 | Minor improvement in implementation of disabling functionality for the comparator. | Power drive mode for the comparator is restored to the level before disabling, instead of initial level. |
Documented MISRA C-2012 violation of the Rule 10.3. | MISRA C-2012 compliance. | |
1.40 | Introduced an extended versions of the existing functions with a pointer to the context structure allocated by the user: |
|
1.30 | Fixed/documented MISRA 2012 violations. | MISRA 2012 compliance. |
1.20.1 | Minor documentation updates. | Documentation enhancement. |
1.20 | Flattened the organization of the driver source code into the single source directory and the single include directory. | Driver library directory-structure simplification. |
Added register access layer. Use register access macros instead of direct register access using de-referenced pointers. | Makes register access device-independent, so that the PDL does not need to be recompiled for each supported part number. | |
1.10.1 | Added Low Power Callback section | Documentation update and clarification |
1.10 | The CY_WEAK keyword is removed from Cy_LPComp_DeepSleepCallback() and Cy_LPComp_HibernateCallback() functions Added input parameter validation to the API functions. | |
1.0 | Initial version |
API Reference | |
Macros | |
Functions | |
Data Structures | |
Enumerated Types | |