cancel
Showing results for 
Search instead for 
Did you mean: 

how to generate a PWM signal with MCU stm32 inside the ARDUINO IDE? Ex: stm32f103xxx

audiex
Associate II
 
5 REPLIES 5
AScha.3
Chief II

analogwrite -> pwm

https://www.arduino.cc/reference/de/language/functions/analog-io/analogwrite/

If you feel a post has answered your question, please click "Accept as Solution".

Not a strong Arduino following here.

The STM32 TIM have quite good functional implementation for PWM output for Servo, etc.

Single frequency per TIM, but multiple PWM channels (4 typical)

You can always use the Arduino framework, and then code your own libraries, or access the hardware more directly/explicitly.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
audiex
Associate II

--- OK. As a matter of necessity, I need to make a 120h pwm and dutycycle 

variable from 0 ~ 100%. 

I know how to do this in CubeIDE, but inside the Arduino ide with an STM32XX MCU I can't! 

In 2019 in Arduino Ide 1.8.4, the parameters below worked with the STM32F103C8 MCU, but now they don't work anymore. It seems that these arguments have become obsolete!

--------------------------------------------

  HardwareTimer timer(2);      

   timer.setPrescaleFactor(1);    

   //timer.setOverflow(2500);    

   timer.setOverflow(14400);    

   

   //pwmWrite(PA8, 1200);    

   //pwmWrite(PA9, 1200);

   //pwmWrite(PA10, 1200);

   pwmWrite(PA2, 7000);

--

the above is not all, but it seems that pwmWrite is no longer used, nor is

HardwareTimer. 

It seems to me that nobody uses the Arduino to generate PWM with STM32 anymore. I say this because I did not find anything on the Internet about it. Shouldn't ST provide an APPNOTE on how to use their MCUs inside the Arduino IDE? If not, why give support on the boards and not have information for the users?

The purpose of the MCU is to read two analog inputs and send this reading through wireless communication with NRF24L01, and while it is sending, it will be producing a PWM signal. 

As I can't get the NRF24L01 library for CUBEIDE, I have to do everything in the Arduino IDE, but I want to use an STM32 in the Arduino IDE because STMs are more reliable.

Translated with www.DeepL.com/Translator (free version)

AScha.3
Chief II

>Shouldn't ST provide an APPNOTE on how to use their MCUs inside the Arduino IDE?

no. is not up to STM , what "Arduino" doing or not doing

i just can tell you, i had almost same problem: using a TFT , only in Arduino was a lib.

so i tried , in Arduino , include some defines and HAL access , to get ADC of STM doing, what i need.

no success.

then i tried, making a STM32 project, in stm32IDE, include the lib from Arduino; after some compile/see errors turns i had the variables and defines , and got "no errors" , program runs.

now i have the "nice" control over the chip, in stm32IDE, AND the lib. (for you: nrf24 lib .)

so i recommend : make STM32 project, include the lib from Arduino world, resolve the errors - and it works.

or - use lib like... : https://github.com/kehribar/nrf24L01_plus

or

https://nrf24.github.io/RF24/

If you feel a post has answered your question, please click "Accept as Solution".
audiex
Associate II

Ok, thanks for the tip. Let's be more professional: "give Arduino what is Arduino, and STM what is STM! Thank you and God bless you!