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.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
en:edu:zmitac:s2:aih:lab:stm32pwm [2024/01/13 18:37] – ktokarzen: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://github.com/stm32duino)), there is a simple program which allows us to control a single LED. It is named "All-in-one_setPWM" ((https://github.com/stm32duino/STM32Examples/tree/main/examples/Peripherals/HardwareTimer/All-in-one_setPWM)). It uses hardware timer output connected directly to an LED. Not every pin can work as the timer output, so this example requires proper selection of the pin connected internally to the PWM timer output. On the laboratory board, the pins used are as presented in table {{ref>LEDpinassignment}}.+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://github.com/stm32duino)), there is a simple program which allows us to control a single LED with PWM. It is named "All-in-one_setPWM" ((https://github.com/stm32duino/STM32Examples/tree/main/examples/Peripherals/HardwareTimer/All-in-one_setPWM)). It uses hardware timer output connected directly to an LED. The STM32WB55 microcontroller has two timer units built-in capable of generating PWM signals. One timer is connected to RGB LED, and another to the fan and servo. Not every pin can work as the timer output, so this example requires proper selection of the pin connected internally to the PWM timer output. On the laboratory board, the pins used are as presented in table {{ref>LEDpinassignment}}.
 <table LEDpinassignment> <table LEDpinassignment>
 <caption>Assignment of pins</caption> <caption>Assignment of pins</caption>
Line 10: Line 10:
 </table> </table>
 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. 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>+<code c>
 // ********************************************************* // *********************************************************
 #define LED_BUILTIN D6 //Override of the default LED_BUILTIN #define LED_BUILTIN D6 //Override of the default LED_BUILTIN
Line 21: Line 21:
 </code> </code>
 In the setup part of the code, the program automatically retrieves the timer instance and PWM channel number connected to the previously defined pin. 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>+<code c>
   TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(digitalPinToPinName(pin), PinMap_PWM);   TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(digitalPinToPinName(pin), PinMap_PWM);
   uint32_t channel = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(pin), PinMap_PWM));   uint32_t channel = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(pin), PinMap_PWM));
 </code> </code>
 While having information on the timer instance and channel number it instantiates the HardwareTimer object. While having information on the timer instance and channel number it instantiates the HardwareTimer object.
-<code>+<code c>
  HardwareTimer *MyTim = new HardwareTimer(Instance);  HardwareTimer *MyTim = new HardwareTimer(Instance);
 </code> </code>
 The setup function oi finished with starting the timer to operate in PMW mode and configuring the PWM signal with frequency and duty cycle. 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>+<code c>
   MyTim->setPWM(channel, pin, 5, 10); // 5 Hertz, 10% dutycycle   MyTim->setPWM(channel, pin, 5, 10); // 5 Hertz, 10% dutycycle
 </code> </code>
 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. 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>+<code c>
   MyTim->setCaptureCompare(channel, 50, PERCENT_COMPARE_FORMAT); // 50%   MyTim->setCaptureCompare(channel, 50, PERCENT_COMPARE_FORMAT); // 50%
 </code> </code>
 +
en/edu/zmitac/s2/aih/lab/stm32pwm.1705167460.txt.gz · Last modified: by ktokarz