2 problems with stepper motor control using arduino and Matlab GUI

조회 수: 8 (최근 30일)
jameyao
jameyao 2016년 8월 8일
댓글: Eng Omar 2023년 1월 17일
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개)

jameyao
jameyao 2016년 8월 9일
Does anybody help me, i'm really need help.

Atacan Tosun
Atacan Tosun 2016년 12월 15일
I have the same problem(1). Did you find the solution???

ghazal mohamed
ghazal mohamed 2017년 1월 7일
I am in the same situation does anyone have an idea??

darryl tan
darryl tan 2017년 4월 27일
i face to same things also. Anyone know? the code can use but slow.

AGOUNAD Mohamed
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
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!

댓글을 달려면 로그인하십시오.

커뮤니티

더 많은 답변 보기:  Power Electronics Community

카테고리

Help CenterFile Exchange에서 Arduino Hardware에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by