View Single Post
  #4   Spotlight this post!  
Unread 19-11-2008, 22:05
Mr. Lim Mr. Lim is offline
Registered User
AKA: Mr. Lim
no team
Team Role: Leadership
 
Join Date: Jan 2004
Rookie Year: 1998
Location: Toronto, Ontario
Posts: 1,125
Mr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond reputeMr. Lim has a reputation beyond repute
Re: Troublesome encoder ISR

I know this will only give you 1/4 the resolution you want, but does at least this work?

Code:
	const unsigned char aMask = 0x10;
        const unsigned char bMask = 0x20;

	unsigned char a = (PORTB & aMask) == aMask;
        unsigned char b = (PORTB & bMask) == bMask;


	if((PORTB ^ oldPORTB) & aMask == aMask)
	{
		if(a)						// a transitioned high
		{
			if(b)					// b is high
				++encoderCount;
			else					// b is low
				--encoderCount;
		}
	}

	oldPORTB = PORTB;

	INTCONbits.RBIF = 0;     /*     and clear the interrupt flag         */
If this does work, then chances are it's an ISR timing problem. If this doesn't work, then it's likely a logic issue that's not obvious to us. Either way, it'd help us narrow down the nature of the beast.

-Shawn T. Lim...
__________________
In life, what you give, you keep. What you fail to give, you lose forever...

Last edited by Mr. Lim : 19-11-2008 at 22:09.