Borrar filtros
Borrar filtros

Changing PWM frequency of Arduino board in a .m script

6 visualizaciones (últimos 30 días)
Matthew Tieu
Matthew Tieu el 29 de Nov. de 2022
Comentada: Sarvesh Kale el 15 de Dic. de 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.

Respuesta aceptada

Sarvesh Kale
Sarvesh Kale el 14 de Dic. de 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 comentarios
Matthew Tieu
Matthew Tieu el 14 de Dic. de 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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Arduino Hardware en Help Center y File Exchange.

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by