Low Power Application on PIC32CM LE00 (Cortex M23) MCUs Using MPLAB® Harmony v3 Peripheral Libraries

Last modified by Microchip on 2023/11/16 06:54

Objective

This tutorial shows you how to create a low power application on a PIC32CM LE00 MCU using the MPLAB® Harmony v3 software framework.

The PIC32CM LE00 is a 32-bit Arm® Cortex®-M23-based microcontroller that provides features to reduce power consumption through different Sleep modes, such as Idle and Standby.

  • In Idle mode, the CPU is stopped and optionally, some synchronous clock domains are stopped, depending on the IDLE argument. The regulator operates in Normal mode. This mode allows power optimization with a fast wake-up time.
  • In Standby mode, all clock sources are stopped, except those that are kept running if requested by a running module or have the ONDEMAND bit set to zero. The regulator operates in Low Power mode. Before entering Standby mode the user must make sure that a significant amount of clocks and peripherals are disabled so that the voltage regulator is not overloaded. This mode allows the device to consume the lowest power with little overhead on wake-up time.

The Power Manager (PM) module is responsible for controlling the Low Power modes. Additionally, the PIC32CM LE00 MCU provides SleepWalking. SleepWalking is the capability for a device to temporarily wake up clocks for the peripheral to perform a task without waking up the CPU in STANDBY sleep mode.

The application makes use of the PIC32CM LE00 Curiosity Pro Evaluation Kit, and the I/O1 Xplained Pro Extension Kit (sold separately).

The application is developed on the MPLAB Harmony v3 software framework. MPLAB Harmony v3 is a modular framework that provides interoperable firmware libraries for application development on 32-bit MCUs and MPUs. It includes an easy-to-use Graphical User Interface (GUI) (MHC) for selecting, configuring, and generating starter codes, peripheral libraries, and middleware (USB, TCP/IP, Graphics, and so on).

On power-up, the application prints a menu on a PC serial terminal. The menu provides options to measure the device's power consumption in Sleep modes. Once the option is selected, the application sets up the EIC peripheral clock source and goes to Standby Sleep mode to enable measurement modes.

In this training module,

The power consumption of the PIC32CM LE00 Curiosity Pro Evaluation Kit is measured using the tool:

  • Data Visualizer - A software tool

The steps to connect and measure the power consumption using these tools are provided in the following sections.

Power Measurement Mode

By default, the application is running with the device in Standby Sleep mode. While the device is in Standby Sleep mode, the user can measure the device's power consumption by following the instructions provided in the following sections.

The device wakes up from Standby mode and enters Active mode when you cover the light sensor (by placing a hand over it, for example) on the I/O1 Xplained Pro Extension Kit. Here, you can observe the transition of the device's power consumption from Standby Sleep mode to Active mode on the Data Visualizer tool.

The application prints the room temperature on a serial terminal, and the device goes back to Standby Sleep mode. The LED0 on the PIC32CM LE00 Curiosity Pro Evaluation Kit is toggled every time the serial console displays the temperature.

When you press the switch button SW1, the application switches from Standby Sleep mode to Idle Sleep mode. Here, you can observe the transition of the device's power consumption from Standby Sleep mode to Active mode and from Active mode to Idle Sleep mode. At this point, you can measure the device's power consumption in Idle Sleep mode by following the instructions provided in the following sections.

The device wakes up from Idle mode and enters Active mode when you cover the light sensor (by placing a hand over it, for example) on the I/O1 Xplained Pro extension Kit. Here, you can observe the transition of the device's power consumption from Idle Sleep mode to Active mode on the Data Visualizer tool.

The application prints the room temperature on a serial terminal, and the device goes back to Standby Sleep mode. The LED0 on the PIC32CM LE00 Curiosity Pro Evaluation Kit is toggled every time the serial console displays the temperature.

By default, the application is running with the device in Standby Sleep mode, and the device wakes up from Standby Sleep mode when you press a switch on the Evaluation board. The application switches the device's Sleep mode between Standby Sleep mode and Idle Sleep mode whenever you press the SW1 switch.

Also, the device wakes up from Standby mode or Idle mode when you cover the light sensor by placing your hand over it, prints the wake-up reason message, and goes back to Sleep mode.

The application you create will utilize the following peripherals:

  • SERCOM5 (as I²C) peripheral library to read the temperature from the temperature sensor.
  • Real-Time Clock (RTC) peripheral library to periodically generate an event for the ADC to sample the light sensor.
  • SERCOM3 (as Universal Synchronous Asynchronous Receiver Transmitter (USART)) peripheral library to print messages on a serial console running on a computer.
  • PORT peripheral library to toggle the LED0.
  • Analog to Digital Converter (ADC) peripheral library to sample the light sensor analog input and detect whether the light sensor is covered or not.
  • PM peripheral library to configure Low Power modes.
  • External Interrupt Controller (EIC) peripheral library to control the user button SW1.
  • EVSYS peripheral library to trigger the start of the ADC conversion on every RTC compare match event. The EVSYS allows for peripheral-to-peripheral communication without CPU intervention. This reduces the burden on the CPU and other resources when compared to conventional interrupt-based systems.

Two approaches for this Tutorial

  1. Create the project from scratch:
    • Use the provided source files and step-by-step instructions below.
  2. Use the solution project as an example:
    • Build the solution project and download it to the PIC32CM LE00 Curiosity Pro evaluation Kit to observe the expected behavior.

Lab Objectives

  1. Create an MPLAB X IDE Harmony v3 project for a PIC32CM LE00 MCU from scratch.
  2. Use MCC to configure and generate Harmony v3 Peripheral Library code for the RTC, I²C, USART, ADC, PM, EIC, EVSYS, and PORT peripherals.
  3. Use the Harmony v3 Peripheral Library Application Programming Interfaces (APIs) to implement and demonstrate a low-power application.

Reference Materials

The application is being developed on a PIC32CM LE00 CPRO-04 Revision board. Please verify the board revision by turning the board around and noticing the white box. Ensure that you use the same revision on the Evaluation board before going further, else you could face issues with power consumption values.

Figure 1. Board Revision

Figure 1. Board Revision

The Curiosity Pro series Evaluation Kits include an onboard Embedded Debugger (EDBG). No external tools are necessary to program or debug the PIC32CM5164LE00100. For programming or debugging, the EDBG connects to the host PC through the USB micro-B connector on the PIC32CM LE00 Curiosity Pro Evaluation Kit.

Figure 2: Hardware Setup

Figure 2: Hardware Setup

Hardware Connection Setup

  • Connect the I/O1 Xplained Pro extension Kit to the Extension Header 1 (EXT1) of the PIC32CM LE00 Curiosity Pro Evaluation Kit.
  • Connect a USB cable to the DEBUG USB port for programming.

Software Tools

This project has been verified to work with the following versions of software tools:

Because we regularly update our tools, occasionally you may discover an issue while using the newer versions. If you suspect that to be the case, we recommend that you double-check and use the same versions that the project was tested with.

For this lab, download the following repositories from GitHub:

  • CSP: The following table shows the summary of contents.
FolderDescription
appsExample applications for CSP library components
archInitialization and starter code templates and data
docsCSP library help documentation
peripheralPeripheral library templates and configuration data
  • DEV_PACKS: The following table shows the summary of contents.
FolderDescription
MicrochipPeripheral register specific definitions
armCore Specific Register Definitions (CMSIS)

Overview

This lab shows you how to create an MPLAB Harmony v3 project from scratch. You will configure and generate Harmony v3 peripheral library code for the RTC, I²C, USART, ADC, DMA, PM, SUPC, EIC, EVSYS, and PORT peripherals. It also demonstrates Low Power mode features of the PIC32CM LE00 MCU using light and temperature sensors on the I/O1 Xplained Pro extension Kit.

The application flow is as follows:

  • On power-up, the application runs in Standby Sleep mode
  • The RTC is configured as an event generator to generate a periodic (every 500 ms) event to trigger the ADC to start conversion
  • The ADC acknowledges the event from the RTC and starts the conversion of the light sensor signal
  • If the ADC conversion result is greater than the defined threshold, the ADC produces an interrupt to wake up the CPU
  • In Active mode, the CPU submits an I²C read transfer request to read the temperature value from the temperature sensor on the I/O1 Xplained Pro Evaluation Kit
  • The application submits a DMA transfer request to transfer the latest temperature value (in a formatted message) to the USART (serial console)
  • After the DMA transfer is complete, the device re-enters Standby Sleep mode
Figure 3. Application Initialization flow sequence

Figure 3. Application Initialization flow sequence

The application also monitors the pressing of the switch SW1. If a switch press is detected, the application moves the device to Idle Sleep mode. As in Standby Sleep mode, covering the light sensor with your hand wakes up the device from Idle Sleep mode. Once awake, the application prints room temperature values on the serial console and re-enters Standby Sleep mode once the light sensor is uncovered.

Figure 4. CPU in Idle or Standby mode

Figure 4. CPU in Idle or Standby mode

Lab Source Files and Solutions

This ZIP file contains the completed solution project for this lab. It also contains the source files needed to perform the lab by following the step-by-step instructions (see the "Procedure" section on this page).

Extracting the ZIP file creates the following folders:

  • pic32cm_le00_low_power contains the lab solution (in the firmware folder) and source files (in the dev_files folder)
    • dev_files contains subfolder pic32cm_le00_cpro containing application source files and other support files (if any) required to perform the lab (see "Procedure" section below)
    • firmware contains the completed lab solution project. It can be directly built and downloaded on the hardware to observe expected behavior.

Procedure

All steps must be completed before you will be ready to build, download, and run the application.

Lab Index

Step 1: Create Project and Configure the PIC32CM LE00

  • Step 1.1 - Verify Whether the MCC Plug-in is Installed in MPLAB X IDE
  • Step 1.2 - Create MPLAB Harmony v3 Project Using MPLAB X IDE
  • Step 1.3 - Configure Clock Settings

Step 2: Configure I²C, USART, and RTC Peripheral Libraries

  • Step 2.1 - Configure RTC Peripheral Library
  • Step 2.2 - Configure I²C Peripheral Library, I²C Pins, and Verify I²C Clock
  • Step 2.3 - Configure USART Peripheral Library, USART Pins, and Verify USART Clock
  • Step 2.4 - Configure DMA Peripheral Library

Step 3: Configure ADC, Event System, and EIC Peripheral Libraries

  • Step 3.1 - Configure Analog-to-Digital Converter (ADC) Peripheral Library (PLIB)
  • Step 3.2 - Configure External Interrupt Controller (EIC) PLIB for Switch Button
  • Step 3.3 - Configure Event System (EVSYS) PLIB

Step 4: Configure PM, SUPC, and NVMCTRL Peripheral libraries and LED

  • Step 4.1 - Configure Power Manager (PM) Peripheral Library
  • Step 4.2 - Configure SUPC Peripheral Library
  • Step 4.3 - Configure NVMCTRL Peripheral Library
  • Step 4.4 - Configure LED

Step 5: Generate Code
Step 6: Add Application Code to the Project
Step 7: Build, Program, and Observe the Outputs