主要内容

Control Onboard LED Brightness Using PWM Blocks on Renesas RA Microcontrollers

This example shows how to control the brightness of an onboard LED on a Embedded Coder ® Support Package for Renesas® RA Microcontrollers by varying the duty cycle of a hardware PWM signal generated using the General PWM Timer (GPT). The example demonstrates how duty-cycle modulation directly affects LED intensity and how a Simulink model can be deployed to Renesas RA hardware for real-time execution.

You can use this workflow to validate PWM configuration, understand duty-cycle–based brightness control, or other PWM-controlled actuators on Renesas RA devices.

The example shows how to:

  • Generate a hardware PWM signal using the GPT32 peripheral.

  • Control LED brightness by varying the PWM duty cycle.

  • Deploy a Simulink model to Renesas RA hardware and observe real-time behavior.

Prerequisites

Before you begin,

Required Hardware

Hardware Connections

This example uses the onboard LED on the MCK-RA6T2 board.

Use a jumper wire to route the configured PWM output pin to the GPIO pin that drives the onboard LED.

RASC Project File

This example uses a Renesas Smart Configurator (RASC) project file to define the hardware configuration required for PWM generation.

The RASC project file contains:

  • GPT timer configuration for PWM operation.

  • Output pin mapping for the onboard LED.

  • Clock and peripheral settings required by the PWM block.

Configure the Simulink Model

Open the PWMExampleModelRA6.slx Simulink model.

modelName = "PWMExampleModelRA6";
open_system(modelName) 

The model is pre-configured for Renesas RA6 Based hardware.

Ensure the following settings are applied:

  • configuration.xml is added as the Renesas Smart Configurator (RASC) project file in Build options. To verify click Modeling > Model Settings to open the Configuration Parameters dialog box. Navigate to Hardware Implementation > Target hardware resources > Build options.

Configure the Blocks

Period and Duty Inputs

The Period and Duty inputs area defines the PWM behavior:

  • A Constant block specifies the PWM period.

  • A Sine Wave block generates a time-varying duty-cycle signal.

  • An Absolute Value block ensures the duty-cycle remains nonnegative.

LED Brightness Behavior

  • Increasing the duty cycle increases the average on-time of the PWM signal.

  • Increased on-time raises the average current through the LED.

  • Higher average current results in increased perceived LED brightness.

Reducing the duty cycle dims the LED accordingly.

Varying the PWM duty cycle gradually changes the LED brightness.

PWM Output Block

The PWM Output block generates the hardware PWM signal using the GPT32 peripheral.

  • The Period input controls the PWM frequency

  • The Duty input controls the duty cycle

  • The output pin drives the onboard LED

Deploy Model to Hardware

Deploy the model to the target hardware and observe how PWM duty-cycle changes affect LED brightness in real time.

To deploy and run the model:

In the Simulink toolstrip, from the Hardware tab, click Build, Deploy & Start. This action generates code, programs the target, and starts execution on the Renesas RA6 board.

To monitor progress, open the Diagnostic Viewer using the link displayed at the bottom of the model canvas. The Diagnostic Viewer reports code generation, compilation, and download status.

Observe LED Brightness Behavior

Observe the onboard LED on the Renesas RAMCK-RA6T2 board. The LED brightness varies according to the PWM duty-cycle input, confirming correct PWM configuration and hardware execution.