MATLAB Answers

HARIS
2

How to change PWM Frequency of Arduino USING MATLAB SIMULINK Support package

Asked by HARIS
on 11 Jun 2014
Latest activity Answered by Greg Wolff on 15 Aug 2019
Hello,
i have problem with my project. I use Arduino uno and Simulink. For the control i need a PWM signal with 3000 Hz - 5000 Hz but the Simulink support package (PWM) has only 490 Hz and i can change only the duty-cycle.
What can I do?
I would welcome your response

  13 Comments

Hi all...I am also facing same issue to set PWM frequency for MATLAB support package of Arduino..I am using 2017b...how to solve this in MATLAB model (Not Simulink)?..could you please share?
Facing the same issue, I am not able to generate more than 1 KHz PWM for arduino in simulink as well as in matlab code. Can anyone help in this regard?
I had quite the same problem (needed 5 - 25 kHz for my DC-motor to work), so I wrote my own S-function, which I will attach.
By using a prescaler of 8 for the timer 2, the outcoming frequency at D3 and D11 is approximately 7.8 kHz. You can also use a prescaler of 1 (to get 62.5 kHz) or 64 (to get 980 Hz), if you take a look inside the S-function -> Start --> TCCR2B.
You'll also need the following requirements for the simulink-model in order to work:
  • Arduino Uno
  • Matlab R2019a or newer
  • Add-Ons: Matlab+Simulink Support for Arduino, MinGW-w64 C/C++ Compiler
  • run in "External"-mode, Simulation stop time: "inf"
I hope this will help you with your project.
Best regards

Sign in to comment.

1 Answer

Answer by Greg Wolff on 15 Aug 2019

You cannot change the PWM frequency of the PWM block found in the Arduino hardware support package.
You can however create custom device driver blocks. There is a good resource here:
that has various examples, all built around supporting Arduino boards.

  0 Comments

Sign in to comment.