필터 지우기
필터 지우기

Stepper motor programming on arduino using drv8825 on MATLAB

조회 수: 11 (최근 30일)
Rajbir Singh
Rajbir Singh 2020년 2월 20일
댓글: Conner Carriere 2021년 2월 17일
I am facing a problem while programming a stepper motor on arduino using drv8825 on MATLAB. The results are not same while programming on these 2 platforms.
On Arduino IDE its working as expected using the following code:
# define dirpin 2
# define stepPin 3
# define stepsPerRevolution 200
void setup() {
// Declare pins as output:
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void loop() {
// Set the spinning direction clockwise:
digitalWrite(dirPin, HIGH);
// Spin the stepper motor 1 revolution slowly:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(600);
digitalWrite(stepPin, LOW);
delayMicroseconds(600);
}
delay(600);
// Set the spinning direction counterclockwise:
digitalWrite(dirPin, LOW);
//Spin the stepper motor 5 revolutions fast:
for (int i = 0; i < stepsPerRevolution; i++) {
// These four lines result in 1 step:
digitalWrite(stepPin, HIGH);
delayMicroseconds(600);
digitalWrite(stepPin, LOW);
delayMicroseconds(600);
}
delay(600);
}
On MATLAB I have tried to program the same but results are not same as shown on Arduino, using the following code:
clear a
% Arduino Declaration
a = arduino('COM4', 'Uno');
StepPerRevolution = 200;
% Pin Configuration
configurePin(a,'D2','DigitalOutput'); %D2 = Direction pin
configurePin(a,'D3','DigitalOutput'); %D3 = Step pin
while true
writeDigitalPin(a,'D2',1);
for i = 0:StepPerRevolution
writeDigitalPin(a,'D3',1);
pause(0.0006);
writeDigitalPin(a,'D3',0);
pause(0.0006);
end
writeDigitalPin(a,'D2',0);
for i = 0:StepPerRevolution
writeDigitalPin(a,'D3',1);
pause(0.0006);
writeDigitalPin(a,'D3',0);
pause(0.0006);
end
end
Please help

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by