Using Comparator0 as a Wake-up Source for the C8051F960
09/265/2016 | 04:57 PM
Question
How do I use the Comparator0 (CMP0) as a wake-up source for the C8051F96x family of MCUs? In addition, I would like to route the Comparator output to a pin - is that possible in the low power modes SLEEP and SUSPEND?
Answer
To use the Comparator0 as a wake-up source from the low power modes of the C8051F96x devices, the following steps are required:
1) Firmware must configure the desired wake-up sources (Comparator0 in this case) and clear the wakeup flags in the PMU0CF and PMU0FL registers.
2) Enter the desired low power mode by writing a '1' to the SLEEP or SUSPEND bits in the PMU0CF register.
Attached to this article is an example project for the C8051F960-TB that demonstrates using the Comparator0 as a wakeup source for the device (F96x_SleepMode_ComparatorWake.zip). This code can be modified to put the device into SLEEP or SUSPEND mode.
To import this project into Simplicity Studio, follow these steps:
1) Do not unzip the file.
2) In the Simplicity Studio IDE, click [File] > [Import...]
3) Select [Existing Projects into Workspace] > [Next...]
4) Click [Select archive file] > [Browse...] and navigate to the location of the .zip file.
5) Select the .zip file and click [Open]
6) The project "F96x_SleepMode_ComparatorWake" and click [Finish]
As for routing the Comparator0 output to a port pin, it is possible to route either the latched/synchronous comparator output value (CP0) or the asynchronous output value (CP0A) to a port pin via the crossbar on the C8051F960. The code necessary to do this is posted below, however neither signal will be available on the port pin when the device is in SLEEP mode, as the output value of the port pins are latched in SLEEP mode. You can, however, produce the CP0A signal on a port pin while the device is in SUSPEND mode, as the port pins values are not latched. Level changes on the comparator output that result in the wake event for the device do not appear on the pin when the device is in SLEEP mode, but after the device wakes, it is possible to see the comparator output on the pin. Conversely, when the device is in SUSPEND, it is possible to see the CP0A (asynchronous only) signal on that pin before and after the device has woken from SUSPEND. It is not possible to output the synchronous comparator output on a pin in either SLEEP or SUSPEND mode, as the clock that latches the synchronous output value to the output buffer is not active in these low power modes.
To enable the Comparator0 output on a port pin, the following steps are required:
1) In the XBR0 register, enable comparator synchronous/CP0 output (XBR0 |= 0x10 or asynchronous/CP0A output (XBR0 |= 0x20.
2) Ensure that port pin you wish to use is configured as a digital output.
3) Skip any pins necessary to assign CPT0 output to your desired pin. For instance, if you wish to use P0.4, and assuming that you are not using any higher priority digital peripherals on the crossbar (UART0, SPI1, SPI0, or SMBus), then you would need to skip pins P0.0 - P0.3 (P0SKIP |= 0x0F.
Thus, to enable the asynchronous CP0A output to pin P0.4, the following code should be added to the COMPARATOR0_Init() routine:
XBR0 |= 0x20; // enable CPT0A asynchronous output to pin
P0MDOUT |= 0x10; // set P0.4 to push-pull
P0SKIP |= 0x0F; // skip P.0.0-P0.3 on crossbar - this should put CP0A on P0.4
Using Comparator0 as a Wake-up Source for the C8051F960