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
en:edu:zmitac:s2:aih:lab:stm32pwm [2024/01/13 20:34] – ktokarzen:edu:zmitac:s2:aih:lab:stm32pwm [2024/01/16 09:11] (current) – ktokarz
Line 37: Line 37:
   MyTim->setCaptureCompare(channel, 50, PERCENT_COMPARE_FORMAT); // 50%   MyTim->setCaptureCompare(channel, 50, PERCENT_COMPARE_FORMAT); // 50%
 </code> </code>
-The program that controls all three LEDs has two files shown below PwmLedTest.h and PwmLedTest.cpp.\\ 
-**PwmLedTest.h** 
-<code c> 
-#include "Arduino.h" 
-#include <HardwareTimer.h> 
  
-#ifndef _PWMLED_TestLib 
-#define _PWMLED_TestLib 
- 
-// Pins definition for RGB LED 
-#define LED_PWM_RED   D3  //Arduino numberring D3, STM numberring PA_10 
-#define LED_PWM_GREEN D6  //Arduino numberring D6, STM numberring PA_8 
-#define LED_PWM_BLUE  D9  //Arduino numberring D9, STM numberring PA_9 
- 
-// PWM variables definitions 
-HardwareTimer *MyTimLED;               //Hardware Timer for PWM 
-uint32_t channelR, channelG, channelB; //RGB cahnnels 
- 
-#endif 
-</code> 
-**PwmLedTest.cpp** 
-<code c> 
-  #include "PwmLedTest.h" 
-   
-  void PwmLedSetup() 
-  { 
-    //Create Timer instance type based on the servo pin (the same timer is used for fan).   
-    TIM_TypeDef *Instance = (TIM_TypeDef *)pinmap_peripheral(digitalPinToPinName(LED_PWM_RED), PinMap_PWM); 
-     
-    //Define two separate channels for servo and fan 
-    channelR = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(LED_PWM_RED), PinMap_PWM)); 
-    channelG = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(LED_PWM_GREEN), PinMap_PWM)); 
-    channelB = STM_PIN_CHANNEL(pinmap_function(digitalPinToPinName(LED_PWM_BLUE), PinMap_PWM)); 
- 
-    // Instantiate HardwareTimer object. Thanks to 'new' instantiation, HardwareTimer is not destructed when setup() function is finished. 
-    MyTimLED = new HardwareTimer(Instance); 
- 
-    // Configure and start PWM 
-    MyTimLED->setPWM(channelR,LED_PWM_RED,100,1);   /* 100 Hertz, 1% dutycycle. */ 
-    MyTimLED->setPWM(channelG,LED_PWM_GREEN,100,1); /* 100 Hertz, 1% dutycycle. */ 
-    MyTimLED->setPWM(channelB,LED_PWM_BLUE,100,1);  /* 100 Hertz, 1% dutycycle. */ 
-  } 
- 
-  void fRGBLEDSet(int red, int green, int blue) 
-  { 
-    MyTimLED->setCaptureCompare(channelR, red, PERCENT_COMPARE_FORMAT);   //modify duty cycle 
-    MyTimLED->setCaptureCompare(channelG, green, PERCENT_COMPARE_FORMAT); //modify duty cycle 
-    MyTimLED->setCaptureCompare(channelB, blue, PERCENT_COMPARE_FORMAT);  //modify duty cycle 
-  } 
-</code> 
en/edu/zmitac/s2/aih/lab/stm32pwm.1705174446.txt.gz · Last modified: by ktokarz