Exact match. Not showing close matches.
'[PIC]:Rotary Encoder coding problem'
|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
unsigned char new_enc_state;
unsigned char temp_enc_state;
new_enc_state&=0x03; //get bottom two bits
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
addlw 155 ;255-100 we are testing for range 1 to 100
addlw 100 ;(max range - min range)+1
movf trip+0,W ;this is needed due to Wiz-C internal routines
that deduct one from W for function calls.
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, barnard.name on 31/03/2002 cdb
http://www.piclist.com hint: The list server can filter out subtopics
(like ads or off topics) for you. See http://www.piclist.com/#topics
More... (looser matching)
- Last day of these posts
- In 2003
, 2004 only
- New search...