How do I set the Motor Speed with an Arduino with no Adafruit-Shield?
1 次查看(过去 30 天)
显示 更早的评论
Hey guys!
I am using an arduino to control a bipolar stepper motor with MATLAB. I don't use the normal Adafruit Motorshield, but another with an H-bridge.
In Arduino IDE, to move the motor I basically let following functions running, which where given in the data sheet (in C)
while true{
backward();
delay(x);
right();
delay(x);
forward();
delay(x);
left();
delay(x);
}
where x is the delaytime. These functions (backward(), right(),...) set the different Pins of the Arduino to either 0 or 1, to control the coils inside the stepper.
So for example the backward() function looks like this:
void backward()
{
digitalWrite(pinI4,LOW);
digitalWrite(pinI3,HIGH);
digitalWrite(pinI2,HIGH);
digitalWrite(pinI1,LOW);
}
or in MATLAB:
writeDigitalPin(a,'D13',0);
writeDigitalPin(a,'D12',1);
writeDigitalPin(a,'D11',1);
writeDigitalPin(a,'D8',0);
The delay function is needed to adjust the PWM frequency, which then controls the speed of the stepper, how I suggest. The function stops running the programm for exactly the time written inside it. In Arduino IDE it works perfectly for x = 3.5, which is 3.5ms.
Now, I wrote the exact same code translated into MATLAB, where I encounter major problems with the speed.
There, even though I set the delaytime to exactly the same, the motor doesn't run as fast as with the C-programm. Additionaly, it doesn't run fluently, but more like stumbles while running. The code I wrote basically just looks alike, only adjusted to MATLAB syntax.
As I spectated, I suggest, that MATLAB doesn't write the bits onto the pins as fast as Arduino IDE. So my question is, is there any way to tell MATLAB to run the commands faster? Or does anybody know how to set the speed higher?
Very much thanks for reading!
Kind regards
0 个评论
回答(0 个)
社区
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Arduino Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!