This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Change the LED Glow Intensity on STMicroelectronics Nucleo Boards

This example demonstrates how to use the Simulink Coder Support Package to run a Simulink® model on an STMicroelectronics Nucleo board to brighten and dim an LED.

Simulink Coder Support Package for STMicroelectronics Nucleo Boards enables you to use PWM Output block to vary the duty cycle of digital output pulse. This PWM output is written to GPIO 13 which is a user LED.

In this example you will learn how to configure a simple Simulink model to change the intensity of user LED for STMicroelectronics Nucleo F401RE board. You can configure this model for other supported Nucleo boards by browsing to Configuration Parameters > Hardware Implementation > Hardware board and selecting the required board.

Available versions of this example

STM Nucleo: stmnucleo_pwm_LED.slx

Prerequisites

We recommend completing these examples:

Required Hardware

To run this example you need the following hardware:

  • Supported STMicroelectronics Nucleo boards

  • USB type A to Mini-B cable

Model

The following figure shows the example model:

Connecting Pin D3 with D13

We will write the PWM output to GPIO D3, and connect D3 to D13(user LED) using a breadboard wire, as shown.

Configuring the Model for Code Generation and Download

In this task, you configure the model for the supported STMicroelectronics Nucleo board.

1. Open the PWM-LED model. This model has been configured for the Nucleo F401RE board. Follow the steps shown in the figure below to configure the model for the appropriate Nucleo board:

The user LED is driven by GPIO Pin 13 on the Nucleo F401RE board. The user LED might be driven by a different Pin on different Nucleo boards.

2. Click "Deploy To Hardware" to automatically download the generated bin file, stmnucleo_pwm_LED.bin, on to the connected Nucleo board.

3. Observe that the onboard LED connected at Pin 13 brightens up to the fullest and then dims up to the lowest intensity.

You can change the value of bias and sample time in "sine wave" block to observe the difference in LED intesntiy and it's frequency.