旋转编码开关(Rotary Encoder switch)-使用说明及程序

合集下载

旋转编码开关的使用和分析

旋转编码开关的使用和分析

断路器分类
二、磁断路器 磁断路器为大多数设计问题提供了精度和可靠性较高的成本效益型解决 方案。 磁断路器的过流检测机理是只对被保护电路里的电流变化做出响应,由 于其电流感应螺线管受环境温度变化的影响不大,因此磁断路器具有温 度稳定性,不会像热断路器那样明显地受到环境温度变化的影响。 磁断路器没有预热阶段,因此不会减缓断路器对过载的响应速度,从过 载结束到其复位之前没有冷却期。 可以从四个独立的方面对磁断路器的特性进行有针对性的调整:断路器 所需的电路;跳闸点(以安培计);延迟时间(以秒计)和浪涌处理能 力。对这些因素所做的调整对断路器短路分断能力的影响极小。 一般而言,目前有三种跳闸时间延迟曲线各不相同的磁断路器可供选择: 慢速、中速和快速。当对级联电路和判别电路中的断路器进行匹配时, 这些可供选择的曲线为设计师提供了很高的设计灵活性。 此外,对于常常需要承受巨大涌入电流的设备,还可以选择具备特殊涌 入结构的磁断路器。但是,当设备位置不稳定时,由于磁断路器的跳闸 次数会因螺线管的运动受重力的影响而发生变化,此时热断路器或许是 一个比较好的选择。 磁断路器的应用领域涵盖了很多市场,比如电信、船舶、电器、工业自 动化和控制以及医疗设备。
断路器结构分析
6 实现断路器多种安装接线方式的附件 断路器的安装接线方式除最常见的板前接线方式外,还有板后 接线方式和插入式接线方式。 (1)板后接线方式采用板后接线装置。 (2)插入式接线方式采用插入式安装台。 7 其他 辅助接点装置是专门为带有机内附件的插入式接线方式配套的 附属装置。 电操机构不仅是一种远距离操作断路器的机外附件,也常用于 630A以上开关的现场操作(大开关手操较费力)。 塑壳断路器的安装方式和接线方式并不是一回事。按安装方式 分有固定式(适用于抽屉柜),插入式/抽出式(适用于固定柜); 按接线方式分,不论固定式和插入式/抽出式,都有板前接线、板后 接线,有些产品有专用的电缆或母线的前/后接线端子。

Mayhew Labs旋钮编码器LED环绕指南说明书

Mayhew Labs旋钮编码器LED环绕指南说明书

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。

ERD6系列微型尺寸7x3旋转选择开关产品说明书

ERD6系列微型尺寸7x3旋转选择开关产品说明书

ERD6 SERIESMINIATURE SIZE □7×3 ROTARY SELECTOR SWITCH■FEATURESz Outer dimension 7.2mm square, 3.0mm high on board.z Positions and switch code can be identified.z Pin-out compatible with most of current equivalents.z Gold plated contact area ensures reliable electric continuity for micro current.z Surface mounting type can be supplied in embossed taping for automatic packing. z Easy position setting with wide switching angle and high digit visibility.z All plastics are UL 94V-0 grade fire retardant.z RoHS compliant.■APPLICATIONSz Address switching applicationsz Data storage devicesz Computer and peripheralsz Instrumentation■SPECIFICATIONS1.ELECTRICALz Contact rating Max. switching load 100mA, 5VDC Min. switching load 10μA, 5VDCz Contact resistance (initial) 100mΩ Max.z Insulation resistance 100MΩ Min. at 100VDCz Dielectric strength 250VAC rms. at 60 seconds 2.MECHANICAL and ENVIRONMENTALz Temperature rating operation -25℃ to +85℃storage -40℃ to +85℃z Operation force 510gf-cm Max.z Operation life 10,000 detents Min.z Vibration 10Hz-50Hz-10Hz for 6Hrs.z Solderability After flux 245±5℃ for 5±1 secondsz Resistance to soldering heat solder bath 260±5℃ for 5±1 seconds solder reflow Peak temperature 260℃ Max.3.SOLDERING PROCESSz Solder iron Max. 2 sec/350℃z Reflow soldering heat forSMT & THR type (reference only)■PART NUMBERING SYSTEMZ: RoHS CompliantERD6: Miniature size (7.2×7.2mm²) Rotary Selector Switch■CONSTRUCTION■OPTIONS1.Special marking available■PACKING1.PACKING METHOD■QUICK SELECTION GUIDESIZE POSITIONS CIRCUITTYPESETTINGPOSITIONPINOUTSHAPE OF TERMINALPARTNUMBER 7×7 41 POLE4 CONTACTSTOPSETTING3:3THR WITH ROW SPACING 7.62mm ERD604XSZSMT WITH GULL WING ERD604XMZSMT WITH GULL WING IN T&R ERD604XDZSMT WITH J-HOOK ERD604XCZSMT WITH J-HOOK IN T&R ERD604XEZ Through hole reflow (THR) Gull wing (SMT) J-Hook (SMT)■DIMENSIONS AND CIRCUITRY。

(整理)旋转编码开关

(整理)旋转编码开关

旋转编码开关(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编译、硬件测试通过//注意:编码器的信号,程序未做消抖处理。

旋转编码器工作方式图解

旋转编码器工作方式图解

旋转编码器旋转编码器是由光栅盘(又叫分度码盘)和光电检测装置(又叫接收器)组成。

光栅盘是在一定直径的圆板上等分地开通若干个长方形孔。

由于光栅盘与电机同轴,电机旋转时,光栅盘与电机同速旋转,发光二极管垂直照射光栅盘,把光栅盘图像投射到由光敏元件构成的光电检测装置(接收器)上,光栅盘转动所产生的光变化经转换后以相应的脉冲信号的变化输出。

编码器码盘的材料有玻璃、金属、塑料等。

玻璃码盘是在玻璃上沉积很薄的刻线,其热稳定性好,精度高。

金属码盘直接以通和不通刻线,不易碎,但由于金属有一定的厚度,精度就有限制,其热稳定性也比玻璃的差一个数量级。

塑料码盘成本低廉,但精度、热稳定性、寿命均要差一些。

编码器以信号原理来分,有增量式编码器(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,再除以所用的时间,就得到此次角度码盘运动的角速度。

旋转编码器使用方法

旋转编码器使用方法

旋转编码器使用方法使用方法一:修改驱动程序旋转编码器属于精密仪器,在其使用过程中需通过程序发出指令,才能起到特定的作用,而根据不同环境下的需求,需要设定不同的驱动程序,所以说决定编码器使用效果怎么样,修改合适的驱动程序是非常重要的。

通常情况下只要直接修改reg文件,同时注册一个表文件,利用添加的方式改写动态链接,在确定动态链接已经修改好的情况下,需要将其添加到内核中;使用方法二:硬件接口连接驱动程序修改好之后,下面就是硬件接口连接操作,在连接中,通常有A和B两个集电极输出接口,为确保线路衔接性,需要在3.3V 上的电阻上进行操作,将A和B两个接口分别插到CPU上。

在硬件接口连接成功之后,以防万一,须做好测试工作检查电压输出端高低压数值是否正确,比如在按下按钮之后,如果P2端口输出值是高电平的话,说明连接正确;使用方法三:流接口驱动程序的编写流接口驱动程序的编写是为下面的中断服务程序做准备,具体编写步骤是创建线程实现变量值的记录,同时记录在线路中断的情况下,各端口的数值是否还是高电平;使用方法四:中断服务程序的编写终端服务程序编写主要是起到编码器线路保护作用。

通过对CPU 的I/O接口进行初始化工作,在此基础上编写中断服务程序。

旋转编码器使用说明1. 确定检测对象,测速、测距、测角位移还是计数等。

2.仅用于动态过程还是包含静态位置或状态。

3.确认是择增量型旋转编码器还是绝对型旋转编码器。

4.确定对象的运动范围。

5.确认是选择单圈绝对型旋转编码器还是多圈绝对型旋转编码器。

6.确定对象的最高速度或频率。

7.确定对象的精度要求。

8.确定选择旋转编码器的应用参数。

9. 使用环境,注意旋转编码器的接口方式和保护等级。

旋转编码器(音量旋钮)原理、AD接键原理教材

旋转编码器(音量旋钮)原理、AD接键原理教材

编码器内部的工作原理
此接口为编码器按下 的检测脚,软件通过 检测它的电平变化来 判断是否按下
编码器的内部构造其实 就是3个开关
下图为实物编码器内部 构造图
3.软件处理的逻辑通过编码器输出波形图可知每个运动周期 的时序
顺时针运动 逆时针运动
AB
AB
11
11
01
10
00
00
10
01
(1)MCU通过判断A,B输出的两个状态,就可以轻易的得出角度码盘的运动 方向。
(2)当编码器按下时,编码器上的KEY脚为低电平(常态为高电平), MCU判断其管脚被拉低来做出它相应的动作。 (3)我司大屏机的编码器硬件上A、B两端口是接在一起,分别串了10K和 20K电阻,MCU通过识别其不同的电压值变化还判断编码器旋转的方向。
பைடு நூலகம்
以下为编码器顺时针和逆时针旋转输出的波形图:
4.编码器在使用时需注意的事项 (1)选用编码器时要注意以下几点: 编码器的空间大小、柄长、切槽深度、总高度、封装类型等 (2)增量型旋转编码器有分辨率的差异,使用每圈产生的脉冲数来计量,数目从 6到5400或更高,脉冲数越多,分辨率越高;这是选型的重要依据之一。
假设需采集S10按下的电压:
Ua=3.3*(R2+R3)/R1+R2+R3
2.电阻并联分压式 右图为电阻并联分压式原理图,其原理也是同电阻串联式, MCU通过采集a点的电压来识别按键的功能。一般这种做法 使用的较少,因为按键越多,就代表后面的电阻取值就要越 大。
3.软件如何处理AD数据 我们常见的汽车上的方向盘上的按键,大多数都是
4.AD采集数据的误差干扰及设计注意事项 其实在实际中不可能得到很准确的AD转换值,这是由于存在以 下几种误差: ◆对于同一个电压值,AD多次转换的结果不可能完全相同。

TT电子EN11系列旋转编码器说明书

TT电子EN11系列旋转编码器说明书
Issue E 11/2023 Page 5
Issue E 11/2023 Page 2
Rotary Encoder Model EN11 Series
Q Type
Shaft Types
H = 5mm L 15 20 25 30 P 7 7 11 14 T 6 6 10 12 M 2 224
H = 7mm L 15 20 25 30 P 7 7 11 14 T 6 6 10 12 M 1 124
10mA/5Vdc 10mA
300Vac/1mA, 1 minute 100M ohms at 250Vdc/ 1 mA
2.0ms max. 5.0ms max. 100 RPM max. 10mA/5Vdc 100 miliohms Continuous
General Note TT Electronics reserves the right to make changes in product specification without notice or liability. All information is subject to TT Electronics’ own data and is considered accurate at time of going to print.
Model Styles Available
Top adjust, with switch, threaded bushing Top adjust, without switch, threaded bushing Top adjust, with switch, plain bushing Top adjust, without switch, plain bushing Side adjust, with switch, threaded bushing Side adjust, without switch, threaded bushing Side adjust, with switch, plain bushing Side adjust, without switch, plain bushing
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

旋转编码开关(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
}
else if(couch_ba == 0x00)
{
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
}
else if(couch_ba == 0x01)
{
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;
}。

相关文档
最新文档