フィルターのクリア

Changing PWM frequency of Arduino board in a .m script

6 ビュー (過去 30 日間)
Matthew Tieu
Matthew Tieu 2022 年 11 月 29 日
コメント済み: Sarvesh Kale 2022 年 12 月 15 日
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.

採用された回答

Sarvesh Kale
Sarvesh Kale 2022 年 12 月 14 日
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 件のコメント
Matthew Tieu
Matthew Tieu 2022 年 12 月 14 日
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 2022 年 12 月 15 日
Hello Matthew,
You can take a look at the following documentation for this purpose

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by