Changing PWM frequency of Arduino board in a .m script

36 vues (au cours des 30 derniers jours)
Matthew Tieu
Matthew Tieu le 29 Nov 2022
Commenté : Sarvesh Kale le 15 Déc 2022
Hi all,
As you might know, the PWM frequency of an Arduino board can be changed by adding code to a S-function builder block in Simulink. However, I prefer using a .m script when possible since it runs faster than Simulink. When I check the website: https://au.mathworks.com/help/supportpkg/arduinoio/ref/writepwmvoltage.html, it seems there is no way to specify the PWM frequency. Is there a function in the MATLAB Arduino library which can control the PWM frequency? Thanks in advance.

Réponse acceptée

Sarvesh Kale
Sarvesh Kale le 14 Déc 2022
Hello Matthew,
As per my understanding you are trying to change to PWM frequency on the Arduino Uno board and looking for a MATLAB built-in function to do that. There is no built-in function to change the frequency however you have the following functionality available to you.
  • Using writePWMDutyCycle, you can change the PWM duty cycle. More information can be obtained by executing help writePWMDutyCycle on MATLAB prompt. The help information displays the inputs to writePWNDutyCycle function.
  • To get a list of available function use help arduino
  2 commentaires
Matthew Tieu
Matthew Tieu le 14 Déc 2022
Hi Sarvesh,
Thank you for responding back. Since there is no explicit function, can pieces of code from other languages be included in a .m script (similar to C Function Builder in Simulink)? I know in the Arduino language, the code below changes the PWM frequency from 490 Hz to 7812.5 Hz.
TCCR0B = (TCCR0B & 0b11111000) | 0b00000010; // Sets clock divisor to 8 on register B
Sarvesh Kale
Sarvesh Kale le 15 Déc 2022
Hello Matthew,
You can take a look at the following documentation for this purpose

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Arduino Hardware dans Help Center et File Exchange

Produits


Version

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by