Custom Function in MATLAB

Hi,

Since I couldn't find a way to change the frequency of PWM output in MATLAB, I want to write my own function in MATLAB. But I couldn't find a reliable source to get help.

Is there a way to write my own function to control Arduino's output in MATLAB?

Thanks!

An Arduino Uno is an ATmega328p, you may want to have a look at the datasheet.

https://www.microchip.com/wwwproducts/en/ATMEGA328P

It is a microcontroller that has an AVR core with some peripherals.

The PWM pins are done with output compare registers that cause modulation when some control bits are set correctly. Arduino has abstracted this for you into what they call analogWrite()

https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/

The way this abstraction works can be seen

Now if you want MATLAB (or any Windows/Mac/Linux program) to access those functions you have to write an Arduino program that runs on the ATmega328p and exposes the desired functions in a way that MATLAB can interface (e.g. over the serial port).