stepper motor (bipolar motor driving) library and sample codes

このページはまだ未公開.書きかけでーす!

このページは日本語でも記載されています.日本語版はこのページ後半をご覧ください. This page is written in Japanese as well. Please find it in 2nd half of this page.

What is this?

A class library and its sample code for the stepper (stepping) motor drive.

The mbed drives a stepper motor but a motor driver chip. Because the mbed cannot drive the motor directly which does not have enough current capacity.

The stepper motor can be driven with two signals with appropriate phase pulse sequence. This library let the mbed to generate those signals.

Next picture is a simplified model of the stepper motor operation (simplified to explain the mechanism easer). You can see the switching of coil current direction in each timings makes the rotor turn. The mbed with this library manages these signal timing and phase. The example of this picture has only 4 position (angle) in one rotation (in two phase operation) but actual motor has more position when the signals making one of those phase.

Code :

The code is available as a library : StepperMotor

And sample codes are available.

Just a simple code to operate one motor: StepperMotor_HelloWorld

Bit complex sample is also available that operates 3 stepper motors simultaneously : AnalogClock_StepperMotor_NTP

This analog clock demo is a code which has been demonstrated in Make: Tokyo Meeting 06 (@Tokyo Institute of Technology on 20 & 21 Nov 2010). It demonstrates the stepper motors and NTP access capability via internet connection. The NTP access code is from http://mbed.org/users/nucho/programs/SimpleLCDClock/ .

#include "mbed.h"
#include "StepperMotor.h"

BusOut          leds( LED4, LED3, LED2, LED1 );
StepperMotor    m( p21, p22, p23, p24 );

int main() {
    m.set_sync_mode( StepperMotor::SYNCHRONOUS );
    m.set_power_ctrl( true );

    while ( 1 ) {
    
        leds    = 1;
        m.go_angle( 120 );
        wait( 0.5 );

        leds    = 2;
        m.go_angle( 240 );
        wait( 0.5 );

        leds    = 3;
        m.go_angle( 0 );
        wait( 0.5 );

        leds    = 4;
        m.go_angle( 240 );
        wait( 0.5 );

        leds    = 5;
        m.go_angle( 120 );
        wait( 0.5 );

        leds    = 6;
        m.go_angle( 0 );
        wait( 0.5 );
    }
}

Hardware :

Supply:

To simplify the hardware configuration, it uses only one power supply from USB bus (from mbed's VU output). The USB supply should be taken from root hub (USB ports on a PC) or self power hub. If bus power hub is used for the supply, it may have problem of the current capacity (self powered hub: >500mA/port, bus powered hub: = 100mA/port).

If the motor doesn't have enough torque, higher voltage supply can be applied on motor power supply pins on the TA7774PG (pins 9 and 16).

Stepper motor:

The motor I could buy was a Copal SPG20-332. It's not a bipolar motor but it may be OK to use as an bipolar. The unipolar motor has a middle point of each coils but just ignoring this connection, it can be used as a bipolar motor.

Signals:

In figure above, the signalA and the signalB are necessary for the motor operation. Other 2 signals (Power control output and Position sensor input) are option. The power control is a signal to the TA7774PG that controls the POWER-OFF(Low) and OPERATION(High) on Vs2_b pin (pin8). The Vs2_b pin has a pull up resister because this signal is an option. The pull-up resister ensures that the pin has High state if it is not connected any control output. The power control can be enabed by set_power_ctrl( true ). It makes power control signal low (POWER-OFF) when no motor turn required.

An option input is available called position_detect (position sensor input). This can be used for the sensor (output of a photointerruptor, etc.) input to detect home position of the motor. User can set the edge of rise or fall for the detection. When the find_home_position( StepperMotor::RISING_EDGE | StepperMotor::FALLING_EDGE ) called, it starts to turn the motor (1 rotation). And then when the defined signal edge detected, the motor is stopped and the home position will be set to current position.

Note:

Multiple motor operation:

Multiple motors can be used. The analog clock applicaition shows a sample of 3 hands (hour, minute and second) clock driven stepper motors.

StepperMotor    m_s( p21, p22, p23, p30 );  //  motor for second
StepperMotor    m_m( p24, p25, p26, p30 );  //  motor for minute
StepperMotor    m_h( p27, p28, p29, p30 );  //  motor for hour

Since the position_detect (position sensor input) is an input, it can be shared by multiple sensors [THIS IS NOT TESTED, SORRY]. But if the sensor shared configuration taken, the find_home_position() should be done one after the other (or sensor sharing declaration may be good if you don't use the sensors).

Operation modes:

There are several modes and settings for operation. The functions of set_sync_mode() and set_rot_mode() are for SYNC, ROTATE mode setting. With set_pps() function, the motor speed can be controlled.

set_sync_mode( StepperMotor::SYNCHRONOUS | StepperMotor::ASYNCHRONOUS ) sets the motor operation synchronised to the program execution or not. Three function makes the motor to turn to specified position (target position): go_angle(), go_position() and move_steps(). If the SYNCHRONOUS is set, the program execution will be kept waiting inside of those functions until motor rotation complete.If ASYNCHRONOUS is set (default), the function will return immediately and program can work for something else.

set_rot_mode( StepperMotor::SHORTEST | StepperMotor::NO_WRAPAROUND | StepperMotor::CLOCKWISE_ONLY | StepperMotor:: COUNTER_CLOCKWISE_ONLY ) defines rotate direction when the motor works. If it is in SHORTEST mode (default), motor will turn the way shortest to target position. NO_WAPAROUND is to avoid the motor don't turn across the home position. CLOCKWISE_ONLY and COUNTER_CLOCKWISE_ONLY are to make one directional turn.

 

 

 

 

 

 

 

 



これはなに?

ステッピングモータ駆動用のクラスライブラリとそのサンプルです.

mbedはステッピングモータを直接ドライブするのではなく,ドライバチップを駆動します.というのもmbedはモータ駆動に充分な電流容量がなく,直接接続することができないためです.

ステッピング・モータは2本の信号線に適切な位相関係を持ったパスル列で駆動します.このライブラリはmbedにこの信号を発生させます.

 

次の図はステッピングモータの動作を単純化したものです.コイルに流れる電流を切り替えてやるたびに回転子が動きます.mbedはこの信号の極性とタイミングを作ります.

この図のモータは1回転中に取り得る位置は4つしかありませんが,実際のモータではもっと多い位置が設けられています.

コード:

コードはライブラリとして用意されています.

またサンプルコードも用意されています.

1個のモータを駆動する単純な例

3個のステッピングモータを同時に駆動するやや複雑な例

 

アナログ時計のコードは20101120日,21日に東京工業大学で開催されたMake: Tokyo Meeting 06でデモされたものです.

このデモでは3個のステッピングモータ制御とネットワークを介したNTPアクセスをデモしました.NTPサーバへのアクセスコードは次のURLのものから拝借しました.

ハードウェア:

電源

ハードウェアを単純化するためUSBバス電源を用いる単一電源としています(モータ回路へはmbedVU出力から供給)

USBバス電源はルートハブ(PCのコネクタ)またはセルフパワーを用いなければなりません.バスパワー・ハブからの電源は容量が小さいので問題となります.

(セルフパワー・ハブ >500mA/port,バスパワー・ハブ = 100mA/port)

もしモータに充分なトルクがなようであれば,より高い電圧の使用も可能です.TA7774PGのモーター電源ピン(pin916)

ステッピングモータ:

私が入手できたステッピングモータはコパル電子製のSPG20-332でした(秋月電子で購入).このモータはバイポーラ型ではないのですが,接続によりバイポーラとして使うことが可能です(多分問題ないはずです)

ユニポーラ型では各コイルの中点が端子に出ているのですが,これを無視して使うことでバイポーラ型として扱います.

信号:

上の図中,SinalASignalBはモータの動作に不可欠な信号です.他の2本の信号(Power制御出力と位置センサー入力)はオプションです.

Power制御はTA7774PGVs2_bピン(pin8)に与えPOWER-OFF(Low)OPERAITION(High)を切り替えるための信号です.

このVs2_bピンはにはプルアップ抵抗がつけられていますがこれはこの信号がオプションであるためです.この信号を使わない場合,非接続とした場合にもこのピンがHighになるようにしています.

Power制御はset_power_ctrl( true )によってイネーブルされます.これがイネーブルされている間,モータが動作しない状態であるときにTA7774PGPOWER-OFF状態になるようにします.

もうひとつの入力信号:位置検出入力(位置センサー入力)もオプションです.モータのホーム・ポジション検出のために使われるフォトインタラプタなどの出力を接続できます.

検出をどちらのエッジ(立ち上がりまたは立ち下がり)で検出するのかを選択可能です.find_home_position( edge )


0 comments

You need to log in to post a comment