How to change pulse width modulation FREQUENCY of arduino analog pins with new support package for R2014b?

14 次查看(过去 30 天)
I need to change the pulse-width modulation FREQUENCY (not the duty cycle) of the arduino analog pins for my applications. With the previous arduinoio package for matlab ( http://www.mathworks.com/matlabcentral/fileexchange/32374-matlab-support-for-arduino--aka-arduinoio-package-), one had to upload the sketch to the arduino manually, but the advantage was that this enabled the user to add some lines to the setup() function in the sketch that would change the PWM frequency of the pins.
The R2014b matlab support package for arduino (<http://www.mathworks.com/matlabcentral/fileexchange/47522-matlab-support-package-for-arduino%C2%AE-hardware>) replaces the existing sketch on the arduino by an auto-generated one upon executing the command arduino(port) and I have no control over what's actually being uploaded to the arduino.
Can anyone tell me, how to change the PWM frequencies with new package?
Thanks so much! Wolfgang

回答(3 个)

Martin Egginton
Martin Egginton 2015-12-25
You can add a S-function builder block on the sketch to include custom code to be run either in setup() or loop().
I think you should then be able to use the code you used in the previous package.
Best Regards, Martin

Ahmet yüksel
Ahmet yüksel 2016-11-28
ı want to change arduino pwm freqaucny in MATLAB SIMULINK, how to do this, thank you a lot..
  1 个评论
pallab choudhury
pallab choudhury 2018-6-13
@ Ahmet yüksel ...did you find the solution?..I am also facing same issue to set PWM frequency for MATLAB support package of Arduino..I am using 2017b...could you please share for MATLAB model (Not Simulink)?..Thanks

请先登录,再进行评论。


HARIS
HARIS 2014-11-23
Dear Wolfgang can you tell me how to change the pwm frequency in the previous support package you are talking about, as i need it very urgent for my project and i tried a lot to change it with the previous package but couldnt succeed. can you send me one example. Thanks alot
  1 个评论
Wolfgang
Wolfgang 2014-11-24
You only have to a couple of lines to the void setup() function in adio.pde, adioe.pde or adioes.pde sketch, depending on what arduino you are using. These sketches are provided with the old version of the arduinoio package for releases earlier than R2014b. Instructions on what to add to the void setup() function are given here (arduino mega 2560, but uno is very similar)
I was not able to save the modified .pde sketch (the software wants to change the ending of the file and after that matlab doesn't recognize the sketch anymore) so I just added the lines and uploaded the sketch to the arduino without saving and it worked.
NOTE: I did not try to change the PWM frequency dynamically during execution of my program because I didn't need that. This would require some more serious digging into the arduinoio sketches.
Hope that helps!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by