// DVDスピンドルの3相アナログ駆動テスト // 20221230_3PhaseSteppingMoter #define MAG_POW 70 // 励磁パワー (0-120の値で指定) void setup() { Serial.begin(115200); angle(0, 5000); delay(1000); } void loop() { // Serial.println(millis()); for (int a = 0; a < 360 * 12; a += 1) { angle(a, 400); // 角度a に移動して指定時間待機 } delay(1000); for (int a = 360 * 12; a > 0; a -= 1) { angle(a, 400); } delay(1000); } void angle(int a, int tt) { // 指定された位相でコイルを駆動.位相は度の値で指定 int r, s, t; float pow_r, pow_s, pow_t; pow_r = cos(PI * a / 180.0); // 駆動位相をラジアンに変換 pow_s = cos(PI * (a + 120 ) / 180.0); // +120度 pow_t = cos(PI * (a - 120 ) / 180.0); // -120度 r = (pow_r * MAG_POW) + 125; // 振幅125±120でスイング(255近傍は怪しいので避ける) s = (pow_s * MAG_POW) + 125; t = (pow_t * MAG_POW) + 125; analogWrite( 9, r); // アナログ(PWM)出力 analogWrite(10, s); analogWrite(11, t); delayMicroseconds(tt); Serial.print(r); Serial.print(", "); Serial.print(s); Serial.print(", "); Serial.println(t); }