SKU:RB-02S043 光電測速碼盤套件

來自ALSROBOT WiKi
2021年12月10日 (五) 09:37Zhangxin討論 | 貢獻的版本

(差異) ←上一版本 | 最后版本 (差異) | 下一版本→ (差異)
跳轉(zhuǎn)至: 導(dǎo)航搜索
Gdcsmp.jpg

目錄

產(chǎn)品概述

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

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

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

接口定義

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

使用方法

example1_Arduino

  • 硬件連接

將光電測速碼盤的 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

  • 硬件連接

將光電測速碼盤1的 S 端口接到控制器的數(shù)字 I/O 口 2,+ 和-分別接到電源的 +5V 和 GND
將光電測速碼盤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;  //碼盤數(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è)定時間為 1s
  attachInterrupt(digitalPinToInterrupt (MOTOR1), ISR_count1, RISING);  // 當(dāng)檢測到上升沿時,計數(shù)
  attachInterrupt(digitalPinToInterrupt (MOTOR2), ISR_count2, RISING);  
  Timer1.attachInterrupt( ISR_timerone ); // 開啟Timer中斷
} 

void loop()
{

}
  • 程序效果

通過串口打印出兩個電機的轉(zhuǎn)速

資料下載

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

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