mkliop 发表于 2010-11-23 08:50:20

那种音响上用的小型旋转编码器怎么驱动?只要编程思路,和原理,不要原码。

我昨天鼓捣一晚上怎么就是往左转有加也有减呀?按说该都是加呢。我用手机发的贴子所以程序就不发了。

fwluck 发表于 2010-11-23 08:59:17

把你的编码器图发上来,有一种的数字的,有一种是可高低电平左右转不同的。

titrwh 发表于 2010-11-23 11:17:43

设编码器有ab两根线,当a电平改变一次,则编码器改变数量1;每次a为高时检测b,如果b为高则编码器正转,为低则反转。以上ab和正反都是相对的。

greencamel 发表于 2010-11-23 11:23:29

我用过一种数字的(可以360°旋转),它有两个输出信号,拿一个输出信号做“时钟”,在“时钟”的下降沿检测另一个信号的电平,这样来区分左转还是右转
如果你的音响使用这种,出现这种情况的原因可能是编码器使用太久,导致“时钟”和信号有抖动或不同步

wuyya 发表于 2010-11-23 11:34:44

基本思路:旋转编码器一般是两组触点,在旋转过程依次 A闭合 AB闭合 B闭合 AB断开,反方向旋转则为 B闭合 AB闭合 A闭合 AB断开,按这个过程来处理即可,注意机械触点要做去抖动处理。
另外一点小经验,不要直接用手捏着转轴来旋转,要套上旋钮的外壳,没有外壳的话,随便找个东西夹住来旋转,比如衣夹。不要问我为什么,我也不知道,只是我第一次写这种程序时,调了好多天都没调通,后来发现用镊子夹住转轴来旋转就OK了。

jeffwei 发表于 2010-11-23 13:26:15

你的肯定是没消抖
我第一次用也是这样
后来并联的102电容消抖

mkliop 发表于 2010-11-23 19:22:05

下学我回去试试

osoon2008 发表于 2010-11-24 08:24:15

用个示波器fuck一下,一清二楚。

hujiahua 发表于 2010-11-25 12:20:58

你可以参考一下这个帖子中我在21楼的回复
http://www.ourdev.cn/bbs/bbs_content_all.jsp?bbs_sn=857853

这种编码器的A、B两条线的其中一条线的状态是不稳定的。建议你把A、B两条线互换一下试试。

millwood0 发表于 2010-11-25 22:41:34

those switches have two pins out: A and B. and their states change depending on the rotation.

so you can look up a table, based on the previous states of A+B and the current states of A+B -> state machine.

when you rotate the switch, A goes 0, 1, 1, 0; and B goes 0, 0, 1, 1;

so if AB is 10 (the 2nd position), and AB was 11 (the 3rd position), you know the switch has moved counterclockwise.

here is the code.

===========code==================
//determine increment / decrement of the encoder
unsigned char encoder_read(PORT_TYPE port, PORT_TYPE pin_a, PORT_TYPE pin_b) {
        const signed char ABs_states[]={0, -1, 1, 0, 1, 0, 0, -1, -1, 0, 0, 1, 0, 1, -1, 0};
        static unsigned char encoder_output=0x00;
        static unsigned char ABs=0x00;                                //AB key read out, Previous in the high 2 bits and current in the low two bits;
        unsigned char tmp;

        ABs <<=2;                                                //left 2 bits now contain the previous AB key read-out;
        tmp=IO_GET(port, pin_a | pin_b);                        //read ab pins
        if (tmp & pin_a) ABs |= 0x02;                        //set the 1st bit if A is high now;
        if (tmp & pin_b) ABs |= 0x01;                        //set the 0th bit if B is high;
        ABs &= 0x0f;                                        //only retain ABs' last 4 bits (A_previous, B_previous, A_current, B_current)
        encoder_output += ABs_states;
        return encoder_output;                        //return the absolute value
        //return ABs_states;                        //return the relative value (+1 = clockwise, 0, -1 = counterclockwise)
}

========end code============

depending on which "return" statement you use, you can either get the absolute value or the relative value of the switches.

yiminglei 发表于 2010-11-25 23:55:31

我加104消抖就可以了,软件上没加,非常好用。。。

lxa0 发表于 2010-12-2 01:58:54

上图 看看啊~~~~~~~~~~~~~~~~~~~~~~~

wandy2010 发表于 2010-12-2 08:25:41

回复【4楼】wuyya
基本思路:旋转编码器一般是两组触点,在旋转过程依次 a闭合 ab闭合 b闭合 ab断开,反方向旋转则为 b闭合 ab闭合 a闭合 ab断开,按这个过程来处理即可,注意机械触点要做去抖动处理。
另外一点小经验,不要直接用手捏着转轴来旋转,要套上旋钮的外壳,没有外壳的话,随便找个东西夹住来旋转,比如衣夹。不要问我为什么,我也不知道,只是我第一次写这种程序时,调了好多天都没调通,后来发现用镊子夹住转轴来旋转就ok了。
-----------------------------------------------------------------------

人体干扰?

tranquilly86 发表于 2012-5-29 13:52:37

wandy2010 发表于 2010-12-2 08:25 static/image/common/back.gif
回复【4楼】wuyya
基本思路:旋转编码器一般是两组触点,在旋转过程依次 a闭合 ab闭合 b闭合 ab断开,反方 ...

我怀疑是那个松手检测的问题,因为实际应用时会出现,没有松手的情况,就是最后可能没有拉高,或者拉低
页: [1]
查看完整版本: 那种音响上用的小型旋转编码器怎么驱动?只要编程思路,和原理,不要原码。