My firmware configures the MCU to go into suspend mode and wake whenever a CS0 greater than comparator event occurs. Why does the device sometimes get into a state where it does not wake from suspend when I know that a CS0 greater than comparator event has occurred?
Solution
The CS0 peripheral's comparator can be enabled and configured as both an interrupt source and a suspend mode wake-up source. To convert continuously while in suspend mode, firmware configures CS0 to convert continously in auto-scan mode by setting CS0CM in CS0CF to '111', sets a range of input pins to measure using CS0SS and CS0SE, configures and enables the greater than comparator in CS0CN, and enables the CS0 comparator as a wake-up source. After being properly configured, conversions begin when firmware writes '1' to CS0BUSY in CS0CN. After CS0BUSY has been set to one, the MCU can be placed into suspend mode by setting the SUSPEND bit (OSCICN's bit 5). Whenever a CS0 conversion output crosses the CS0 greater than comparator threshold, CS0 conversions are halted and hardware forces enabled interrputs and/or wake-up events.
If firmware configures hardware to go into suspend mode just as a completed CS0 conversion crosses the comparator threshold, that conversion is not considered by hardware to be a wake-up event because it completed while the MCU was still in an active state. In this case, because CS0 conversions have been halted, the CS0 peripheral is prohibited from acting as a wake-up source, and the device will go into a suspend state until the device is reset.
To prevent this behavior from occurring, firmware should be structured so that the MCU enters suspend mode before the first CS0 conversion can complete. This can be accomplished by placing the call to enter suspend mode immediately after the call to set CS0BUSY to '1'. If application requirements prohibit the system from going into suspend mode immediately after conversions start, the firmware designer must employ code profiling to ensure that the worst case (longest) time between the setting of CS0BUSY and the setting of SUSPEND is shorter than the specified minimum CS0 conversion time.
CS0 suspend wake-up events