Hi Zsombor,
To achieve continuous motor control independent of Simulink's sample time, you can use hardware interrupts or timers on the Arduino.
You can set up a timer interrupt on the Arduino to handle motor stepping.
For example, use the `TimerOne` library to configure a timer interrupt:
#include <TimerOne.h>
void setup() {
Timer1.initialize(1000); // Set timer to trigger every 1000 microseconds
Timer1.attachInterrupt(stepMotor); // Attach the ISR
}
void stepMotor() {
// Logic to step the motor
}
- This method provides precise timing for motor control and reduces dependency on Simulink's scheduling.
- During the initialization phase of the S-function (e.g., in the `mdlStart` function), configure the timer interrupt.
- This setup allows the motor control to be managed independently by the interrupt.
For more detailed guidance on generating interrupt service routines (ISRs), you can refer to the below MathWorks documentation: