Velocidad Motor paso a paso Nema 17 con Driver L293D en Matlab

7 次查看(过去 30 天)
Buen dia
Estamos implementando la conexion de un motor nema 17 con driver L293 en Matlab pero en el momento de correr el codigo es lento
Se realiza la prueba en Arduino y funciona bien pero en matlab resulta lento
el motor se encuentra probado, al igual que el driver
se tiene la secuencia de funcionamiento de las bobinas Probada
pero hay un conflicto con la velocidad al momento de subirlo en matlab (Envia las Señales con un intervalo de tiempo muy lento aprox 1 segundo entre pasos)
le estaria muy agradecido si fuera posible responder la duda.
Adjunto el codigo:
function Paso_a_Paso(Pos_Sig)
global ARD; global BASE;
if Pos_Sig>BASE
DIR=0;
Pasos=((Pos_Sig-BASE)*8);
end
if Pos_Sig<BASE
DIR=1;
Pasos=((BASE-Pos_Sig)*8);
end
steps={'1010', '0010', '0110', '0100', '0101', '0001', '1001' ,'1000'}; %SECUENCIA
if DIR==1
for(p=0:1:Pasos)
for (i = 1:1:8)
step = steps{i}; % step=1,2,3,4
writeDigitalPin(ARD,'D8' ,str2double(step(1)));
writeDigitalPin(ARD,'D9' ,str2double(step(2)));
writeDigitalPin(ARD,'D10' , str2double(step(3)));
writeDigitalPin(ARD,'D11' ,str2double(step(4)));
end
end
end
if DIR==0
for(p=0:1:Pasos)
for (i = 8:1:1)
step = steps{i}; % step=1,2,3,4
writeDigitalPin(ARD,'D8' ,str2double(step(1)));
writeDigitalPin(ARD,'D9' ,str2double(step(2)));
writeDigitalPin(ARD,'D10' , str2double(step(3)));
writeDigitalPin(ARD,'D11' ,str2double(step(4)));
end
end
end
BASE=Pos_Sig;
writeDigitalPin(ARD,'D8' ,0);
writeDigitalPin(ARD,'D9' ,0);
writeDigitalPin(ARD,'D10' , 0);
writeDigitalPin(ARD,'D11' ,0);
end
Gracias y buen dia

回答(1 个)

Karan Singh
Karan Singh 2025-2-1
I translated your text and noticed that you’ve been facing performance issues related to your MATLAB code. There are a few suggestions that might help.
Loops in MATLAB can be slow, which is why the process of vectorization is preferred over traditional "for" loops. You can read more about this in the documentation, which clearly states the performance benefits: MATLAB Vectorization.
Another optimization would be to reduce the number of communications between MATLAB and the Arduino. Instead of sending individual signals for each step, consider sending a batch of steps and letting the Arduino handle the timing. These optimizations might help resolve your performance issues.
Karan

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB Support Package for Arduino Hardware 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by