Simple Methods to Achieve Breathing Light Effect with Microcontrollers

Follow+Star Public Account Number, don’t miss exciting content

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

Source | Renesas Embedded Encyclopedia

To create a better atmosphere, many electronic products have applied breathing lights.

There are many methods to achieve breathing lights, which are relatively simple. Today, I will describe a few simple steps to configure a breathing light effect with the Renesas microcontroller.

Overview

This article is based on the e2studio development environment, using the CPK-RA2L1 evaluation board, configuring the timer PWM output to achieve the breathing light effect.
This project will teach you how to create a new project in the development environment, how to configure a new peripheral, how to call peripheral drivers, and how to develop applications based on FSP.

Hardware Preparation

First, you need to prepare an evaluation board. Here, we use the R7FA2L1AB2DFM evaluation board provided by Renesas, with the chip package PLQP0064KB-C and a Cortex-M23 core, running at a maximum frequency of 48MHz, as shown in the figure below.
Simple Methods to Achieve Breathing Light Effect with Microcontrollers
This evaluation board supports USB power supply debugging, making it very suitable for early verification and development of customer projects. The development board drives a blue LED through the P501 port, as shown in the diagram below.
Simple Methods to Achieve Breathing Light Effect with Microcontrollers

Create Project

1. Select File-New C/C++ Project from the menu, choose as shown in the figure below, and then click Next.

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

2. Fill in the project name and the location to save the project, please note not to include Chinese paths, then click Next.

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

3. FSP version selection → Device selection → Debugging method selection. As shown in the table below, then click Next, and you can directly click Next on the next interface.

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

4. Select the project template, as shown in the figure below, and click Finish if confirmed.

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

5. After the project is created, the interface shown in the figure below appears, where you can confirm whether your configuration information is correct.

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

Project Configuration

Project configuration is the key to the project, involving the configuration of the peripherals used in the project, including BSP, Clocks, Pins, Interrupts, Stacks, etc.

1. Click on the Stacks tab from the previous interface, and add the TIMER for this project. As shown below:

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

2. Click on the newly created stack, as shown below, to pop up the properties window.

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

Note: If the properties window does not pop up, you can find it from the menu Window-Show View.

3. Double-click Properties to go full screen, double-click again to exit full screen. The specific configuration of properties is as follows.

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

4. Assign the pins to P501, and after the configuration is complete, click the triangle button (Generate Project Content) in the upper right corner.

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

Software Development

After entering the software development interface, find the hal_entry.c file in the src folder to implement software development.

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

Before the formal software development, let me introduce some tips for e2studio development, otherwise beginners may feel stuck. Familiarizing with e2studio will make development much more convenient for engineers.

The first tip is the Developer Assistance under the project directory. Double-click to open it, and all related driver functions for the configured peripherals will be inside. Experienced engineers can understand the function and usage based on the literal meaning. Beginners may see the functions but still struggle to understand them, so it is necessary to refer to the FSP (Flexible Software Package) user manual for function usage instructions. This is also the second tip for software development.

Open hal_entry.c, find the place where you can add your code, and add the corresponding application function.

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

The specific method of adding functions is as follows (click the function you need to add on the left side with the mouse, and drag it to the corresponding position on the right side).

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

Engineers interested can study each function. The specific research method refers to the FSP document. For example, the function for this project is extracted based on FSP, as shown in the figure below.

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

The specific code used for controlling the breathing light with the TIMER PWM output is shown in the figure below.

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

The project adopts a 1% step adjustment duty cycle to achieve PWM pulse width modulation, thereby achieving the breathing light function.

The effect of duty cycle adjustment and the effect of breathing light are shown in the figure below. Two small videos of the experimental process can be found in the attachment.

Summary

The above is the complete development process to achieve the breathing light effect based on the CPK-RA2L1 evaluation board and the e2studio development environment. The CPK-RA2L1 evaluation board is an entry-level kit launched by Renesas, with all IO ports brought out through pin headers, making it very convenient for other functional module expansion and debugging. Only one USB debugging cable is needed to connect the evaluation board and PC to realize power supply, program download, and debugging of the evaluation board. e2studio is Renesas’ integrated development environment, which, based on the graphical user interface of FSP, can conveniently achieve peripheral selection, configuration, code generation, and code development, significantly accelerating the development process. Like many mainstream MCU manufacturers’ development environments, e2studio is also developed based on eclipse, with a similar development interface, allowing users to quickly familiarize themselves with Renesas MCU development.

———— END ————

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

Based on IAR to set up MCU serial port and RTT Viewer printing

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

Using SystemView tool to analyze MCU running status under RTOS

Simple Methods to Achieve Breathing Light Effect with Microcontrollers

Important contents in the MCU FSP library startup file

Leave a Comment