Error while operating on stepper motor

Hello,
I want to control stepper motor using matlab, arduino hardware and l293d driver.
I write simple code to supply the driver with appropriate pulses, the motor move but not in the correct way and the speed is fixed dispite of value of delay time between steps. this is the code below. I test the code in arduino ide it work fine and the stepper fully controlled, but i don't know why in matlab it doesn't work. any one help?

</

clear;
clc;
delay_time = 0.001; % delay time between steps

%% Initialize arduino pins
a = arduino("COM6","Mega2560");
configurePin(a,"D8","DigitalOutput");
configurePin(a,"D9","DigitalOutput");
configurePin(a,"D10","DigitalOutput");
configurePin(a,"D11","DigitalOutput");

%% move stepper motor step by step with delat time 1ms

while 1
% first step
writeDigitalPin(a,'D8',1)
writeDigitalPin(a,'D9',0)
writeDigitalPin(a,'D10',1)
writeDigitalPin(a,'D11',0)
pause(delay_time)
% second step
writeDigitalPin(a,'D8',0)
writeDigitalPin(a,'D9',1)
writeDigitalPin(a,'D10',1)
writeDigitalPin(a,'D11',0)
pause(delay_time)
% third step
writeDigitalPin(a,'D8',0)
writeDigitalPin(a,'D9',1)
writeDigitalPin(a,'D10',0)
writeDigitalPin(a,'D11',1)
pause(delay_time)
% 4th step
writeDigitalPin(a,'D8',1)
writeDigitalPin(a,'D9',0)
writeDigitalPin(a,'D10',0)
writeDigitalPin(a,'D11',1)
pause(delay_time)
end
/>

Why? Is this an academic exercise?

You can say that.

Try asking on a Matlab forum.

I tried but no one answering

You never said what is wrong. Just "doesn't work".

1 Like

It rotates so slowly about 5 rpm
And what ever i change the speed, the stepper still rotates at the some speed which is about 5 rpm

Also there is vibration during rotation

My guess, the Matlab Arduino core is very slow when performing digital I/O. I know nothing about variables in Matlab, your delay looks like a float type, you need to confirm the specifications of the pause() function.

I thought about that too. But i test the speed of matlab i/o on led blank. But it work fine

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.