フィルターのクリア

Error while operating stepper motor

5 ビュー (過去 30 日間)
safaa al-hafar
safaa al-hafar 2021 年 11 月 3 日
回答済み: Shreshth 2024 年 7 月 16 日 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

回答 (1 件)

Shreshth
Shreshth 2024 年 7 月 16 日 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.

カテゴリ

Help Center および File ExchangeArduino Hardware についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by