|
背景:想要使得步进电机每分钟4转,通过设置驱动器拨码开关得到电机每转脉冲为1600,这样算得每个脉冲的延续时间即为60/(4*1600),高低电平各是它的一半,为4688us,但是通过arduino写入程序,程序如图一所示,电机无法启动。若将motorRotationSpeed函数中的time变量变成50us,则可以正常启动,笔者试验过几次,直到80us时也还可以正常启动,但到100us就堵转了,请教各位大神,这到底是怎么回事?有什么解决办法呢?被此问题折磨好几天了...
程序中,PUL_1接步进电机PUL-端,DIR_1接DIR-端子。
- int PUL_1=2;
- int DIR_1=4;
- void setup() {
- // put your setup code here, to run once:
- pinMode(DIR_1,OUTPUT);
- pinMode(PUL_1,OUTPUT);
- }
- void motorRotationSpeed(unsigned long stepMotorResolution,unsigned int time)
- {
-
-
- while(stepMotorResolution>=0)
- {
- digitalWrite(PUL_1,HIGH);
- delayMicroseconds(time);
- digitalWrite(PUL_1,LOW);
- delayMicroseconds(time);
- stepMotorResolution--;
- }
- }
- void loop() {
- // put your main code here, to run repeatedly:
- digitalWrite(DIR_1,HIGH);
- int i;
- for(i=1;i<=90;i++)
- {
- motorRotationSpeed(1600,50*i);
- delay(1000);
- }
-
- while(1)
- {
- motorRotationSpeed(1600,4688);
- }
- }
复制代码 |
|