connect Simulink with Arduino using Simulink Arduino support package

1 回表示 (過去 30 日間)
ahmad salahat
ahmad salahat 2024 年 12 月 18 日
回答済み: Deep 2024 年 12 月 20 日
im using simulink arduino suppport packge and i wrote a code in arduino which generate a pwm signal as shown below in the code so, iam tring to get the pwm signal to simulink to control a mosfet so, the code of the arduino will be the controller, so how to get this singal and connected to the mosfet gate
the code:
int motorPin = 9; //Set pin 9 as motor control pin
void setup() {
pinMode(motorPin, OUTPUT); //Set Motor control pin as output Pin
Serial.begin(9600); //Start Serial Communications
}
void loop() {
analogWrite(9, 64);
delay(2000);
analogWrite(9, 0);
delay(2000);
}

回答 (1 件)

Deep
Deep 2024 年 12 月 20 日
Communicating with pins on an Arduino from Simulink is typically done using Connected IO mode, which you can learn more about at https://www.mathworks.com/help/simulink/supportpkg/arduino_ug/connected-io.html. This involves a one-time deployment of an IO server that will overwrite your existing C++ code. Therefore, I suggest modelling your C++ logic in Simulink to use it for your MOSFET implementation.
To get you started, your C++ logic generates a PWM signal equivalent to a square wave with a width of 2 seconds and a period of 4 seconds. You can replicate this behaviour using the "Pulse Generator" block in Simulink (https://www.mathworks.com/help/simulink/slref/pulsegenerator.html). Once modelled, you can pass this signal to an "Analog Output" block for Arduino (https://www.mathworks.com/help/simulink/supportpkg/arduino_ref/analogoutput.html).

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by