Searching \ for '[PIC]:Rotary Encoder coding problem' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'Rotary Encoder coding problem'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]:Rotary Encoder coding problem'
2003\04\13@190326 by cdb

I have a Piher  04-CI-11 rotary encoder 30 detents/15 pulses two bit.

The code (below) that I have scraped up works, with one annoying
flaw, it only ever counts in two's either 1,3,5,7 etc or 2,4,6,8.
Now other than rewriting the code completely is there an adjustment I
can make to the maths? Or would just changing the size of the knob

The encoder code is --
// A terminal of encoder is connected to PortA:1, B to PortA:0

void getenc()
       unsigned char new_enc_state;
       unsigned char temp_enc_state;

       new_enc_state&=0x03;    //get bottom two bits
       if (temp_enc_state==0)
               enc_state=0;            //No change

       old_enc_state=old_enc_state<<1; //rotate old bit 0 to bit 1
       old_enc_state^=new_enc_state;           //which bit changed?

       if (old_enc_state&=(1<<enc_A)) //check this happened
               enc_state=1;            //encoder went CW
               enc_state=-1;           //encoder went CCW
       old_enc_state=new_enc_state;    //update last encoder position

The part of the code that calls this is

//asm routine saves 6 program words over  using if <1 || > 99
       if (lmenu==2)           //set under humidity trip point

                       if(enc_state==1)        //encoder moved CW
                               #asmline incf trip+0,F          ; increment struct trip.hummidity

                       if(enc_state== -1)              //encoder moved CCW
                               #asmline decf trip+0,F  ;decrement trip.humidity

                         movf trip+0,W
                         addlw 155                     ;255-100 we are testing for range  1 to 100
                         addlw 100                     ;(max range[100] - min range[1])+1
                         movf trip+0,W ;this is needed due to Wiz-C internal routines
that deduct one from W for function calls.
                         btfss STATUS,C
                       display1(trip.humidity,3);       //send to display format 3 digits wide

As you can see only being able to set temperature and humidity trip
points in odd or even numbers, is not quite what is needed.

Thanks for any advice.

cdb, on 31/03/2002

-- hint: The list server can filter out subtopics
(like ads or off topics) for you. See

More... (looser matching)
- Last day of these posts
- In 2003 , 2004 only
- Today
- New search...