周首杰



摘 要:嵌入式控制是指将单片机嵌入产品中,对产品起到控制作用。机械式旋转编码开关是通过人工操作旋转方向来控制某个量的增加或减小。虽然产生的信号只有两个,但是干扰信号的存在使信号准确检测变得相对困难。通常使用的检测方法有两种,一是通过中断方式进行外部信号的采集,二是通过查询方式进行信号的检测。本文对两种方法进行比较,进而采用较好的办法进行软件设计,有效滤除抖动带来的干扰信号影响。
关键词:嵌入式产品;机械旋转编码开关;信号检测;抗抖动;中断;查询
Abstract: Embedded control refers to embedding the single-chip microcomputer in the product and playing a controlling role on the product. The mechanical rotary coding switch controls the increase or decrease of a certain amount by manually operating the direction of rotation. Although only two signals are generated, the presence of interfering signals makes it relatively difficult to detect the signals accurately. There are two commonly used detection methods, one is to collect external signals by interruption, and the other is to detect signals by query. This paper compared the two methods, and then adopted a better method for software design, effectively filtering out the effects of interference signals caused by jitter.
Keywords: embedded products;mechanical rotary coding switch;signal detection;anti-jitter;interrupt; query
機械式旋转编码开关是通过旋转过程中产生的触点接通与断开来实现信号的检测,根据触点接通与断开的先后顺序来检测自身的旋转方向。接通与断开过程中存在触点抖动情况,使得单片机检测过程变得较为复杂[1-2]。本文提出两种软件检测方法,讨论其检测程序的编写。
1 编码开关原理
图1是一种机械式旋转编码开关外形图。其中,1、2脚是作为按键开关使用的,这里不作讨论。A、B、C三脚是作为旋转信号提供的,下面重点讨论这三个脚的使用。在硬件接线中,人们将C脚接地,将A、B脚分别接单片机检测脚,那么在旋动旋钮时会形成A脚与C脚的接通与断开、B脚与C脚的接通与断开。A脚与C脚的接通与断开形成动作1,B脚与C脚的接通与断开形成动作2,动作1和动作2是不同时发生的,有一个先后顺序,如图2所示。
图2为分别向两个方向旋转旋钮时产生的波形图。……