How do I set the Motor Speed with an Arduino with no Adafruit-Shield?

1 回表示 (過去 30 日間)
Hieu Philip Hoang
Hieu Philip Hoang 2018 年 12 月 5 日
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 件)

コミュニティ

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by