2 problems with stepper motor control using arduino and Matlab GUI

24 views (last 30 days)
hi everyone, i'm doing now a project about stepper motor controlling with Arduino and Matlab GUI. The 2 main tasks are: able to change the direction and speed of the motor. Hardwares are Stepper Motoe; motor controller L297;Arduino Mega 2560.
What i have successfully done at this point are: 1.i wrote the matlab GUI code(not finish jet) which is successfully connectedwith Arduino broad 2.i do can control the stepper motor using the GUI code, but the stepper motor rotates very slow.
two Problems are: 1. the stepper motor rotates very slow compared to using arduino IDE with same code. I searched pretty much about this problem. the reason may be: Matlab GUI reacts much slower (the time between 2 steps is smaller, the motor rotates quicker). And i tested the time between 2 steps on matlab GUI, it's 0.002-0.018 second, approximately 20 times than arduino 2. how to write the slider code to change the speed? Or how to achieve controlling speed on GUI?
here are two parts of the code:
function steppermotor_OpeningFcn(hObject, eventdata, handles, varargin)
clear all;
global a;
a = arduino('COM7');
a.pinMode(5,'output');
a.pinMode(6,'output');
function pushbutton1_Callback(hObject, eventdata, handles)
global a;
a.digitalWrite(6,1);
pauseje2Schritte = 0.00001; %pause between 2 steps
zahlderSchritte= 200; %number of steps
for x = 1:zahlderSchritte
a.digitalWrite(5,1);
tic;
pause(0.000001);
toc
a.digitalWrite(5,0);
tic;
wait(1);
toc
and here ist the GUI surface
%

Answers (5)

jameyao
jameyao on 9 Aug 2016
Does anybody help me, i'm really need help.

Atacan Tosun
Atacan Tosun on 15 Dec 2016
I have the same problem(1). Did you find the solution???

ghazal mohamed
ghazal mohamed on 7 Jan 2017
I am in the same situation does anyone have an idea??

darryl tan
darryl tan on 27 Apr 2017
i face to same things also. Anyone know? the code can use but slow.

AGOUNAD Mohamed
AGOUNAD Mohamed on 15 Jun 2021
hello bro
I have the same problem. Did u find the solution???
please help me if u have a solution.
  1 Comment
Evan Baker
Evan Baker on 15 Jun 2021
Hey Mohamed,
The solution is to not use Matlab in this way. Matlab is way too slow to run high frequency operations that are needed to control a stepper motor. You can use a PWM rather than just writing the signals to the pins, but this is a much more complicated process than just using Arduino IDE which can run signifigantly faster. Also, the pause() function can only operate as low as around 1 ms so its pointless to use pause(0.000001);.
I hoped this helped. TLDR: use arduino IDE for anything high frequency and you should be smooth sailing!

Sign in to comment.

Communities

More Answers in the  Power Electronics Control

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!