Azzera filtri
Azzera filtri

Error while operating stepper motor

5 visualizzazioni (ultimi 30 giorni)
safaa al-hafar
safaa al-hafar il 3 Nov 2021
Risposto: Shreshth il 16 Lug 2024 alle 6:37
Hello,
I want to control stepper motor using matlab, arduino hardware and l293d driver.
I write simple code to supply the driver with appropriate pulses, the motor move but not in the correct way and the speed is fixed dispite of value of delay time between steps. this is the code below. I test the code in arduino ide it work fine and the stepper fully controlled, but i don't know why in matlab it doesn't work. any one help
clear;
clc;
delay_time = 0.001; % delay time between steps
%% Initialize arduino pins
a = arduino("COM6","Mega2560");
configurePin(a,"D8","DigitalOutput");
configurePin(a,"D9","DigitalOutput");
configurePin(a,"D10","DigitalOutput");
configurePin(a,"D11","DigitalOutput");
%% move stepper motor step by step with delat time 1ms
while 1
% first step
writeDigitalPin(a,'D8',1)
writeDigitalPin(a,'D9',0)
writeDigitalPin(a,'D10',1)
writeDigitalPin(a,'D11',0)
pause(delay_time)
% second step
writeDigitalPin(a,'D8',0)
writeDigitalPin(a,'D9',1)
writeDigitalPin(a,'D10',1)
writeDigitalPin(a,'D11',0)
pause(delay_time)
% third step
writeDigitalPin(a,'D8',0)
writeDigitalPin(a,'D9',1)
writeDigitalPin(a,'D10',0)
writeDigitalPin(a,'D11',1)
pause(delay_time)
% 4th step
writeDigitalPin(a,'D8',1)
writeDigitalPin(a,'D9',0)
writeDigitalPin(a,'D10',0)
writeDigitalPin(a,'D11',1)
pause(delay_time)
end

Risposte (1)

Shreshth
Shreshth il 16 Lug 2024 alle 6:37
Hey Safaa,
It appears that u are looking to control stepper motor using MATLAB and L293D driver.
MATLAB handles the timing and digital pin writing compared to the Arduino IDE. MATLAB might not be able to achieve the precise timing required for controlling the stepper motor, resulting in the motor not moving correctly or at a fixed speed regardless of the delay time.
I would recommend you to install the support package for ardunio hardware and then try to control the motor.
You can use L293D motor block controls to control the motor.
Kindly refer to the below mentioned resources from MathWorks to understand about the support package and controlling motor using Arduino board.
Hope it helps.

Categorie

Scopri di più su Arduino Hardware in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by