## Progress on the shaft encoder

Expand Messages
• Well I have learned a lot today about the shaft encoder, and it is working for the most part. I use a 1ms interrupt to read the encoder inputs. I must have 3
Message 1 of 1 , May 1, 2008
Well I have learned a lot today about the shaft encoder, and it is
working for the most part. I use a 1ms interrupt to read the encoder
inputs. I must have 3 readings the same to set the encoder valid flag.
That's a fairly short debounce because when you spin the knob the
transitions are 5ms apart. So this works pretty reliably. Now from the
spec and my observations, I am capturing 60 transitions per revolution
and there are 30 detents per revolution. That makes for an interesting
situation :-) I was hoping to make each detent bump the freq digit by 1.
But because of the mechanics you can get 1 3 or 2 2 transitions per
detent. If I choose 1 revolution for ten increments of the frequency
digit it is 3 detents and 6 transitions. Well I'm learning :-) I'll
figure it out tomorrow :-)

if ( Flag.encoder_valid ) {

if ( new_encoder != old_encoder ) {

if ( ( ( new_encoder >> 1 ) ^ old_encoder ) & 0x01 )
delta_freq = 10;

else delta_freq =
-10;

// if ( new_encoder ^ old_encoder == 0x03 )
delta_freq = 0;

old_encoder = new_encoder;

Flag.freq_change = 1;

}

}

and

//===================================================================

char old_encoder, new_encoder;

__interrupt void isrVmtim(void) {

static char counter = 0;

char temp;

MTIMSC_TRST = 1;

temp = PTBD & 0x03;

if ( temp == new_encoder ) ++counter;

else {

new_encoder = temp;

Flag.encoder_valid = 0;

counter = 0;

}

if ( counter >= 2 ) {

Flag.encoder_valid = 1;

counter = 2;

}

}

//===================================================================

--
Regards,
John

=========================================================
email: k5jhf@...
photos: http://www.flickr.com/photos/k5jhf/sets/