旋转编码开关(RotaryEncoderswitch)使用说明及程序
- 格式:doc
- 大小:270.00 KB
- 文档页数:11
P m o d E N C ™ R e f e r e n c e M a n u a lRevision: October 31, 2011Note: This document applies to REV A of the board.1300 NE Henley Court, Suite 3Pullman, WA 99163(509) 334 6306 Voice | (509) 334 6300 FaxDoc: 502-117page 1 of 2OverviewThe PmodENC Rotary Encoder Module features a rotary shaft encoder with integral push-button that provides rotate-right, rotate-left, and button-press outputs. The module also includes a sliding switch that provides an on/off output.Features include:• a rotary push-button shaft encoder • a slide switch with a series resistor • a 6-pin header• small form factor (1.5” x 0.75”).Functional DescriptionThere are four outputs on the PmodENCmodule, labeled A, B, BTN, and SWT. Outputs A and B are the encoded outputs from the rotary shaft encoder. In principle, the rotary shaft encoder behaves like a cam connected to a central shaft. Rotating the shaft operates two push-button switches, as shown in Figure 2. Depending on which way the shaft is rotated, one of the switches closes before the other. Likewise, as the rotation continues, one switch opens before the other. When the shaft is stationary (the detent position) both switches are open (logic 1).5 = GND 1 = A 2 = B 3 = BTN 4 = SWT6 = VCCFigure 1 PmodENC Pin SignalsFigure 2 Rotary Shaft Encoder CircuitryPmodXYZ Reference Manualpage 2 of 2Pressing the rotary push-button shaft encoder will drive the output pin BTN to VCC voltage or a logic level 1. Otherwise BTN is driven to GND voltage or a logic level 0.Placing the slide switch into the up position on the PmodENC module will drive the output SWT to VCC voltage or a logic level 1. Placing the slide switch in the down position will drive SWT to GND voltage or a logic level 0.Decoding Rotations of the Rotary ShaftFigure 4 shows a timing diagram of a rotate-right on the rotary push-button shaft of thePmodENC module. Note the logic noise shown with opening and closing of the switches. A rotate-left of the rotary push-button shaft is similar to Figure 4. The only difference is that output B will drop to logic level 0 first, followed by output A.Figure 3 Push-Button CircuitryD et e n tFigure 4 Timing of Outputs A and B。
1300 Henley Court Pullman, WA 99163509.334.6306 PmodENC ™ Reference ManualRevised April 12, 2016This manual applies to the PmodENC rev. AOverviewThe Digilent PmodENC features a rotary shaft encoder with an integral push-button to provide multiple types of outputs. The module also includes a sliding switch that is commonly used as an on/off output. An encoder is commonly used in freely rotating volume knobs to detect how many “clicks” a knob has been rotated.1Functional DescriptionThe PmodENC utilizes a rotary shaft encoder as a way for users to quickly switch between multiple options such as choices shown on a screen or predefined motors speeds. An integral push-button on the shaft as well as a slide switch allow for a highly configurable Pmod.2 Interfacing with the PmodThe PmodENC communicates with the host board via the GPIO protocol. It provides four inputs to the system board; the two buttons internal to the encoder that are in quadrature with each other as well as the integral push button on the shaft and the slide switch. A system board will read the integral push button and the slide switch at a logic low voltage in their native (or off in the case of the switch) states.The PmodENC.∙ Rotary push-button shaft encoder∙ Add multiple types of user input to hostboard or project∙ Additional static slide switch∙ Small PCB size for flexible designs 1.5 in ×0.8 in (3.8 cm × 2.0 cm)∙ 6-pin Pmod port with GPIO interface ∙ Follows Digilent Pmod InterfaceSpecification Type 1∙ Library and example code availablein resource centerFeatures include:The two internal buttons are both natively pulled to a logic high level through a pull-up resistor. As the two buttons are located 90 degrees from each other (i.e. in quadrature), while the shaft is rotating one button will be pulled to a low logic level voltage before the other button.Figure 1. Rotary shaft encoder circuitry.Users can program their system boards to determine which button was pulled low last (within a small time frame to ensure additional “clicks” are not also captured) in order to figure out which direction the shaft is being rotated.Switch ChatterRising edge of A first, then B is decoded as a rotate rightD e t e n tA BRotate RightFigure 2. Timing of outputs A and B.2.1 Pinout Description TablePin SignalDescription1 A Output of button A in the encoder shaft2 B Output of button B in the encoder shaft3 BTN Output of the integral push button in the encoder shaft4 SWT Output of the on board switch5 GND Power Supply Ground6VCCPositive Power Supply (3.3/5V)It is recommended that Pmod is operated at 3.3V or 5V, although because there are no integrated circuits on the Pmod, any voltage that your system board can handle as a digital input will work fine.3 Physical DimensionsThe pins on the pin header are spaced 100 mil apart. The PCB is 1.5 inches long on the sides parallel to the pins on the pin header and 0.8 inches long on the sides perpendicular to the pin header.。
Table Of Contents:Introduction 1Hardware Description 1Compatible Hardware 1Pin Descriptions 3Example Hardware Connection for Arduino 3Example Code for Arduino 3Adjusting LED Current and Brightness 3Diffusing the LEDs 4Setting the LED Sequence 4_________________________________________IntroductionSince rotary encoders have no start or end point, knobs without a position indicator are typically used – as opposed to potentiometers, where an indicator knob is suitable. Many applications require a visual representation of how a rotary encoder is reacting to user input as well as the control’s current position. The Rotary Encoder LED Ring offers a solution with a ring of 16 LEDs that surround the encoder. The designer may implement any desired sequence on the LEDs by communicating with the onboard series-to-parallel constant current shift register._________________________________________Hardware DescriptionThe Rotary Encoder LED Ring has two separate sections: a rotary encoder breakout and a collection of LEDs controlled by a shift register. A microcontroller can be used to obtain encoder data and set LED data.A rotary encoder may be mounted to the printed circuit board in two separate ways. The PCB has (1) mounting-tab holes and soldering positions for a rotary encoder as well as (2) a hole for the encoder shaft: the encoder may be soldered to the PCB or fitted through the shaft hole. Compatible rotary encoders are described below in the‘Compatible Hardware’ section.The PCB has 15 LEDs in a 270˚ arc and one LED at the bottom of the arc; they are interfaced with a Texas Instruments TLC5925 16-bit shift register. The interface uses a standard Serial-Data/Clock/Latch-Enable 3 wire connection that is further described with timing diagram in the TLC5925 datasheet:/lit/ds/symlink/tlc5925.pdf.A thru-hole resistor can be used to increase the brightness of the LEDs and is described further in the ‘Adjusting LED Current and Brightness’ section.Please see the ‘Pin Descriptions’ section for more information about the 10 available connections._________________________________________Compatible HardwareThe Rotary Encoder LED Ring is compatible with any microcontroller with at least 2 input lines (for the rotary encoder) and 3 output lines (for the serial interface) available.It can accept knobs up to 3/4-inch diameter without covering the LEDs. Image 1 shows how a 3/4" knob appears on a shaft-mounted encoder._________________________________________DIMENSIONS:MM(INCHES)Pin DescriptionsPin Description Section GND Ground, zero voltage referencePowerVCC 3 to 5.5 Volts (Yellow, Green, Red LED models)** BLUE LED model requires 3.6 to 5.5 Volts **ENCA Rotary Encoder A TerminalRotaryEncoderENCB Rotary Encoder B TerminalSWTCH Rotary Encoder SwitchSDI Serial Data InputTLC5925CLK ClockLE Latch EnableOE (Active Low) Output Enable; tie to ground for constant operationSDO Serial Data Output – for daisy chaining units_________________________________________Example Hardware Connection for Arduino:The following is an example of how the Rotary Encoder LED Ring might be connected to an Arduino. The example code listed below follows this set of connections.Image 2: Connections to an Arduino Table 2: List of pin connections to an Arduino_________________________________________Example Code for Arduino:Three examples of how the Rotary Encoder LED Ring might be used can be found in the Arduino example code available at: /products/rotary-encoder-led-ringIf an Arduino is not the desired target device, the example code gives enough detail to outline the procedures necessary to implement an interface on other programmable devices._________________________________________Adjusting LED Current and Brightness:Rotary Encoder LEDRing PinArduino PinGND GNDVCC 5VENCA 8 (Digital)ENCB 9 (Digital)SWTCH 10 (Digital)SDI 2 (Digital)CLK 3 (Digital)LE 4 (Digital)OE (Active Low) GNDSDO Not connectedThe Rotary Encoder LED Ring ships with dim LEDs so the end user may increase the brightness to a levelappropriate for the application. The current to each of the 16 LEDs is constant and is set per the TLC5925datasheet. A surface mount 22k Ω resistor is provided and a parallel thru-hole resistor may be added to increasethe brightness by lowering the resistance. Please reference Equation 1 and Figure 2 to set the current output to theLEDs. Using a parallel resistance calculator like /calculator-paralresist.htm orEquation 2 can help determine what resistor value to use for the thru-hole resistor. With the surface mount 22k Ωresistor, the output current is set to about 1mA. Adding a 1k Ω resistor thru-hole will increase the LED brightness to their highest setting. A potentiometer or voltage controlled resistor may also be used to adjust the brightness on the fly. Care must be taken to not increase the current beyond the capability of the LEDs (20mA to 30mA max).Equation 1: Current Output to Each LEDFigure 2: Relationship between I OUT and R EXTImage Credit: Texas Instruments TLC5925 DatasheetEquation 2: Parallel Resistance Total (Surface Mount and Thru-Hole)_________________________________________Diffusing the LEDs:Some applications may require LEDs that have more uniform lighting or appear more as an indicator than a light source. Sanding the clear lens of the LEDs, roughening it up to create a diffused lens can accomplish this. 400 grit sand paper or similar works well._________________________________________Setting the LED Sequence:There are primarily two methods to create an LED sequence to be outputted to the shift register. The first, andeasiest, is to create a sequence of ‘images’ that will be stepped through as the encoder is rotated. The second is to use bitwise operations (AND, OR, XOR) to build and modify the ‘image’ that is currently on the LEDs. This method is how the example code turns on the bottom LED while not changing the current image otherwise.I OUT =1.21VR ext ×18APPLICATION INFORMATION g Principles Current OutputCurrent 0510152025303540455001000150020002500300035004000R ext –8I O U T –m AW play applications,TLC5925provides nearly no current variations from channel to channel and from IC e I OUT 45mA,the maximum current skew between channels is less than ±5%and between ICs is 6%.ets I OUT based on the external resistor R ext .Users can follow the below formulas to calculate the ut current I OUT,target in the saturation region:(1.21V /R ext )!18,where R ext is the external resistance connected between R-EXT and GND.the default current is approximately 26mA at 840 and 13mA at 1680 .The default relationship on between I OUT,target and R ext is shown in Figure 5.Figure5.Default Relationship Curve Between IOUT,target and R ext After Power UpR ext =R 1×R 2R 1+R 2As an example, the image to output that will turn on one additional LED each step looks like: 0000000000000001 (hex 0x01)0000000000000011 (hex 0x03)0000000000000111 (hex 0x07)and so on. This sequence can be written directly to the shift register.If the same output was created using XOR or OR, the sequence would look like:0000000000000001 (hex 0x01)0000000000000010 (hex 0x02)0000000000000100 (hex 0x04)and so on. An image would be OR’ed with the previous image and the result would be the same as the first example.For details about using bitwise operations, please see the Arduino Reference:/en/Reference/BitwiseAndUsing the map() function, it is possible to scale the speed of the LED output sequence relative to the encoder rotation. For example, when rotating the rotary encoder one full revolution, one additional LED is turned on. See the Arduino Reference: /en/Reference/Map。
四:旋转编码器的调整增量式编码器的相位对齐方式在此讨论中,增量式编码器的输出信号为方波信号,又可以分为带换相信号的增量式编码器和普通的增量式编码器,普通的增量式编码器具备两相正交方波脉冲输出信号A和B,以及零位信号Z;带换相信号的增量式编码器除具备A/B/Z 输出信号外,还具备互差120度的电子换相信号U/V/W,U/V/W各自的每转周期数与电机转子的磁极对数一致。
带换相信号的增量式编码器的U/V/W电子换相信号的相位与转子磁极相位,或曰电角度相位之间的对齐方法如下:1.用一个直流电源给电机的U/V绕组通以小于额定电流的直流电,U入,V出,将电机轴定向至一个平衡位置.2.用示波器观察编码器的U相信号和Z信号.3.调整编码器转轴与电机轴的相对位置.4.一边调整,一边观察编码器U和Z相信号跳变沿,直到Z信号稳定在高电平上(在此默认Z信号的常态为低电平),锁定编码器与电机的相对位置关系。
5.来回扭转电机轴,撒手后,若电机轴每次自由回复到平衡位置时,Z信号都能稳定在高电平上,则对齐有效。
撤掉直流电源后,验证如下:1.用示波器观察编码器的U相信号和电机的U/V线反电势波形。
2.转动电机轴,编码器的U相信号上升沿与电机的U/V线反电势波形由低到高的过零点重合,编码器的Z信号也出现在这个过零点上。
上述验证方法,也可以用作对齐方法。
需要注意的是,此时增量式编码器的U相信号的相位零点即与电机UV线反电势的相位零点对齐,由于电机的U相反电势,与UV线反电势之间相差30度,因而这样对齐后,增量式编码器的U相信号的相位零点与电机U相反电势的-30度相位点对齐,而电机电角度相位与U相反电势波形的相位一致,所以此时增量式编码器的U相信号的相位零点与电机电角度相位的-30度点对齐。
有些伺服企业习惯于将编码器的U相信号零点与电机电角度的零点直接对齐,为达到此目的,可以:1.用3个阻值相等的电阻接成星型,然后将星型连接的3个电阻分别接入电机的UVW三相绕组引线;2.以示波器观察电机U相输入与星型电阻的中点,就可以近似得到电机的U相反电势波形。
DELTA ROTARY OPTICAL ENCODERINSTRUCTION SHEET (English Version)CIRCUIT OF OUTPUT SIGNALSBefore connecting the encoder wirings to the receiver, please identify the type of the output signal with the specification. 1. Connection Table ES/EH/ET SeriesConnect the shield wire (bare wire) with the grounding end of equipment for better performance.AS/AH Series (AXX-XXCXXXXX, AXX-XXVXXXXX)Wire Color Function Wire Color Function Red Vcc Blue 24Black 0V Purple 25 Brown 20Gray 26 Orange 21 White 27Yellow 22 Pink 28 Green23Light Blue29MH4/MT4 Series2. Output CircuitDELTA ROTARY ENCODER KULLANIMI(Türkçe Version)ÇIKI Ş S ĐNYAL Đ DEVRES ĐEnkoder ba ğlantısı yapılmadan önce a şa ğıdaki tabloya göre çıkış tipi belirlenmelidir. 1. Ba ğlantı Tablosu ES/EH/ET SerisiDaha iyi bir performans için topraklama ucuna shield (aynalı kablo) kullanın.AS/AH Serisi (AXX-XXCXXXXX, AXX-XXVXXXXX)Kablo Rengi Fonksiyon Kablo RengiFonksiyonKırmızı Vcc Mavi 24Siyah 0V Mor 25 Kahve 20Gri 26Turuncu 21 Beyaz 27 Sarı 22 Pembe 28 Ye şil23Açık Mavi292. Çıkış Devresi台達旋轉式編碼器使用說明(繁體版)輸出訊號之電路將編碼器連接至接收端前,請先根據下表確認輸出訊號種類。
四:旋转编码器的调整增量式编码器的相位对齐方式在此讨论中,增量式编码器的输出信号为方波信号,又可以分为带换相信号的增量式编码器和普通的增量式编码器,普通的增量式编码器具备两相正交方波脉冲输出信号A和B,以及零位信号Z;带换相信号的增量式编码器除具备A/B/Z 输出信号外,还具备互差120度的电子换相信号U/V/W,U/V/W各自的每转周期数与电机转子的磁极对数一致。
带换相信号的增量式编码器的U/V/W电子换相信号的相位与转子磁极相位,或曰电角度相位之间的对齐方法如下:1.用一个直流电源给电机的U/V绕组通以小于额定电流的直流电,U入,V出,将电机轴定向至一个平衡位置.2.用示波器观察编码器的U相信号和Z信号.3.调整编码器转轴与电机轴的相对位置.4.一边调整,一边观察编码器U和Z相信号跳变沿,直到Z信号稳定在高电平上(在此默认Z信号的常态为低电平),锁定编码器与电机的相对位置关系。
5.来回扭转电机轴,撒手后,若电机轴每次自由回复到平衡位置时,Z信号都能稳定在高电平上,则对齐有效。
撤掉直流电源后,验证如下:1.用示波器观察编码器的U相信号和电机的U/V线反电势波形。
2.转动电机轴,编码器的U相信号上升沿与电机的U/V线反电势波形由低到高的过零点重合,编码器的Z信号也出现在这个过零点上。
上述验证方法,也可以用作对齐方法。
需要注意的是,此时增量式编码器的U相信号的相位零点即与电机UV线反电势的相位零点对齐,由于电机的U相反电势,与UV线反电势之间相差30度,因而这样对齐后,增量式编码器的U相信号的相位零点与电机U相反电势的-30度相位点对齐,而电机电角度相位与U相反电势波形的相位一致,所以此时增量式编码器的U相信号的相位零点与电机电角度相位的-30度点对齐。
有些伺服企业习惯于将编码器的U相信号零点与电机电角度的零点直接对齐,为达到此目的,可以:1.用3个阻值相等的电阻接成星型,然后将星型连接的3个电阻分别接入电机的UVW三相绕组引线;2.以示波器观察电机U相输入与星型电阻的中点,就可以近似得到电机的U相反电势波形。
旋转编码开关(Rotary Encoder switch)这种旋转编码开关(Rotary Encoder switch),一个使用3脚的,后面一个使用5脚的,大家可能对这种玩意都不是很了解,但涉及到有调整的地方,这个玩意使用真是很爽,我弄了2个,研究了一下,供大家参考~5脚的ALPS:具有左转,右转,按下三个功能。
4、5脚是中间按下去的开关接线 1 2 3脚一般是中间2脚接地,1、3脚上拉电阻后,当左转、右转旋纽时,在1、3脚就有脉冲信号输出了。
着这是标准资料:在单片机编程时,左转和右转的判别是难点,用示波器观察这种开关左转和右转时两个输出脚的信号有个相位差,见下图:由此可见,如果输出1为高电平时,输出2出现一个高电平,这时开关就是向顺时针旋转; 当输出1 为高电平,输出2出现一个低电平,这时就一定是逆时针方向旋转.所以,在单片机编程时只需要判断当输出1为高电平时,输出2当时的状态就可以判断出是左旋转或是右旋转了。
还有另外一种3脚的,除了不带按钮开关外,和上面是一样的使用。
参考:#include "reg51.h"#define uint unsigned intsbit CodingsWitch_A=P1_1;sbit CodingsWitch_B=P1_2;uint CodingsWitchPolling()//{static Uchar Aold,Bold; //定义了两个变量用来储蓄上一次调用此方法是编码开关两引脚的电平static Uchar st; //定义了一个变量用来储蓄以前是否出现了两个引脚都为高电平的状态uint tmp = 0;if(CodingsWitch_A&&CodingsWitch_B)st = 1; //if(st) //如果st为1执行下面的步骤 {if(CodingsWitch_A==0&&CodingsWitch_B==0) //如果当前编码开关的两个引脚都为底电平执行下面的步骤{if(Bold) //为高说明编码开关在向加大的方向转{st = 0;tmp++; //}if(Aold) //为高说明编码开关在向减小的方向转{st = 0;tmp--; //设返回值}}}Aold = CodingsWitch_A; //Bold = CodingsWitch_B; //储return tmp; //}//编码器计数程序void encoder_cnt(void){uchar temp;temp = PIND; //取端口D管脚信号couch_clr = (temp & 0x08); //取编码器清零信号if(couch_clr != false) //有编码器清零信号{couch_num = 0; //水平床码清零}else{if(encoder_cnt_en == false) //编码器计数模块没有启动{pr_couch_ba = temp &0x03; //取编码器A、B相电平信号}else{couch_ba = temp & 0x03; //取编码器A、B相电平信号if(pr_couch_ba == 0x00){if(co uch_ba == 0x01){couch_num++; //水平床码加1}elseif(couch_ba == 0x10){couch_num--; //水平床码减1}}else if(pr_couch_ba ==0x01){if(co uch_ba == 0x11){couch_num++; //水平床码加1}elseif(couch_ba == 0x00){ couch_num--; //水平床码减1}}else if(pr_couch_ba == 0x10){if(co uch_ba == 0x00){couch_num++; //水平床码加1}else if(couch_ba == 0x11){couch_num--; //水平床码减1}}else if(pr_couch_ba == 0x11){if(co uch_ba == 0x10){couch_num++; //水平床码加1}else if(couch_ba == 0x01){couch_num--; //水平床码减1}}}pr_couch_ba = couch_ba;}}编码器及其计数模块原理飘扬的旋转编码器的检测程序(MCS51)//旋转编码器检测程序,A/B信号分别接在了INT0和INT1上//程序作者:BG4UVR//2005年1月15用KEIL编译、硬件测试通过//注意:编码器的信号,程序未做消抖处理。
旋转编码器使用方法使用方法一:修改驱动程序旋转编码器属于精密仪器,在其使用过程中需通过程序发出指令,才能起到特定的作用,而根据不同环境下的需求,需要设定不同的驱动程序,所以说决定编码器使用效果怎么样,修改合适的驱动程序是非常重要的。
通常情况下只要直接修改reg文件,同时注册一个表文件,利用添加的方式改写动态链接,在确定动态链接已经修改好的情况下,需要将其添加到内核中;使用方法二:硬件接口连接驱动程序修改好之后,下面就是硬件接口连接操作,在连接中,通常有A和B两个集电极输出接口,为确保线路衔接性,需要在3.3V 上的电阻上进行操作,将A和B两个接口分别插到CPU上。
在硬件接口连接成功之后,以防万一,须做好测试工作检查电压输出端高低压数值是否正确,比如在按下按钮之后,如果P2端口输出值是高电平的话,说明连接正确;使用方法三:流接口驱动程序的编写流接口驱动程序的编写是为下面的中断服务程序做准备,具体编写步骤是创建线程实现变量值的记录,同时记录在线路中断的情况下,各端口的数值是否还是高电平;使用方法四:中断服务程序的编写终端服务程序编写主要是起到编码器线路保护作用。
通过对CPU 的I/O接口进行初始化工作,在此基础上编写中断服务程序。
旋转编码器使用说明1. 确定检测对象,测速、测距、测角位移还是计数等。
2.仅用于动态过程还是包含静态位置或状态。
3.确认是择增量型旋转编码器还是绝对型旋转编码器。
4.确定对象的运动范围。
5.确认是选择单圈绝对型旋转编码器还是多圈绝对型旋转编码器。
6.确定对象的最高速度或频率。
7.确定对象的精度要求。
8.确定选择旋转编码器的应用参数。
9. 使用环境,注意旋转编码器的接口方式和保护等级。
旋转编码器旋转编码器是由光栅盘(又叫分度码盘)和光电检测装置(又叫接收器)组成。
光栅盘是在一定直径的圆板上等分地开通若干个长方形孔。
由于光栅盘与电机同轴,电机旋转时,光栅盘与电机同速旋转,发光二极管垂直照射光栅盘,把光栅盘图像投射到由光敏元件构成的光电检测装置(接收器)上,光栅盘转动所产生的光变化经转换后以相应的脉冲信号的变化输出。
编码器码盘的材料有玻璃、金属、塑料等。
玻璃码盘是在玻璃上沉积很薄的刻线,其热稳定性好,精度高。
金属码盘直接以通和不通刻线,不易碎,但由于金属有一定的厚度,精度就有限制,其热稳定性也比玻璃的差一个数量级。
塑料码盘成本低廉,但精度、热稳定性、寿命均要差一些。
编码器以信号原理来分,有增量式编码器(SPC)和绝对式编码器(APC),顾名思义,绝对式编码器可以记录编码器在一个绝对坐标系上的位置,而增量式编码器可以输出编码器从预定义的起始位置发生的增量变化。
增量式编码器需要使用额外的电子设备(通常是PLC、计数器或变频器)以进行脉冲计数,并将脉冲数据转换为速度或运动数据,而绝对式编码器可产生能够识别绝对位置的数字信号。
综上所述,增量式编码器通常更适用于低性能的简单应用,而绝对式编码器则是更为复杂的关键应用的最佳选择--这些应用具有更高的速度和位置控制要求。
输出类型取决于具体应用。
一:增量式旋转编码器工作原理增量式旋转编码器通过两个光敏接收管来转化角度码盘的时序和相位关系,得到角度码盘角度位移量的增加(正方向)或减少(负方向)。
增量式旋转编码器的工作原理如下图所示。
图中A、B两点的间距为S2,分别对应两个光敏接收管,角度码盘的光栅间距分别为S0和S1。
当角度码盘匀速转动时,可知输出波形图中的S0:S1:S2比值与实际图的S0:S1:S2比值相同,同理,当角度码盘变速转动时,输出波形图中的S0:S1:S2比值与实际图的S0:S1:S2比值仍相同。
通过输出波形图可知每个运动周期的时序为:我们把当前的A、B输出值保存起来,与下一个到来的A、B输出值做比较,就可以得出角度码盘转动的方向,如果光栅格S0等于S1时,也就是S0和S1弧度夹角相同,且S2等于S0的1/2,那么可得到此次角度码盘运动位移角度为S0弧度夹角的1/2,再除以所用的时间,就得到此次角度码盘运动的角速度。
旋转编码开关(Rotary Encoder switch)-使用说明及程序具有左转,右转,按下三个功能.4.5 脚是中间按下去地开关接线 1 23 脚一般是中间2脚接地,1.3 脚上拉电阻后,当左转.右转旋纽时,在1.3 脚就有脉冲信号输出了.着这是标准资料:在单片机编程时,左转和右转地判别是难点,用示波器观察这种开关左转和右转时两个输出脚地信号有个相位差,见下图:由此可见,如果输出1 为高电平时,输出2 出现一个高电平,这时开关就是向顺时针旋转; 当输出1 为高电平,输出2 出现一个低电平,这时就一定是逆时针方向旋转.所以,在单片机编程时只需要判断当输出1 为高电平时,输出2 当时地状态就可以判断出是左旋转或是右旋转了.还有另外一种3 脚地,除了不带按钮开关外,和上面是一样地使用.参考:#include "reg51.h"#define uint unsigned intsbit CodingsWitch_A=P1_1;sbit CodingsWitch_B=P1_2;uint CodingsWitchPolling()//{static Uchar Aold,Bold; //定义了两个变量用来储蓄上一次调用此方法是编码开关两引脚地电平static Uchar st; //定义了一个变量用来储蓄以前是否出现了两个引脚都为高电平地状态uint tmp = 0;if(CodingsWitch_A&&CodingsWitch_B)st = 1; //if(st) //如果st 为1 执行下面地步骤{if(CodingsWitch_A==0&&CodingsWitch_B==0) //如果当前编码开关地两个引脚都为底电平执行下面地步骤{if(Bold) //为高说明编码开关在向加大地方向转{st = 0;tmp++; //}if(Aold) //为高说明编码开关在向减小地方向转{st = 0;tmp--; //设返回值}}}Aold = CodingsWitch_A; //Bold = CodingsWitch_B; //储return tmp; //}//编码器计数程序void encoder_cnt(void){uchar temp;temp = PIND; //取端口D 管脚信号couch_clr = (temp & 0x08); //取编码器清零信号if(couch_clr != false) //有编码器清零信号{couch_num = 0; //水平床码清零}else{if(encoder_cnt_en == false) //编码器计数模块没有启动{pr_couch_ba = temp & 0x03; //取编码器A.B 相电平信号}else{couch_ba = temp & 0x03; //取编码器A.B 相电平信号if(pr_couch_ba == 0x00){if(couch_ba == 0x01){couch_num++; //水平床码加1}else if(couch_ba == 0x10){couch_num--; //水平床码减1}}else if(pr_couch_ba == 0x01){if(couch_ba == 0x11){couch_num++; //水平床码加1}{couch_num--; //水平床码减1}}else if(pr_couch_ba == 0x10){if(couch_ba == 0x00){couch_num++; //水平床码加1}else if(couch_ba == 0x11){couch_num--; //水平床码减1}}else if(pr_couch_ba == 0x11){if(couch_ba == 0x10){couch_num++; //水平床码加1}{couch_num--; //水平床码减1}}}pr_couch_ba = couch_ba;}}编码器及其计数模块原理飘扬地旋转编码器地检测程序(MCS51)//旋转编码器检测程序,A/B信号分别接在了INT0和INT1上//程序作者:BG4UVR//2005 年1 月15 用KEIL编译.硬件测试通过//注意:编码器地信号,程序未做消抖处理.测试中,A/B信号上各//接了一只104地瓷片电容,工作很正常.如果不接电容,请自行编//写信号消抖程序.#include <at89x51.h>sbit led="0xB1";//有一只LED接在了RXD 引脚上,用来指示正反转;main(){EA=1; //总中断允许EX0=1; //外部中断0允许IT0=1; //外部中断0为边沿触发方式while(1);;}/*********************编码器中断函数入口:无出口:无*********************/void encoder(void) interrupt 0 { //外部中断0if (INT1){led=1;}else{led=0;}}whimsy 地AVR 程序//外部中断0,用于编码开关解码,解码图: A 接中断脚(AVR 地PD2),以此为基准,B 用来判断方向(连到AVR 地PA1), C 接地//A -|// | -----|__________|----------|____________//C -|////B -|// | ----------|__________|----------|____________//C -|// CW ===>>> ROTATION//外部中断设置(ISC01=0,ISC00=1): INT0 引脚上任意地逻辑电平变化都将引发中断#pragma interrupt_handler int0_isr:2void int0_isr(void){//external interupt on INT0GICR=0; //禁止外部中断if ((PIND & 0x04)==0) //先判断是高电平产生地中断还是低点平地中断if ((PINA & 0x02)==0) //再判断B 线上地电平{keycounter--;keydirection="0";}个人收集整理资料,仅供交流学习,勿作商业用途else{keycounter++;keydirection="1";}elseif ((PINA & 0x02)==0){keycounter++;keydirection="1";}else{keycounter--;keydirection=0;}GICR=0x40;}。
---------------------------------------------------------------最新资料推荐------------------------------------------------------旋转编码器教学课件旋转编码器编辑锁定旋转编码器是用来测量转速并配合PWM 技术可以实现快速调速的装置,光电式旋转编码器通过光电转换,可将输出轴的角位移、角速度等机械量转换成相应的电脉冲以数字量输出(REP)。
分为单路输出和双路输出两种。
技术参数主要有每转脉冲数(几十个到几千个都有),和供电电压等。
单路输出是指旋转编码器的输出是一组脉冲,而双路输出的旋转编码器输出两组 A/B 相位差 90 度的脉冲,通过这两组脉冲不仅可以测量转速,还可以判断旋转的方向。
中文名旋转编码器外文名 Rotary Encoder 脉冲编码器SPC 绝对脉冲 APC 作用实现快速调速的装置齿轮组BESM58 目录 1. 1 基本简介 2. 2 形式分类 3. 3 工作原理 4.4 特点 1.5 信号输出 2.6 注意事项 3.7 原理特点 4.8 输出信号 1.9 常用术语 2. 10 安装事项 3. 11 应用旋转编码器基本简介编辑按信号的输出类型分为:电压输出、集电极开路输出、推拉互补输出和长线驱动输出。
旋转编码器形式分类编辑有轴型:有轴型又可分为夹紧法兰型、同步法兰型和伺服安装型等。
轴套型:1 / 15轴套型又可分为半空型、全空型和大口径型等。
器件图片(2 张) 以编码器工作原理可分为:光电式、磁电式和触点电刷式。
按码盘的刻孔方式不同分类编码器可分为增量式和绝对式两类。
增量式 BEN 编码器是将位移转换成周期性的电信号,再把这个电信号转变成计数脉冲,用脉冲的个数表示位移的大小。
绝对式编码器的每一个位置对应一个确定的数字码,因此它的示值只与测量的起始和终止位置有关,而与测量的中间过程无关。
台達旋轉式編碼器使用說明台达旋转式编码器使用说明DELTA ROTARY OPTICAL ENCODER INSTRUCTION SHEET(繁體版)輸出訊號之電路將編碼器連接至接收端前,請先根據下表確認輸出訊號種類。
1.線路連接表ES/EH/ET 系列 將屏蔽線(裸線)連接到應用設備之接地端,以使其有更高品質的輸出訊號。
AS/AH 系列 (AXX-XXCXXXXX,AXX-XXVXXXXX)線材顏色功能線材顏色功能紅Vcc 藍24黑0V 紫25棕20灰26橘21白27黃22粉紅28綠23淡藍29MH4/MT4 系列CS7 系列2.輸出型式ES/EH/ET 系列Vcc0VoutputVcc0V0VVccoutput電壓輸出開集極差動推挽AS/AH 系列 (AXX-XXCXXXXX,AXX-XXVXXXXX)Vcc0Voutput電壓輸出開集極MH4/MT4/CS7系列Vcc0V差動(简体版)输出信号之电路将编码器连接至接收端前,请先根据下表确认输出信号种类。
1.线路连接表ES/EH/ET 系列 将屏蔽线(裸线)连接到应用设备之接地端,以使其有更高品质的输出信号。
AS/AH 系列 (AXX-XXCXXXXX,AXX-XXVXXXXX) 线材颜色 功能 线材颜色 功能红 Vcc 蓝 24 黑 0V 紫25 棕 20灰 26 橘 21白 27 黄 22粉红 28 绿 23淡蓝 29MH4/MT4 系列CS7 系列2. 输出形式 ES/EH/ET 系列Vcc0VoutputVcc0V0VVccoutput電壓輸出開集極差動推挽AS/AH 系列 (AXX-XXCXXXXX,AXX-XXVXXXXX)Vcc0Voutput電壓輸出開集極MH4/MT4/CS7系列Vcc0V差動(English Version)CIRCUIT OF OUTPUT SIGNALSBefore connecting the encoder wirings to the receiver, please identify the type of the output signal with the specification. 1. Connection Table ES/EH/ET SeriesConnect the shield wire (bare wire) with the grounding end of equipment for better performance.AS/AH Series (AXX-XXCXXXXX,AXX-XXVXXXXX) Wire ColorFunctionWire ColorFunction Red Vcc Blue 24Black 0V Purple 25 Brown 20Gray 26 Orange 21 White 27 Yellow 22 Pink28Green 23Light Blue29MH4/MT4 SeriesCS7 Series2. Output Circuit ES/EH/ET SeriesVcc0V outputVcc0V 0VVccoutputVoltage OutputOpen-Collector Line Driver Push-PullAS/AH Series (AXX-XXCXXXXX,AXX-XXVXXXXX)Vcc0VoutputVoltage OutputOpen-CollectorMH4/MT4/CS7SeriesVcc0VLine Driver***************************************。
旋转编码开关(Rotary Encoder switch)-使用说明及程序
具有左转,右转,按下三个功能.4.5 脚是中间按下去地开关接线 1 2
3 脚一般是中间2
脚接地,1.3 脚上拉电阻后,当左转.右转旋纽时,在1.3 脚就有脉冲
信号输出了.
着这是标准资料:
在单片机编程时,左转和右转地判别是难点,用示波器观察这种开关
左转和右转时两个输出
脚地信号有个相位差,见下图:
由此可见,如果输出1 为高电平时,输出2 出现一个高电平,这时开
关就是向顺时针旋转; 当输
出1 为高电平,输出2 出现一个低电平,这时就一定是逆时针方向旋
转.
所以,在单片机编程时只需要判断当输出1 为高电平时,输出2 当时
地状态就可以判断出是左
旋转或是右旋转了.
还有另外一种3 脚地,除了不带按钮开关外,和上面是一样地使用.
参考:
#include "reg51.h"
#define uint unsigned int
sbit CodingsWitch_A=P1_1;
sbit CodingsWitch_B=P1_2;
uint CodingsWitchPolling()//
{
static Uchar Aold,Bold; //定义了两个变量用来储蓄上一次调用此
方法是编码开关两引
脚地电平
static Uchar st; //定义了一个变量用来储蓄以前是否出现了两个
引脚都为高电
平地状态
uint tmp = 0;
if(CodingsWitch_A&&CodingsWitch_B)
st = 1; //
if(st) //如果st 为1 执行下面地步骤
{
if(CodingsWitch_A==0&&CodingsWitch_B==0) //如果当前编码开关
地两个引脚
都为底电平执行下面地步骤
{
if(Bold) //为高说明编码开关在向加大地方向转
{
st = 0;
tmp++; //
}
if(Aold) //为高说明编码开关在向减小地方向转
{
st = 0;
tmp--; //设返回值
}
}
}
Aold = CodingsWitch_A; //
Bold = CodingsWitch_B; //储
return tmp; //
}
//编码器计数程序
void encoder_cnt(void)
{
uchar temp;
temp = PIND; //取端口D 管脚信号
couch_clr = (temp & 0x08); //取编码器清零信号
if(couch_clr != false) //有编码器清零信号
{
couch_num = 0; //水平床码清零
}
else
{
if(encoder_cnt_en == false) //编码器计数模块没有启动
{
pr_couch_ba = temp & 0x03; //取编码器A.B 相电平信号
}
else
{
couch_ba = temp & 0x03; //取编码器A.B 相电平信号
if(pr_couch_ba == 0x00)
{
if(couch_ba == 0x01)
{
couch_num++; //水平床码加1
}
else if(couch_ba == 0x10)
{
couch_num--; //水平床码减1
}
}
else if(pr_couch_ba == 0x01)
{
if(couch_ba == 0x11)
{
couch_num++; //水平床码加1
}
{
couch_num--; //水平床码减1
}
}
else if(pr_couch_ba == 0x10)
{
if(couch_ba == 0x00)
{
couch_num++; //水平床码加1
}
else if(couch_ba == 0x11)
{
couch_num--; //水平床码减1
}
}
else if(pr_couch_ba == 0x11)
{
if(couch_ba == 0x10)
{
couch_num++; //水平床码加1
}
{
couch_num--; //水平床码减1
}
}
}
pr_couch_ba = couch_ba;
}
}
编码器及其计数模块原理
飘扬地旋转编码器地检测程序(MCS51)
//旋转编码器检测程序,A/B信号分别接在了INT0和INT1
上
//程序作者:BG4UVR
//2005 年1 月15 用KEIL编译.硬件测试通过
//注意:编码器地信号,程序未做消抖处理.测试中,A/B信号上各//接了一只104地瓷片电容,工作很正常.如果不接电容,请自行编
//写信号消抖程序.
#include <at89x51.h>
sbit led="0xB1";//有一只LED接在了RXD 引脚上,用来指示正反
转;
main()
{
EA=1; //总中断允许
EX0=1; //外部中断0允许
IT0=1; //外部中断0为边沿触发方式
while(1);;
}
/*********************
编码器中断函数
入口:无
出口:无
*********************/
void encoder(void) interrupt 0 { //外部中断0
if (INT1){
led=1;
}else{
led=0;
}
}
whimsy 地AVR 程序
//外部中断0,用于编码开关解码,解码图: A 接中断脚(AVR 地PD2),
以此为基准,B 用来
判断方向(连到AVR 地PA1), C 接地
//A -|
// | -----|__________|----------|____________
//C -|
//
//B -|
// | ----------|__________|----------|____________
//C -|
// CW ===>>> ROTATION
//外部中断设置(ISC01=0,ISC00=1): INT0 引脚上任意地逻辑电平
变化都将引发中断
#pragma interrupt_handler int0_isr:2
void int0_isr(void)
{
//external interupt on INT0
GICR=0; //禁止外部中断
if ((PIND & 0x04)==0) //先判断是高电平产生地中断还是低点平地
中断
if ((PINA & 0x02)==0) //再判断B 线上地电平
{
keycounter--;
keydirection="0";
}
个人收集整理资料,仅供交流学习,勿作商业用途
else
{
keycounter++;
keydirection="1";
}
else
if ((PINA & 0x02)==0)
{
keycounter++;
keydirection="1";
}
else
{
keycounter--;
keydirection=0;
}
GICR=0x40;
}。