No ACL setup yet! Denying access to everyone.
en:edu:zmitac:macro:embedeed:lab:stm32-pwm
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| en:edu:zmitac:macro:embedeed:lab:stm32-pwm [2024/03/18 08:06] – ktokarz | en:edu:zmitac:macro:embedeed:lab:stm32-pwm [2025/04/02 08:50] (current) – ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| - | ====== STM32 Control of build-in LEDs with PWM ===== | + | ====== STM32 Control of built-in LEDs with PWM ===== |
| - | This exercise presents how to handle the brightness control of three LEDs mounted on the Nucleo STM32WB55 board. LEDs are electrically connected to microcontroller' | + | This exercise presents how to handle the brightness control of three LEDs mounted on the Nucleo STM32WB55 board. LEDs are electrically connected to the microcontroller' |
| ===== Prerequisites ===== | ===== Prerequisites ===== | ||
| Line 28: | Line 28: | ||
| ==== Task 2 ==== | ==== Task 2 ==== | ||
| - | To do the second task it is necessary to understand the timer operation. It is more complex task than the previous so some detailed explanation is provided below. | + | To do the second task it is necessary to understand the timer operation. It is a more complex task than the previous so some detailed explanation is provided below. |
| === Hardware we use === | === Hardware we use === | ||
| - | In the STM32WB55 there are two timers capable of generating the PWM signal for up to four channels per timer. Unfortunately, | + | In the STM32WB55, there are two timers capable of generating the PWM signal for up to four channels per timer. Unfortunately, |
| === Software library === | === Software library === | ||
| Line 70: | Line 70: | ||
| channelB = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(LED_PWM_BLUE), | channelB = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(LED_PWM_BLUE), | ||
| - | // Instantiate HardwareTimer object. Thanks to ' | + | // Instantiate HardwareTimer object. Thanks to the ' |
| MyTimLED = new HardwareTimer(Instance); | MyTimLED = new HardwareTimer(Instance); | ||
| Line 89: | Line 89: | ||
| === Step 4 === | === Step 4 === | ||
| - | To modify the intensity of the chosen LED in the loop() function use the setCaptureCompare function. It changes the content of the capture compare register responsible for the duration of the duty cycle. In the following example, the duty_cycle_value can vary between 0 and 100. | + | To modify the intensity of the chosen LED in the loop() function, use the setCaptureCompare function. It changes the content of the capture compare register responsible for the duration of the duty cycle. In the following example, the duty_cycle_value can vary between 0 and 100. |
| <code c> | <code c> | ||
| MyTimLED-> | MyTimLED-> | ||
| Line 119: | Line 119: | ||
| ===== FAQ ===== | ===== FAQ ===== | ||
| - | **What is the maximum number of channels? | + | **What is the maximum number of channels? |
| \\ | \\ | ||
| - | **What is the maximum bit resolution for PWM?**: Maximum resolution is 16 bits. Note that we can express the duty cycle in a variety of formats. In the presented example we expressed it in percentage so it varies between 1 and 100. It can be also expressed in ticks, Hertz, microseconds, | + | **What is the maximum bit resolution for PWM?**: Maximum resolution is 16 bits. Note that we can express the duty cycle in a variety of formats. In the presented example, we expressed it in percentage so it varies between 1 and 100. It can also be expressed in ticks, Hertz, microseconds, |
| \\ | \\ | ||
| - | **What PWM frequency should I use? | + | **What PWM frequency should I use? |
en/edu/zmitac/macro/embedeed/lab/stm32-pwm.1710745575.txt.gz · Last modified: by ktokarz
