begin()

説明

86Duinoのエンコーダのインターフェースを初期化して、動作モードを指定します。

語法


Enc0.begin(mode)
Enc0.begin(mode, bits)
Enc0.begin(mode, bits, clock)
Enc0.begin(mode, bits, clock, wtime)
Enc0.begin(mode, bits, clock, wtime, gray2bin)

Enc1.begin(mode)
Enc1.begin(mode, bits)
Enc1.begin(mode, bits, clock)
Enc1.begin(mode, bits, clock, wtime)
Enc1.begin(mode, bits, clock, wtime, gray2bin)

Enc2.begin(mode)
Enc2.begin(mode, bits)
Enc2.begin(mode, bits, clock)
Enc2.begin(mode, bits, clock, wtime)
Enc2.begin(mode, bits, clock, wtime, gray2bin)

Enc3.begin(mode)
Enc3.begin(mode, bits)
Enc3.begin(mode, bits, clock)
Enc3.begin(mode, bits, clock, wtime)
Enc3.begin(mode, bits, clock, wtime, gray2bin)

參數

Enc0、Enc1、Enc2、Enc3:ENC0、ENC1、ENC2、ENC3のコーディング インターフェースにマッピングします。

mode:The interface can be set in one of the following 5 modes:

  1. MODE_STEP_DIR:Pulse/DIR 増量コーディングモード(接続例
  2. MODE_CWCCW:CW/CCW 増量コーディングモード(接続例
  3. MODE_AB_PHASE:A/B Pulse 増量コーディングモード(接続例
  4. MODE_SSI:SSI 絶対コーディングモード(接続例
  5. MODE_CAPTURE:PWMモード

bitsMODE_SSI モードのオプション設定,SSI絶対コーディングのBIT幅設定に使われます。(初期値は12bitsですが、最大32bitsに設定可能)

clockMODE_SSI モードのオプション設定,。SSIの通信速度の設定に使われます。(初期値は1000000Hz)

wtimeMODE_SSI モードのオプション設定,。SSI Wait Timeの設定に使われます。(初期値は20 us)

gray2binMODE_SSI モードのオプション設定,出力値はtrue或いはfalseです。Gray Codeの転換機能を開くかとうか指定され、開いた後、本体が自動的にSSIからのフィードバック値をGray Code to Binaryに転換します。(初期値はfalse)

フィードバック

なし

ENC0をPulse/DIRモードに設定して、カウンター数値を読込みします。

#include <Encoder.h>

void setup() {
   Serial.begin(9600);
   Enc0.begin(MODE_STEP_DIR);
}

void loop() {
   Serial.println(Enc0.read()); // カウンター数値を読込みする
   delay(100);
}

ENC1をPWMモードに設定して、パスルHIGH、LOWの幅の数値を読込みます。

#include <Encoder.h>

volatile unsigned long num1 = 0L;
volatile unsigned long num2 = 0L;
void encoder_isr(int flag) { // ISR function
    if (flag == INTR_A_PULSE_LOW) // パスルLOWの幅を読込みする
      num1 = Enc1.read();
    else if (flag == INTR_A_PULSE_HIGH) // パスルのHIGH幅を読込みする
      num2 = Enc1.read();
}

void setup() {
   Serial.begin(9600);
   Enc1.begin(MODE_CAPTURE);
   Enc1.attachInterrupt(encoder_isr); //ISRライブラリをマウントして、中断機能を起動する
}

void loop() {
   Serial.print("LOW:");
   Serial.print(num1); // パスルLOWの幅(単位:μs)をプリントアウトする
   Serial.print("    ");
   Serial.print("HIGH:");
   Serial.println(num2); // パスルHIGHの幅(単位:μs)をプリントアウトする
   delay(100);
}

See also

attachInterrupt()
read()
setIndexReset()
setComparator()


Libraries Reference Home

The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.