SKU:RB-02S043 光電測(cè)速碼盤(pán)套件

來(lái)自ALSROBOT WiKi
跳轉(zhuǎn)至: 導(dǎo)航、 搜索
Gdcsmp.jpg

目錄

產(chǎn)品概述

Arduino 光電碼盤(pán)是哈爾濱奧松機(jī)器人科技有限公司2012年最新推出的光電測(cè)試傳感器,該產(chǎn)品是一款短響應(yīng)速度、開(kāi)關(guān)量輸出的測(cè)速模組,配合白色碼盤(pán)可以測(cè)量電機(jī)轉(zhuǎn)速,該款測(cè)試碼盤(pán)可以直接固定到雙輸出軸直流減速電機(jī)上方便安裝,簡(jiǎn)單易用。

規(guī)格參數(shù)

  1. 工作電壓:5v DC
  2. 工作電流:小于 20mA
  3. 工作溫度:10℃ - 30℃
  4. 與傳感器擴(kuò)展板I/O兼容
  5. 傳感器類(lèi)型:模擬輸出
  6. 平面尺寸:15×35×16mm
  7. 重量大小:24g

接口定義

  • S:信號(hào)控制端(Signal)
  • +:電源(VCC)
  • -:地(GND)

使用方法

example1_Arduino

  • 硬件連接

將光電測(cè)速碼盤(pán)的 S 端口接到控制器的數(shù)字 I/O 口 5,+ 和-分別接到電源的 +5V 和 GND。

  • 示例程序
#include "MsTimer2.h"
#define ENCODER_READ 5
unsigned int encoderPos,a;
void setup()
{  
    Serial.begin(9600);
    MsTimer2::set(1000, flash); // 500ms period
    MsTimer2::start();
    counterStart();
}

void loop()
{
}
void counterStart()
{
  TCCR1A=0;                       
  TCCR1B=0;                
  TCNT1=0;                     
  TCCR1B = TCCR1B | 7; 
}
unsigned int getCount()
{
  unsigned int count;
  count = TCNT1;  
  TCNT1=0;  
  TCCR1B = TCCR1B & ~7;                      
  TCCR1B = TCCR1B | 7;                  
  return count;                             
}
void flash() {
encoderPos = getCount();
a=encoderPos*6;
Serial.print("rotate speed = ");
Serial.print(a);
Serial.println(" RPM");
}
  • 程序效果

在串口打印出"rotate speed ="及 "RPM"相關(guān)數(shù)據(jù)

example2_Arduino

  • 硬件連接

將光電測(cè)速碼盤(pán)1的 S 端口接到控制器的數(shù)字 I/O 口 2,+ 和-分別接到電源的 +5V 和 GND
將光電測(cè)速碼盤(pán)2的 S 端口接到控制器的數(shù)字 I/O 口 3,+ 和-分別接到電源的 +5V 和 GND

  • 示例程序
#include "TimerOne.h"

const byte MOTOR1 = 2;  // Motor 1 使用外部中斷 0
const byte MOTOR2 = 3;  // Motor 2 使用外部中斷 1

unsigned int counter1 = 0;
unsigned int counter2 = 0;

float diskslots = 10;  //碼盤(pán)數(shù)

void ISR_count1()  
{
  counter1++;  //Motor1
} 

void ISR_count2()  
{
  counter2++;  //Motor 2
} 

// TimerOne 中斷
void ISR_timerone()
{
  Timer1.detachInterrupt();  // Stop the timer
  Serial.print("Motor Speed 1: "); 
  float rotation1 = (counter1 / diskslots) * 60.00;  // Motor 1
  Serial.print(rotation1);  
  Serial.print(" RPM  "); 
  counter1 = 0;  
  Serial.print("Motor Speed 2: "); 
  float rotation2 = (counter2 / diskslots) * 60.00;  // Motor 2
  Serial.print(rotation2);  
  Serial.println(" RPM"); 
  counter2 = 0;  
  Timer1.attachInterrupt( ISR_timerone );  
}

void setup() 
{
  Serial.begin(9600);
  
  Timer1.initialize(1000000); // 設(shè)定時(shí)間為 1s
  attachInterrupt(digitalPinToInterrupt (MOTOR1), ISR_count1, RISING);  // 當(dāng)檢測(cè)到上升沿時(shí),計(jì)數(shù)
  attachInterrupt(digitalPinToInterrupt (MOTOR2), ISR_count2, RISING);  
  Timer1.attachInterrupt( ISR_timerone ); // 開(kāi)啟Timer中斷
} 

void loop()
{

}
  • 程序效果

通過(guò)串口打印出兩個(gè)電機(jī)的轉(zhuǎn)速

資料下載

Erweima.png
  • 產(chǎn)品資料

下載鏈接:https://pan.baidu.com/s/1BBy385RbyeitgAo0U6DXxA 提取碼:ym1r