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
We recommend completing these examples:
To run this example you need the following hardware:
Supported STMicroelectronics Nucleo boards
USB type A to Mini-B cable
The following figure shows the example model:
We will write the PWM output to GPIO D3, and connect D3 to D13(user LED) using a breadboard wire, as shown.
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.