Fast PWM on Nucleo-F030R8 with Arduino IDE

STM32F103 Nucleo boards e.g. STM Nucleo F103RB
sabra
Posts: 2
Joined: Wed Aug 02, 2017 7:24 pm

Fast PWM on Nucleo-F030R8 with Arduino IDE

Post by sabra » Thu Aug 03, 2017 12:30 pm

Hello,

I have a Nucleo-F030R8 development board and upon using the analogWrite() function within the Arduino IDE I have found the frequency of my PWM to be just under 1KHz. I would like to increase the frequency to 20KHz, does anyone have any experience or suggestions on how to do this?

Thanks

User avatar
Rick Kimball
Posts: 989
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: Fast PWM on Nucleo-F030R8 with Arduino IDE

Post by Rick Kimball » Thu Aug 03, 2017 1:01 pm

You will find that the ST core (https://github.com/stm32duino/Arduino_Core_STM32) to be a vanilla port. It sticks pretty close to the functions available from the original Arduino core.

You could try changing the variant.h file

https://github.com/stm32duino/Arduino_C ... iant.h#L62

The define "PWM_FREQUENCY" controls the frequency of analogWrite()
-rick

fpiSTM
Posts: 175
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Fast PWM on Nucleo-F030R8 with Arduino IDE

Post by fpiSTM » Thu Aug 03, 2017 1:06 pm

Hi Sabra,

PWM_FREQUENCY is set to 1000.
If you want to change it, you need to modify it in the variant: variants/NUCLEO_F030R8/variant.h

I've tested and set 20000 for the F030 on D5 (PB4, TIM3). I get 20.8KHz.

sabra
Posts: 2
Joined: Wed Aug 02, 2017 7:24 pm

Re: Fast PWM on Nucleo-F030R8 with Arduino IDE

Post by sabra » Thu Aug 03, 2017 1:38 pm

Thanks for the quick responses! Worked flawlessly :D

fpiSTM
Posts: 175
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Fast PWM on Nucleo-F030R8 with Arduino IDE

Post by fpiSTM » Thu Aug 03, 2017 2:22 pm

Welcome.
It could be fine to extend Arduino API to allow change the Frequency.

victor_pv
Posts: 1603
Joined: Mon Apr 27, 2015 12:12 pm

Re: Fast PWM on Nucleo-F030R8 with Arduino IDE

Post by victor_pv » Fri Aug 04, 2017 3:26 am

I hope you are not waiting on the Arduino team to do so, otherwise you'll wait for a long time ;)

fpiSTM
Posts: 175
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Fast PWM on Nucleo-F030R8 with Arduino IDE

Post by fpiSTM » Fri Aug 04, 2017 7:59 am

No, it's planned to extend API.
Compare to AVR, STM32 offers more functionalities/capabilities ;)

User avatar
RogerClark
Posts: 6691
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Fast PWM on Nucleo-F030R8 with Arduino IDE

Post by RogerClark » Fri Aug 04, 2017 10:40 am

Frederic

BTW.

Initially I did ask whether the Arduino team would be willing to add new functions to support newer hardware, but they were not interested.
They seem very focused on the AVR hardware, and do not seem willing to add optional extensions to the API.

So we just added new features even though they are never going to be supported by the core of Arduino (e.g. AVR or SAM etc).

fpiSTM
Posts: 175
Joined: Fri Sep 16, 2016 12:33 pm
Location: Le Mans, France

Re: Fast PWM on Nucleo-F030R8 with Arduino IDE

Post by fpiSTM » Fri Aug 04, 2017 11:59 am

Right Roger.
Arduino do not like change or add API aven if they add new arch (i.e Otto based on an stm32f4), i'm experiencing the wall they raised :mrgreen:

So based on all user input, we will add useful API.

User avatar
RogerClark
Posts: 6691
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Fast PWM on Nucleo-F030R8 with Arduino IDE

Post by RogerClark » Fri Aug 04, 2017 12:47 pm

Cool...

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest