connect Simulink with Arduino using Simulink Arduino support package
조회 수: 2 (최근 30일)
이전 댓글 표시
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);
}
댓글 수: 0
답변 (1개)
colordepth
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).
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Arduino Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!