2018年3月30日 星期五

Arduino+L298N+high toque stepper motor speed control mechanism 步進馬達控速 (240RPM to 45RPM)

    控制電路可以讓步進馬達不使用減速齒輪組的條件下,在二個不同的轉速之間切換(240~180RPM與90~30RPM之間)進行變速以避免L298N過熱與降低轉速時的震動,控制電路使用可變電阻與控制duty cycle的方式進行調速。控制電路使用一個Arduino UNO,一個L298N 馬達控制模組,一個電驛模組搭配組成開迴路的馬達轉速控制。使用12DCV與5DCV做為步進馬達的供電電壓。步進馬達的型號是PKP266D28A 東方馬達公司製造。這個變速方式的限制是,馬達軸上不能有反轉矩的力量。否則會因為馬達未激磁時沒有力量可以抵消反轉矩,這樣會造成反轉與劇烈震動的情況。另外這個程式的功能很單純只進行馬達的轉動控制。如果要處理器同時要處理其他的工作例如通訊等其他較為耗時的運算時,用來控制duty cycle 的機制也要進行改動與調整。熟悉Arduino 與步進馬達控制的人可以直接參考以下的電路與程式碼。

     Using relay to switch the motor supply voltage can be more easy to switch RPM in two ranges. using this method can avoid the L298N over heat and reduce the shaking when motor was under the low speed. The RPM of the stepper motor can be fine turn with a variable resistor and a ADC input. The control circuit is assemble by an Arduino UNO, a L298N motor driver, a single relay module, and a +5VDC/+12VDC dual output switching power.The part number of stepper motor is PKP266D28A. The following code is used to implement low RPM setting.

 在調速的部份與Arduino IDE 內建的example 不同的地方在於加入了Delay以及使用關閉電源的方式來降低馬達的平均驅動電流,以避免L298N過熱的狀況發生。程式中設定Delay 7ms 是為了讓馬達在90RPM的轉速設定下能夠完成2個steps的驅動,約需時6.6ms。

要降低馬達的轉速只需要增加iDelayTime的數值。馬達需要轉動2steps的時間增加等於馬達的轉速降低。

依程式的設定最低的轉速可以降至 100cycle * 57 ms = 5.7sec/rotate 約等於 60sec/5.7sec=10.52 rpm。

// set the motor speed:
digitalWrite(3,LOW);          // turn off the relay to supply +5VDC to stepper motor. myStepper.setSpeed(90);  // step 1/100 of a revolution:
myStepper.step(-stepsPerRevolution/100 );
// tow steps will take 1sec/(90rpm/60second*200steps) is about 3.3 ms per step. 
delay(7);         // Time windows for driving the motor for two steps 
// turn off the stepper motor supply power 
digitalWrite(8,LOW); 
digitalWrite(9,LOW); 
digitalWrite(10,LOW); 
digitalWrite(11,LOW);
int iDelaytime = map(iADCRead, 0, 1000, 1, 50);
delay(iDelaytime); // turn off duty time