Change the LED glow intensity on STMicroelectronics Nucleo Boards
This example demonstrates how to use the Simulink Coder Support Package for STMicroelectronics Nucleo Boards to run a Simulink® model on an STMicroelectronics Nucleo board to brighten up and dims down the LED glow intensity.
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 selecting them as the "Hardware board" on the Hardware Implementation pane of the Model Configuration Parameters.
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:
Task 1 - Connect 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.
Task 2 - Configure 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.
This example showed how to program your STMicroelectronics Nucleo board to use PWM Output block for changing the duty cycle and frequency of the digital output signal.