Low Power Application on SAMC2x (Arm® Cortex®-M0+) MCUs Using MPLAB® Harmony v3 Peripheral Libraries

 Objective

SAMC2x is part of Microchip's 32-bit Arm® Cortex®-M0+ microcontroller (MCU) family that can be used to meet the needs of power-constrained applications. SAMC2x MCUs provide various sleep modes to meet the power consumption requirements of the application. The Power Manager (PM) module is responsible for controlling the low power modes.

SAMC2x supports two low power modes: IDLE and STANDBY.

  • Idle sleep mode: In Idle mode, CPU and Synchronous clocks are stopped except when requested. Idle mode allows power optimization with fast wakeup time.
  • Standby Sleep mode: In Standby mode, the CPU is stopped as well as the peripherals, except those that are running using the RUN IN STANDBY option. Standby mode allows the device to consume the lowest power with little overhead on wakeup time.

The application makes use of the SAM C21 Xplained Pro evaluation kit and the I/O1 Xplained Pro extension kit (sold separately).

The application is developed on MPLAB® Harmony v3 software framework. MPLAB Harmony is a modular framework that provides interoperable firmware libraries for application development on 32-bit microcontrollers and microprocessors. It includes an easy-to-use GUI (MCC) for selecting, configuring, and generating starter codes, peripheral libraries, and middlewares (USB, TCP/IP, graphics, and so on). MCC provides an easy-to-use UI.

On power-up, the application is in Sleep (standby) mode. The application wakes up from the Sleep mode and enters Active mode when you cover the light sensor (by placing a hand over it) on the I/O1 Xplained Pro extension kit. The application periodically prints room temperature on a serial terminal while the light sensor is covered. The application goes back to Sleep (standby) mode when you uncover the light sensor. LED0 in the SAM C21 evaluation kit is toggled every time the temperature is displayed on the serial console.

When you press the switch SW0, the application switches Sleep mode from Standby mode to Idle mode.

The application you create will utilize:

  • SERCOM (as I²C) Peripheral Library to read the temperature from the temperature sensor.
  • RTC Peripheral Library to periodically generate an event for the ADC to sample the light sensor.
  • SERCOM (as USART) and DMA Peripheral Libraries to print the temperature values on a COM (serial) port terminal application running on a PC.
  • PORT Peripheral Library to toggle the LED.
  • ADC Peripheral Library to sample the light sensor analog input and detect whether the light sensor is covered or not.
  • PM and Supply Controller (SUPC) Peripheral Libraries to configure low power modes.
  • External Interrupt Controller (EIC) Peripheral Library to control switch SW0.
  • Event System Peripheral Library to trigger the start of the ADC conversion on every RTC compare match event. The event system 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 Ways to Use 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 SAM C21 Xplained Pro evaluation kit to observe the expected behavior.

Lab Objectives

  1. Create an MPLAB® X IDE Harmony v3 project for a SAM C21 microcontroller from scratch.
  2. Use MCC to configure and generate MPLAB Harmony v3 Peripheral Libraries code for RTC, I²C, USART, DMA, ADC, PM, SUPC, EIC, event system, and PORT peripherals.
  3. Use the MPLAB Harmony v3 Peripheral Library APIs to implement and demonstrate a low power application.

 Materials

Hardware Tools

Tool About Purchase
atsamc21-xpro-50px.png
SAM C21 Xplained Pro
Evaluation Kit
ATIO1-XPRO-50px.png
I/O1 Xplained Pro
Extension Kit
board-50px.png
Power Debugger

The Xplained Pro series evaluation kits include an on-board Embedded Debugger (EDBG). No external tools are necessary to program or debug the ATSAMC21J18A. For programming/debugging, the EDBG connects to the host PC through the USB Micro-B connector on the SAM C21 Xplained Pro evaluation kit.

hardware.jpg
Figure 1: Hardware Setup

Hardware Connection Setup

  • Connect the I/O1 Xplained Pro extension kit to Extension Header 2 (EXT2) of the SAMC21 Xplained Pro evaluation kit.
  • Remove the current measurement jumper on the SAMC21 (highlighted in hardware setup with letter A) and connect to channel A of power debugger using burg connectors (highlighted in hardware setup with letter B) as shown in Figure 1.
  • Probe Pin #9 (PA28 - Switch pin) and Pin #10 (PA27 - wake-up test pin) on Extension Header 3 (EXT3) as highlighted in the Hardware Setup figure to measure wake-up time.
  • Connect a USB cable to the DEBUG USB port for programming.
  • Connect a USB cable to the power debugger DEBUG USB port for current measurement.

Note :
1. Make sure common ground is connected with the board while using the logic analyzer/CRO.
2. SAMC21 supports both 3.3V and 5V. The SAMC21 Xplained Pro kit operates at 3.3V since the VCC-SEL jumper on board is set to 3.3V.

Software Tools

This project has been verified to work with the following versions of software tools:
MPLAB X IDE v6.10, MPLAB XC32 Compiler v4.30, MPLAB MCC v5.3.7

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.

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
MPLAB® X
Integrated Development Environment
MPLAB® XC32
C/C++ Compiler

For this lab, download the following repositories from GitHub:

  • CSP - The following table shows the summary of contents.
Folder Description
apps Example applications for CSP library components
arch Initialization and starter code templates and data
docs CSP library help documentation
peripheral Peripheral library templates and configuration data
  • DEV_PACKS -The following table shows the summary of contents.
Folder Description
Microchip Peripheral register specific definitions
arm Core specific register difinitons (CMSIS)

Use the MPLAB Code Configurator Framework Downloader to download the repositories.

Overview

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


Figure 1.1 Application Flow Sequence

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.
flowchart.png
Figure 1.1 shows the flow sequence of the application task.
Click image to enlarge.
block1.png
Figure 2

The application also monitors the pressing of the switch SW0. 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.

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).

The contents of this ZIP file need to be placed in a folder of your choice.
Note:

  • The project location of an MPLAB Harmony v3 project is independent of the location of the MPLAB Harmony Framework path (i.e., you need not create or place an MPLAB Harmony v3 project in a relative path under the MPLAB Harmony v3 framework folder). The project can be created or placed in any directory of your choice. This is true because when created, an MPLAB Harmony v3 project generates all the referred source/header files and libraries (if any) under the project folder.
  • The point above contrasts with the MPLAB Harmony v2 project location. In MPLAB Harmony v2, the project was supposed to be created in a location under the MPLAB Harmony framework.


Extracting the ZIP file creates the following folders:

  • samc21_low_power contains the lab solution (in the firmware folder) and source files (in the dev_files folder).
    • dev_files contains the sam_c21_xpro subfolder, which contains 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 SAM C21

  • Step 1.1 - Verify whether MPLAB® Code Configurator (MCC) Plug-in installed in MPLAB® X IDE
  • Step 1.2 - Create MPLAB Harmony v3 Project using MPLAB X IDE
  • Step 1.3 - Verify 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 and I²C pins
  • Step 2.3 - Configure USART Peripheral Library and USART pins
  • Step 2.4 - Configure DMA Peripheral Library

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

  • Step 3.1 - Configure ADC Peripheral Library
  • Step 3.2 - Configure EIC Peripheral Library for switch
  • Step 3.3 - Configure Event System Peripheral Library

Step 4: Configure PM, SUPC and LED

  • Step 4.1 - Configure PM and SUPC
  • Step 4.2 - Configure LED and Wake-up test Pins

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

© 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.