Top > Arduino > A4960

広告
  • 追加された行はこの色です。
  • 削除された行はこの色です。
  • Arduino/A4960 へ行く。

*[[Arduino]]から[[Allegro MicroSystems:http://www.allegromicro.com/]]の[[A4960:http://www.allegromicro.com/ja-JP/Products/Motor-Driver-And-Interface-ICs/Brushless-DC-Motor-Drivers/A4960.aspx]]を使ってみる [#lc96f9f4]
[[A4960:http://www.allegromicro.com/ja-JP/Products/Motor-Driver-And-Interface-ICs/Brushless-DC-Motor-Drivers/A4960.aspx]]は外部にNch FETを付けてセンサーレスのブラシレスモータを回すことができる。~
Pch FETを使わないので使いやすい。

Arduinoでは設定するのに[[SPIライブラリ:http://www.musashinodenpa.com/arduino/ref/index.php?f=1&pos=531]]を使う。~
SPIのためにA4960のSTRN、SDI、SDO、SCKをそれぞれ[[Arduino]]側のSS、MOSI、MISO、SCKに接続する必要がる。~
さらにモータを回すにPWMが必要。回転数を知りたいならTACHOにも接続する。

ただ回すだけなら
-Run RegisterのRun bitを「1」にする。
-PWM端子にPWM信号を送る
-方向を変えるにはRun RegisterのDIR bitを変える

とRun Registerしか使わない。~
が、そのためだけにSPIの接続をしなくちゃならない!

でも、単にRun Registerを設定しただけでは動かなかったら他のレジスタもいじる必要があると思う。

[[参考回路図が載っている:http://forum.arduino.cc/index.php?topic=155393.0]]
**[[Arduino]]のプログラム [#p9a4a2f9]
SPIの通信に必要そうな部分のみ。[[SPIライブラリのExample:https://www.arduino.cc/en/Tutorial/BarometricPressureSensor]]を参考にした。
SPIの通信に必要そうな部分のみ。[[SPIライブラリのExample:https://www.arduino.cc/en/Tutorial/BarometricPressureSensor]]や[[フォーラム>http://forum.arduino.cc/index.php?topic=311593.0]]を参考にした。

まずはSPIのヘッダーをインクルードする。
 #include <SPI.h>

使いそうな変数を定義。わざわざ定義する必要ないと思うけど
 const int WRITE = 0x10;
 const int wait=1;

チップセレクトピン(CSまたはSS)を定義
 const int chipSelectPin = 10;

いろいろなレジスタのアドレスを定義
 const byte BLANK = 0b00000000;
 const byte VREF = 0b00100000;
 const byte PWM = 0b01000000;
 const byte HOLD = 0b01100000;
 const byte START = 0b10000000;
 const byte RAMP = 0b10100000;
 const byte MASK = 0b11000000;
 const byte RUN = 0b11100000;
 const byte DIAG = 0b11000000;  //Read only

レジスタ書き込み関数
 void writeRegister(byte thisRegister, byte dataH, byte dataL) {
  byte dataToSend = thisRegister | WRITE;
  dataToSend = dataToSend | dataH;
  digitalWrite(chipSelectPin, LOW);
  //delay(10);
  SPI.transfer(dataToSend); //Send register location
  SPI.transfer(dataL);  //Send value to record into register
  // take the chip select high to de-select:
  digitalWrite(chipSelectPin, HIGH);
 }

レジスタ読み込み関数
 unsigned int readRegister(byte thisRegister ) {
  byte inByte = 0;           // incoming byte from the SPI
  unsigned int result = 0;   // result to return
  byte dataToSend = thisRegister;
  digitalWrite(chipSelectPin, LOW);
  delay(wait);
  // send the device the register you want to read:
  result = SPI.transfer(dataToSend);
  result = result << 8;
  inByte = SPI.transfer(0x00);
  // combine the byte you just got with the previous one:
  result = result | inByte;
  // take the chip select high to de-select:
  digitalWrite(chipSelectPin, HIGH);
  return(result);
 }

で、RUNビットを変更するために変数を定義しておいて
 byte run_h=0b00000010;
 byte run_l=0b00001001;  //RUN

RUNレジスタに書き込む。(RUNビットを1にする)
 writeRegister(RUN, run_h, run_l);
RUNレジスタを確認
 ret=readRegister(RUN);
 Serial.println(ret, BIN); //要シリアル通信の設定

確認すると下位12ビット(レジスタアドレスを引いたもの)ぐらいしか表示されない。
**注意点 [#vc90f554]
[[以前モータが回るときの電流でロジック電圧が降下して動かなかったと書いた>blog/2012-09-09/ブラシレスモーターを回してみる]]が、ロジック電圧を別電源にしてもダメだった。~
結局VBB端子(モータと同じ電源につなぐ)の電圧が落ちてしまうとダメらしいので突入電流に耐えられる大きめのコンデンサを付けておく必要があった。~
A4960の設定で立ち上がりなどを変えられるみたいなのでもしかしたらそれでも対処可能かもしれない。やってないので分からない。

広告

リロード   差分   ホーム 一覧 検索 最終更新 バックアップ リンク元   ヘルプ   最終更新のRSS