2 problems with stepper motor control using arduino and Matlab GUI
4 ビュー (過去 30 日間)
古いコメントを表示
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

%
回答 (5 件)
darryl tan
2017 年 4 月 27 日
i face to same things also. Anyone know? the code can use but slow.
0 件のコメント
AGOUNAD Mohamed
2021 年 6 月 15 日
hello bro
I have the same problem. Did u find the solution???
please help me if u have a solution.
1 件のコメント
Evan Baker
2021 年 6 月 15 日
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!
コミュニティ
その他の回答 パワー エレクトロニクス コミュニティ
参考
カテゴリ
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!