Azzera filtri
Azzera filtri

Changing PWM frequency of Arduino board in a .m script

6 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Sarvesh Kale
Sarvesh Kale il 14 Dic 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 Commenti
Matthew Tieu
Matthew Tieu il 14 Dic 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

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Arduino Hardware in Help Center e File Exchange

Prodotti


Release

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by