本帖最后由 黑之灯 于 2019-2-3 18:15 编辑
已知经过测定,那个1000比的减速箱是1 : 1012.5,恒星速度约86160秒一周 那么电机蜗杆速度就应该是85.096秒一周,步进电机是3.75°,96步一周,所以每一步应该是886.42毫秒。就有下面程序
int a = 2; //定义一个参数a作为a+,a+为接口2 int aa = 3; //定义一个参数aa作为a-,a-为接口3 int b = 4; //定义一个参数b作为b+,b+为接口4 int bb = 5; //定义一个参数bb作为b-,b-为接口5 int ms = 886; //定义ms毫秒 int us = 420; //定义us微秒
void setup() { pinMode(a, OUTPUT); //a接口为输出 pinMode(aa, OUTPUT);//aa接口为输出 pinMode(b, OUTPUT); //b接口为输出 pinMode(bb, OUTPUT);//bb接口为输出 }
void loop() //电极循环 { digitalWrite(a, HIGH); //a+接正 digitalWrite(aa, LOW); digitalWrite(b, LOW); digitalWrite(bb, LOW); delay(ms); //延时毫秒 delayMicroseconds(us); //补偿延时微秒
digitalWrite(a, LOW); digitalWrite(aa, LOW); digitalWrite(b, HIGH); //b+接正 digitalWrite(bb, LOW); delay(ms); delayMicroseconds (us);
digitalWrite(a, LOW); digitalWrite(aa, HIGH); //a-接正 digitalWrite(b, LOW); digitalWrite(bb, LOW); delay(ms); delayMicroseconds (us);
digitalWrite(a, LOW); digitalWrite(aa, LOW); digitalWrite(b, LOW); digitalWrite(bb, HIGH); //b-接正 delay(ms); delayMicroseconds (us); }
不过由于步进电机可以半步工作,比如两个电极同时通电 这样一步就只有443.21毫秒
int a = 2; //定义一个参数a作为a+,a+为接口2 int aa = 3; //定义一个参数aa作为a-,a-为接口3 int b = 4; //定义一个参数b作为b+,b+为接口4 int bb = 5; //定义一个参数bb作为b-,b-为接口5 int ms = 443.21; //定义ms毫秒 int us = 210; //定义us微秒
void setup() { pinMode(a, OUTPUT); //a接口为输出 pinMode(aa, OUTPUT);//aa接口为输出 pinMode(b, OUTPUT); //b接口为输出 pinMode(bb, OUTPUT);//bb接口为输出 }
void loop() //电极循环 { digitalWrite(a, HIGH); //a+接正 digitalWrite(aa, LOW); digitalWrite(b, LOW); digitalWrite(bb, LOW); delay(ms); //延时毫秒 delayMicroseconds (us); //补偿延时微秒
digitalWrite(a, HIGH); //a+接正 digitalWrite(aa, LOW); digitalWrite(b, HIGH); //b+接正 digitalWrite(bb, LOW); delay(ms); delayMicroseconds (us);
digitalWrite(a, LOW); digitalWrite(aa, LOW); digitalWrite(b, HIGH); //b+接正 digitalWrite(bb, LOW); delay(ms); delayMicroseconds (us);
digitalWrite(a, LOW); digitalWrite(aa, HIGH); //a-接正 digitalWrite(b, HIGH); //b+接正 digitalWrite(bb, LOW); delay(ms); delayMicroseconds (us);
digitalWrite(a, LOW); digitalWrite(aa, HIGH); //a-接正 digitalWrite(b, LOW); digitalWrite(bb, LOW); delay(ms); delayMicroseconds (us);
digitalWrite(a, LOW); digitalWrite(aa, HIGH); //a-接正 digitalWrite(b, LOW); digitalWrite(bb, HIGH); //b-接正 delay(ms); delayMicroseconds (us);
digitalWrite(a, LOW); digitalWrite(aa, LOW); digitalWrite(b, LOW); digitalWrite(bb, HIGH); //b-接正 delay(ms); delayMicroseconds (us);
digitalWrite(a, HIGH); //a+接正 digitalWrite(aa, LOW); digitalWrite(b, LOW); digitalWrite(bb, HIGH); //b-接正 delay(ms); delayMicroseconds (us);
}
不懂代码意思也不要紧,只要复制到Arduino ide就可以下载到单片机
等程序下载到单片机,然后就可以按照前面的接线方式连接,就可以看到电机转动了,又或者可以在单片机的2345引脚上,接LED观察是否正常工作
|