Raspberry Pi 備忘録 / Mbedもあるよ!

Raspberry Pi であれこれやった事の記録

ステッピングモーターその2 L6470 の機能を試す

L6470の機能を試す。

データシートは以下ですが、

http://strawberry-linux.com/pub/L6470.pdf

日本語訳してくださったサイトが有りました。

spinelify.blog.fc2.com

Run (DIR, SPD)

0 1 0 1 0 0 0 DIR from host X X X X SP D (Byte 2) from host
SPD (Byte 1) from host
SPD (Byte 0) from host

とあり、

Direction

The Run command produces a motion at SPD speed; the direction is selected by DIR bit: '1' forward or '0' reverse. The SPD value is expressed in step/tick (format unsigned fixed point 0.28) that is the same format that SPEED register (see paragraph 9.1.4).

とある。

DIR bit: '1' forward or '0' reverse.

とのことだから、
0b01010000 = 80 = 0x50 : 逆
0b01010001 = 81 = 0x51 : 順
かな。

BUSY Flag

This command keeps the BUSY flag low until the target speed is reached.

与えらた速度に達するまでは BUSY:LOW になる。

Speed

SPD=5000 の場合は、

0b1001110001000 = 5000 = 0x001388 なので、これを 3 bytes に切り分けると、

0b00000000 0 0x00
0b00010011 19 0x13
0b10001000 136 0x88

になる。

算出の際は、マスク処理をしたたうえで、シフト演算することが多そうだ。
今回は、1バイト目は、半分は使用しないので、マスクは 0x0F0000 になる。

0x0F0000 & spd = 0 = 0x00  
0x00FF00 & spd = 4864, (4864 >> 8) = 19 = 0x13  
0x0000FF & spd = 136 = 0x88

Move (DIR, N_STEP)

0 1 0 0 0 0 0 DIR from host
X X N_STEP (Byte 2) from host
N_STEP (Byte 1) from host
N_STEP (Byte 0) from host

とあり、Dirにかんしては

The move command produces a motion of N_STEP microsteps; the direction is selected by DIR bit ('1' forward or '0' reverse).
The N_STEP value is always in agreement with the selected step mode; the parameter value unit is equal to the selected step mode (full, half, quarter, etc.).

とある。
Run と一緒だ

'1' forward or '0' reverse

0b01000000 = 64 = 0x40 : 逆
0b01000001 = 65 = 0x41 : 順

BUSY flag

This command keeps the BUSY flag low until the target number of steps is performed.

とあるから、全step移動終わるまでは BUSY:LOW になっている。

そして、

This command can be only performed when the motor is stopped. If a motion is in progress the motor must be stopped and then it is possible to perform a Move command.
Any attempt to perform a Move command when the motor is running causes the command to be ignored and the NOTPERF_CMD flag to rise (see paragraph 9.1.22).

動作完了までは動かないよーと。

N_STEP

まず、使用しているステッピングモーターは、 STEP ANGLE 1.8° 5% だから、200 steps で、一周になる。

つぎに、microsteps の意味ですが、STEP_MODEで決まると。
full, half, quarter, etc とのこと。

Full なら、200 steps で一周だ。

Rest Value は 128 microsteps なので、 128 * 200 = 25600 で一周か。
レジスタの値は7)

マスクはどうなるかな?
バイト目のマスクは、 XX000000 になるのだが、表記は、、、調べ中。
001111 のマスクだから 0x3F かな?
0x3F00000 か???

BUSYのチェック

次の処理を入れるために、BUSY flag が終わるまで待ちたいのだが、その方法は?

どうやら、今まで接続してこなかった PIN1 の ~BUSY を使用するようだ。

SetParam(PARAM, VALUE)

ストロベリーリナックスのマニュアルに記述がある。

内部アドレスに書き込むには次のようにします。SetParam(PARAM, VALUE)
8ビットでレジスタアドレスを送信します。これがコマンドバイトになります。その後各レジスタの長さ分引数を与えてくだ
さい。その引数がレジスタに書き込まれます。長さが8ビットで割り切れない場合はMSB 側のビットを0でパディングしま
す。レジスタの長さに応じて引数は1~3バイトとなります。

MAX_SPEED

Address[Hex] Register name Register function Len. [bit] Reset Hex Reset Value Remarks
h07 MAX_SPEED Maximum speed 10 041 248e-6 step/tick(991.8 step/s) R, WR

0x07
0x00
0x41

と、投げれば良さそうだが、なんか変だ。
きちんと速度が変わるケースと、脱調?してしまうことが有る。

reset hex の 0x41 の reset value は 248e-6 step/tick (991.8 step/s) らしい。

STEP_MODE

SYNC_EN(1bit) SYNC_SEL(3bit) 0 STEP_SEL(3bit)

と設定するらしいが、STEP_SELとは?

Table 18. Step mode selection STEP_SEL[2..0] Step mode 0 0 0 Full step
0 0 1 Half step
0 1 0 1/4 microstep
0 1 1 1/8 microstep
1 0 0 1/16 microstep
1 0 1 1/32 microstep
1 1 0 1/64 microstep
1 1 1 1/128 microstep

reset hex の 7 は、 1/128 mode だ。

BUSY PIN

ドライバの PIN 1 の ~BUSY を利用する。

とりあえず、LEDを指して目視で動作を確認すると、平常時は HIGH で、 BUSYな状態だと、 LOW になる。

抜粋ですが

# BUSY PIN の設定
BUSY_PIN        = 21
io = wp.GPIO(wp.GPIO.WPI_MODE_GPIO)
io.pinMode(BUSY_PIN,io.INPUT)


*** 中略 ***

while( io.digitalRead(BUSY_PIN) == 0 ):
    pass