Stepper motor programming on arduino using drv8825 on MATLAB
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
1 commentaire
Réponses (0)
Voir également
Catégories
En savoir plus sur Animation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!