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개)
커뮤니티
더 많은 답변 보기: Power Electronics Community
참고 항목
카테고리
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!