No ACL setup yet! Denying access to everyone.
en:edu:zmitac:s2:aih:lab:stm32pwm
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:edu:zmitac:s2:aih:lab:stm32pwm [2023/12/19 13:52] – ktokarz | en:edu:zmitac:s2:aih:lab:stm32pwm [2024/01/16 09:11] (current) – ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== STM32WB55 PMW LED control ====== | ====== STM32WB55 PMW LED control ====== | ||
| - | Our laboratory board supports an RGB LED that can be controlled with a PWM signal. Red, Green and Blue LEDs are in the same enclosure but can be controlled separately. In the stm32duino examples ((https:// | + | Our laboratory board supports an RGB LED that can be controlled with a PWM signal. Red, Green and Blue LEDs are in the same enclosure but can be controlled separately. In the stm32duino examples ((https:// |
| <table LEDpinassignment> | <table LEDpinassignment> | ||
| < | < | ||
| ^GPIO no^LED^ | ^GPIO no^LED^ | ||
| - | | D??? | Red LED | | + | | D3 | Red LED | |
| - | | D??? | Green LED | | + | | D6 | Green LED | |
| - | | D??? | Blue LED | | + | | D9 | Blue LED | |
| </ | </ | ||
| + | At the beginning of the code, there is a definition of pin value. Although the P-Nucleo-WB55 has the LED_BUILTIN defined it can't work as the PMW timer output. We have to override it. | ||
| + | <code c> | ||
| + | // ********************************************************* | ||
| + | #define LED_BUILTIN D6 //Override of the default LED_BUILTIN | ||
| + | // ********************************************************* | ||
| + | #if defined(LED_BUILTIN) | ||
| + | #define pin LED_BUILTIN | ||
| + | #else | ||
| + | #define pin D2 | ||
| + | #endif | ||
| + | </ | ||
| + | In the setup part of the code, the program automatically retrieves the timer instance and PWM channel number connected to the previously defined pin. | ||
| + | <code c> | ||
| + | TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(digitalPinToPinName(pin), | ||
| + | uint32_t channel = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(pin), | ||
| + | </ | ||
| + | While having information on the timer instance and channel number it instantiates the HardwareTimer object. | ||
| + | <code c> | ||
| + | | ||
| + | </ | ||
| + | The setup function oi finished with starting the timer to operate in PMW mode and configuring the PWM signal with frequency and duty cycle. | ||
| + | <code c> | ||
| + | MyTim-> | ||
| + | </ | ||
| + | It is possible to modify the duty cycle by changing the current value of the capture and compare register for specified channel. To do it we need to use the function. | ||
| + | <code c> | ||
| + | MyTim-> | ||
| + | </ | ||
| + | |||
en/edu/zmitac/s2/aih/lab/stm32pwm.1702990375.txt.gz · Last modified: by ktokarz
