Conditional Wake-Up from SLEEP using the CLC

 Objective

This example uses two simultaneous conditions to wake the PIC16F18855 from sleep mode. The first is when the push button on the MPLAB® Xpress Evaluation Board is pressed and the second is a transmission attempt detected on the RX pin of the Enhanced Universal Synchronous Asynchronous Receiver Transmitter (EUSART) peripheral. Each of these conditions alone won’t wake the device. Only when both the push button is pressed and held simultaneously at the same time data is received on the EUSART RX pin, then and only then will the microcontroller (MCU) wake up.

Background

Many applications need to conserve power like battery-powered or energy-harvesting designs. It is common in such applications to place the MCU into a low-power SLEEP Mode. This mode disables the MCU clock and the CPU stops executing code.

The MCU is kept in this SLEEP mode until a specific event trigger called a 'wake-up' has occurred indicating that something in the application requires attention. This is usually done with some sort of a pin state change.

What if the MCU is only needed to make system changes when two or more conditions are present?

Traditionally this is done using a single pin change that wakes the MCU. The CPU then checks to see if other inputs have changed that constitute the specific condition. If those inputs have not changed then the MCU is placed back into SLEEP mode having just wasted power unnecessarily by waking and performing the check.

wakeUPwithoutCLC%281%29.jpg

A lower power alternative is available that makes use of the Configurable Logic Cell (CLC) peripheral available on many 8-bit PIC® MCUs including the PIC16F18855 on the MPLAB Xpress Development Board.

Since the CLC is able to continue running even in SLEEP mode and the MCU can be woken by an interrupt created by a CLC interrupt, it is possible to conditionally wake the device.

wakeUPwithCLC%281%29.jpg

 MPLAB Xpress IDE Edition - Episode 10 - Enabling Combinational Wake-Up Sources Using the CLC

 Materials

Hardware Tools (Optional)

Tool About Purchase
Xpress-50px.png
MPLAB® Xpress
Development Board

Software Tools

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
MPLAB® X
Integrated Development Environment

Exercise Files

File Download
Installation
Instructions
Windows Linux Mac OSX
Project and Source Files
Board Schematic

 Procedure

To follow along with these steps, MPLAB Xpress should be open and you should be logged in so that the MPLAB Code Configurator plug-in can be used.

1

Create Project

Create a new project in MPLAB Xpress for a PIC16F1855 called conditionalWakeCLC.

If this is your first project please visit the "MPLAB® Xpress: Create a Project" page.

2

Open MCC

The default system settings can be used.

If this is your first project using MCC please visit the "Opening MCC in MPLAB® Xpress" page.

3

EUSART Setup

Select EUSART from the MCC peripheral menu. The EUSART block is located under Device Resources of the MCC.

Figure%201_1.JPG

Setup the EUSART peripheral as follows:

  • Select 9600 the 'Baud Rate' drop-down menu
  • Check the 'Enable Transmit' checkbox
  • Check the 'Redirect STDIO to USART' to allow printf to be used

Double clicking on the EUSART opens the EUSART Setup window:

Figure%202_1.JPG

4

CLC setup

Scroll through the Device Resources and locate the CLC peripheral. Add CLC1 to the project by double-clicking on it.

addCLC1.JPG

Select the CLC1 peripheral under Project Resources to open the Easy Setup dialog and configure as follows:

  • Select Enable CLC Interrupt as this CLC will be the Wake-up source for the PIC16F18855 out of low power SLEEP mode.
  • Select Enable Rising Interrupt. This triggers the interrupt when the output of the CLC1 peripheral goes from LOW to HIGH.
  • Choose AND-OR from the CLC Mode drop-down menu.
  • Connect the CLCIN0 to the top input of the OR 1 gate and the CLCIN1 to the second input of the OR 2 gate.
  • Negate both OR gate outputs.

The Easy Setup for the CLC1 peripheral should now resemble the image below:

clcConfiguration.JPG

5

Pin Manager

Navigate to the Pin Manager and connect the following peripheral signals to the listed pins:

  • CLCIN1 signal to the RA5 pin connected to the pushbutton on the MPLAB Xpress Board
  • CLCIN0 signal to the RC1 pin
  • RC0 pin to the TX signal and RC1 pin to the RX signal
clcPinManager.jpg

Note: The RC0 pin is shared by both the CLCIN0 signal of the CLC1 and the RX input signal of the EUSART. This capability is due to the Peripheral Pin Select (PPS) capabilities of the PIC16F18855. When pins are shared by more than one peripheral, the lock icon in the Pin Manager is replaced by a chain link icon.

6

Generate Code

Generate the code based on the above setting by clicking on the Generate button at the top right of the IDE and then click OK in the Generation Completed dialog.

7

Edit Main.c

Navigate to the MPLAB Xpress IDE and open the main.c source file in the Project pane.

Inside of the main() uncomment the INTERRUPT_GlobalInterruptEnable(); macro to enable global interrupts and the INTERRUPT_PeripheralInterruptEnable() macro to enable peripheral interrupts. The CLC1 peripheral was configured to utilize interrupts that will be used to wake the PIC16F18855 from low power SLEEP mode.

Next, add code that will:

  1. Notify the user that the MCU is about to go into a low power state by transmitting a message over the EUSART.
  2. Place the device into low power SLEEP.
  3. Notify you if and when the MCU is woken by the conditions defined in the CLC1 configuration.

Scroll down through the main() to the while(1) loop. Inside of the loop add the following code just below the //Add your application code comments:

8

Program Xpress Board

Compile the project by clicking on the Make and Program Device icon.

To learn to compile a project please visit the "MPLAB® Xpress: Compile a Project" page.

The MPLAB® Xpress Development Board should be connected to an available USB port on the host computer through a USB cable to the micro B connector on the board. Drivers should install successfully the first time the board is connected and may take a minute or so. The connection is shown in the picture. No other components are required.

figure2.png

Program the MPLAB® Xpress board by dragging the project .hex file from the downloads section of the browser and dropping the file on to the Xpress drive.

figure13.png

The Programmer LED on the Xpress board should quickly flash from green to red and then back to green indicating that the .hex file was successfully programmed to the PIC16F18855.

 Results

Once the MPLAB Xpress board is programmed, open a terminal program such as CoolTerm and connect to the COM port assigned to the board.

Push the RESET button on the MPLAB Xpress Development Board.

RESET%281%29.jpg

This restarts code execution on the MCU and output the notification that the device is going into SLEEP mode.

going2SLEEP.JPG

Pressing the push button alone on the MPLAB Xpress Development Board results in no messages printing to the terminal program window.

pushButton%281%29.jpg

Using the mouse, click inside of the terminal window and hit the return key. The program will indicate that a message has been transmitted over the COM port. Again, no messages should print in the terminal program window.

Finally, while pressing the push button, click inside of the terminal program window with the mouse and hit the enter key. This time the notification will appear inside of the terminal window indicating that the MCU has awoken since the conditions defined during CLC1 configuration have been met. After 500 ms, the notification that the device going back into SLEEP mode will be printed to the terminal window confirming the MCU is now back in a low power mode.

awake.JPG

 Conclusions

Although the EUSART and a push button were used as the CLC inputs, you should note that other on- and off-chip input sources can be used. These could include other sensors, timer outputs, and even other CLCs. Any of these signals can be used in conjunction with logical operations such as OR, XOR or AND operations or even combine this with state machine behavior by incorporating flip-flops, waking the device from sleep only when a very specific combination occurs.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.