2 problems with stepper motor control using arduino and Matlab GUI
30 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
%
1 comentario
Respuestas (5)
Atacan Tosun
el 15 de Dic. de 2016
I have the same problem(1). Did you find the solution???
0 comentarios
ghazal mohamed
el 7 de En. de 2017
I am in the same situation does anyone have an idea??
0 comentarios
darryl tan
el 27 de Abr. de 2017
i face to same things also. Anyone know? the code can use but slow.
0 comentarios
AGOUNAD Mohamed
el 15 de Jun. de 2021
hello bro
I have the same problem. Did u find the solution???
please help me if u have a solution.
1 comentario
Evan Baker
el 15 de Jun. de 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!
Comunidades de usuarios
Más respuestas en Power Electronics Control
Ver también
Categorías
Más información sobre Arduino Hardware en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!